# how to render FBO texture to screen?

**URL:** <https://forums.imgtec.com/t/how-to-render-fbo-texture-to-screen/208>\
**Category:** PowerVR Insider\
**Created:** [December 24, 2008, 7:19am UTC](https://forums.imgtec.com/t/how-to-render-fbo-texture-to-screen/208 "2008-12-24T07:19:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyllanzhou](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@dyllanzhou](https://forums.imgtec.com/u/dyllanzhou)\
**Post date:** [December 24, 2008, 7:19am UTC](https://forums.imgtec.com/t/how-to-render-fbo-texture-to-screen/208/1 "2008-12-24T07:19:43Z")

</div>

hi, all

&nbsp;&nbsp;&nbsp; i am a newer to opengles 2.0,&nbsp; and i currently try to use FBO to render to texture, then show the texture to the screen.
  

but i cound not show it correctly , can anyone give me some idear? i refer to the code for openglees2.0 programming guideline.
  

the following is my code: 
  

ps.480x800 is screen width\*height
  

&nbsp;
  

//
  

GLuint vbo;  
GLuint texture;  
GLuint fbo;
  

GLuint rbo;
  

&nbsp;
  

//generate one vbo
  

glGenBuffers(1,&vbo);  
glBindBuffer(GL\_ARRAY\_BUFFER, vbo);  
glBufferData(GL\_ARRAY\_BUFFER, sizeof(GLfloat)\*8, 0, GL\_DYNAMIC\_DRAW);  
glBindBuffer(GL\_ARRAY\_BUFFER, 0);
  

&nbsp;
  

//generate one texture
  

glGenTextures(1,&texture);&nbsp; 
  

&nbsp;&nbsp;&nbsp; glBindTexture(GL\_TEXTURE\_2D,texture);  
&nbsp;&nbsp;&nbsp; glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, 480,800, 0, GL\_RGB, GL\_UNSIGNED\_BYTE,0);  
&nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_WRAP\_S, GL\_CLAMP\_TO\_EDGE);  
&nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_WRAP\_T, GL\_CLAMP\_TO\_EDGE);  
&nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR);  
&nbsp;&nbsp;&nbsp; glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR);
  

&nbsp;
  

//generate one render buffer
  

glGenRenderbuffers(1, &rbo);
  

&nbsp;&nbsp;&nbsp; glBindRenderbuffer(GL\_RENDERBUFFER,&nbsp;rbo);  
&nbsp;&nbsp;&nbsp; glRenderbufferStorage(GL\_RENDERBUFFER,GL\_DEPTH\_COMPONENT16, 480, 800);
  

&nbsp;
  

//generate FBO
  

glGenFramebuffers(1, &fbo);
  

&nbsp;&nbsp;&nbsp; glBindFramebuffer(GL\_FRAMEBUFFER, fbo);  
&nbsp;&nbsp;&nbsp; glFramebufferTexture2D(GL\_FRAMEBUFFER,GL\_COLOR\_ATTACHMENT0,GL\_TEXTURE\_2D, texture, 0); // attach texture  
&nbsp;&nbsp;&nbsp;&nbsp; glFramebufferRenderbuffer(GL\_FRAMEBUFFER,GL\_DEPTH\_ATTACHMENT, GL\_RENDERBUFFER,rbo);  
&nbsp;
  

//check status
  

&nbsp;GLint status = glCheckFramebufferStatus(GL\_FRAMEBUFFER);  
&nbsp;if(status != GL\_FRAMEBUFFER\_COMPLETE){  
&nbsp;&nbsp;&nbsp; printf("framebuffer not complete ++++++++++n");  
&nbsp;}
  

&nbsp;
  

//render one rectangel to this FBO
  

glBindFramebuffer(GL\_FRAMEBUFFER, fbo);
  

drawRectangle();
  

&nbsp;
  

//show on display window  
glBindFramebuffer(GL\_FRAMEBUFFER,0);
  

glClear(GL\_COLOR\_BUFFER\_BIT);  
glBindTexture(GL\_TEXTURE\_2D,texture);  
glBindBuffer(GL\_ARRAY\_BUFFER, vbo);  
glReadPixels(0, 0, 480,800, GL\_RGBA,GL\_FLOAT, 0);
  

glViewport(0,0,480,800);  
glVertexAttribPointer (0, 2, GL\_FLOAT, GL\_FALSE, 0, 0);  
glDrawArrays (GL\_TRIANGLE\_FAN, 0,4);  
glBindBuffer(GL\_ARRAY\_BUFFER, 0 ); 
  

&nbsp;
  

&nbsp;

---

<div class="post-metadata">

**Author:** ![xmas](https://avatars.discourse-cdn.com/v4/letter/x/958977/32.png) [@xmas](https://forums.imgtec.com/u/xmas)\
**Post date:** [January 5, 2009, 9:42am UTC](https://forums.imgtec.com/t/how-to-render-fbo-texture-to-screen/208/2 "2009-01-05T09:42:35Z")

</div>

Do you actually use a NULL pointer for glBufferData? What does the drawRectangle function do? What shader program are you using? What’s the point of the glReadPixels call?

---

<div class="post-metadata">

**Author:** ![z\_boy](https://avatars.discourse-cdn.com/v4/letter/z/e36b37/32.png) [@z\_boy](https://forums.imgtec.com/u/z_boy)\
**Post date:** [July 26, 2010, 1:46pm UTC](https://forums.imgtec.com/t/how-to-render-fbo-texture-to-screen/208/3 "2010-07-26T13:46:45Z")

</div>

the shading languages shouid be written like…?I don’t know how to write it?it’s for what use?i have already seen all the topics in the forum,but still have little idea…

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [July 28, 2010, 7:39am UTC](https://forums.imgtec.com/t/how-to-render-fbo-texture-to-screen/208/4 "2010-07-28T07:39:01Z")

</div>

Hi Z\_boy,  
  
  
  
  
  
The best place to start is to read through the SDK documentation and the source code of tutorials and demos that are most applicable to the effect you are trying to achieve. Some of the simpler examples, such as the texturing training course, provide an easy to understand introduction to GLSL ES shaders.  
  
  
  
  
  
The PowerVR SDK as a learning resource targets programmers that are familiar with the basics of 3D graphics and teaches them how to optimise their code for PowerVR Graphics cores. If you are looking for an introduction to shaders, you may find it easier to use a text book or online resource that focuses on teaching this.  
  
  
  
  
  
If there are any specific questions you need answering, you can send an email directly to us at [devtech@imgtec.com](mailto:devtech@imgtec.com).  
  
  
  
  
  
Regards,  
  
  
Joe  
  
  
  
  
  
p.s. If you have a new question, can you please start a new topic for it? Its easier to help you when the topic you post in is related to your specific problem 🙂
