Jump to content
  • Advertisement
Sign in to follow this  
goyg

Render to a texture

This topic is 3741 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, When I render to a texture, I have a problem. I have checked out the data in texture, and it's correct. But the texture cannot be rendered.I change the texture with a texture generating from a BMP file, It works. Here is some source: <div class="source">
GLuint Texture;
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexImage2D(GL_TEXTURE_2D,0,3,windowWidth,windowHeight,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

rendering...

glBindTexture(GL_TEXTURE_2D,Texture);
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,windowWidth,windowHeight,0);

These codes are rendering to a texture. <div class="source">
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex2f(-x,-y);
glTexCoord2f(1.0f,0.0f);
glVertex2f(x,-y);
glTexCoord2f(1.0f,1.0f);
glVertex2f(x,y);
glTexCoord2f(0.0f,1.0f);
glVertex2f(-x,y);
glEnd();

Run this code I only get a white QUAD without texture. If I use a texture generating from a BMP file instead, I get the QUAD with texture. Is there any step missing in rendering to a texture?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by delta user
The size of your window probably isn't a power of two or even square at all.
Your window size must be a power of two.


That entirely depends on your hardware setup see: EXT_texture_non_power_of_two.

firstly, why aren't you using Frame buffer Objects? same setup complexity but much easier to use and more debuggable not to mention much more performant.

use glGetError after your calls to glTexImage and glCopyTexImage; actually use it as much as possible when developing rendering code, its a massive timesaver thats often overlooked. You could be missing a required glTexParameteri argument or calling those methods while in the wrong GL state.

Lastly, try read back the texture into CPU memory and see if the actual pixel data matches up, e.g. set the clear colour to green, read back the framebuffer into the texture and see if the texture data actually contains just green pixesl. you can use glGetTexImage2D for this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!