Jump to content
  • Advertisement
Sign in to follow this  
DerAndi25

Render to texture issue

This topic is 4774 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 guys, this is really freakin me out: I do render to texture. It always generates the GL_INALID_OPERATION error although I am not using it within glbegin/glend. The funny thing is: every 100th or so frame gets rendered correctly :( glViewport(0,0,128, 128); component->draw (); glBindTexture(GL_TEXTURE_2D, _textureID); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 128, 128, 0); glGetTexImage( GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); glViewport(0 , 0,640 ,480); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); This is how I set everything up (GL_NO_ERROR generated here): glGenTextures(1, &_textureID); glBindTexture(GL_TEXTURE_2D, _textureID); glTexImage2D(GL_TEXTURE_2D, 0, 4, _width, _height, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); I would appreciate your help :) Cheers Andy

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Huh?


glViewport(0,0,128, 128);
-> This actually does the drawing -> component->draw ();
glBindTexture(GL_TEXTURE_2D, _textureID);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 128, 128, 0);
glGetTexImage( GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
glViewport(0 , 0,640 ,480);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


The prob is that glBindTexture and the following yield the GL_INVALID_OPERATION error :(

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Huh?


glViewport(0,0,128, 128);
-> This actually does the drawing -> component->draw ();
glBindTexture(GL_TEXTURE_2D, _textureID);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 128, 128, 0);
glGetTexImage( GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
glViewport(0 , 0,640 ,480);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


The prob is that glBindTexture and the following yield the GL_INVALID_OPERATION error :(


not sure... but just in case... are you deactivating the rendering context inside component->draw() ?

Share this post


Link to post
Share on other sites
Hmm pretty sure I'm not doing that. How could this possibly happen?? I mean how could I possibly deactivate the rendering context?

Share this post


Link to post
Share on other sites
I think there's a slight mis-communication here. When most people think "render to texture" they think of creating a pBuffer/FBO and rendering directly to that. What it appears you're doing is rendering to your normal backbuffer, then copying the result to a texture with glCopyTexImage2D(), am I correct?

I really don't have much experience with this issue, but I thought I could help clear up the confusion a bit.

EDIT: a couple of question, now that I've looked at the code some more...

Why exactly are you doing the glGetTexImage()? If all you want to do is use the texture you just copied, it's unnessicary. (If you want to manipulate that information it's good, which is why I ask)

Also, you said that you're not calling glBegin()/glEnd()? Since this is simply a straight backbuffer render, you will need to do that SOMEWHERE in the draw code. (Unless you're using glDrawElements() or such, but it didn't sound like it)

Also, what is the format of your back buffer? If it's 32 bits, you may need to change GL_RGB in glCopyTexImage2D() to GL_RGBA to account for the alpha channel.

Hope that helps!

Share this post


Link to post
Share on other sites
on an unrelated point, underscores infront of varibles names is a BIG no no, they are reserved by the compiler as are double underscores (__) anywhere in a name.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!