Render to texture issue

Started by
6 comments, last by _the_phantom_ 18 years, 11 months ago
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
Advertisement
Where's the render to texture code?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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 :(
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() ?
Hmm pretty sure I'm not doing that. How could this possibly happen?? I mean how could I possibly deactivate the rendering context?
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!
// Tojiart
Exactly thats the thing!
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.

This topic is closed to new replies.

Advertisement