glCopyTexSubImage2D = error "invalid operation"

Started by
3 comments, last by MGB 17 years, 1 month ago
Hi all, I'm trying to draw my world to get a refraction texture for a water shader, but when I call glCopyTexSubImage2D I get the GL error "Invalid operation". Code:

	const int texSize = 512;
        glViewport(0,0, texSize, texSize);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
	
        double plane[4] = {0.0, -1.0, 0.0, 0.0};	//normal pointing along negative y
        glEnable(GL_CLIP_PLANE0);
        glClipPlane(GL_CLIP_PLANE0, plane);

	RenderScene();

        glDisable(GL_CLIP_PLANE0);
        glPopMatrix();

        // Render color buffer to texture:
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, ETxRefractionRender);	// Creates a texture object.
	GFXAPI().CheckErrorState();  // < no error.
	glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texSize, texSize);
	GFXAPI().CheckErrorState();  // < gives error!


Using glCopyTexImage2D instead works at runtime, except the rendered texture is black, and the screen is resized to the size of the rendered texture! Any ideas why the "invalid operation" with glCopyTexSubImage2D?
Advertisement
Quote:Original post by Aph3x
Using glCopyTexImage2D instead works at runtime, except the rendered texture is black,...


Quote:glCopyTexSubImage2D()
GL_INVALID_OPERATION is generated if the texture array has not been defined by a previous glTexImage2D or glCopyTexImage2D operation.

Initialize the texture first, by using glTexImage2D(). This is required in order to specify the format and its dimensions. Are you doing that?

Quote:
... and the screen is resized to the size of the rendered texture!

In the code you posted there is no glViewport(0, 0, screenWidth, screenHeight) after rendering to the texture. So this is normal behavior. Try setting the viewport back to the window's dimensions.

HellRaiZer
HellRaiZer
Ah, good point - phew, that gets rid of the error and viewpoint prob - thanks!
The texture's still black though... maybe it's my parameters to glTexImage2D() - I'll have a play with em.

Ed: actually I suspect my shader is wrong...

[Edited by - Aph3x on March 3, 2007 12:05:42 PM]
Hmm nope - it's the texture somehow...
If I bind some texture loaded in normally, it gets projected onto the sea in what appears to be the correct fashion.
If I bind the texture I rendered and glCopyTexSubImage2D'd I just get black where the refraction should be. Saving the rendered texture pixel data to disk and loading it up looks fine.
I'm stumped...
...and so soon after, I solve it :)

Needed to set some texture parameters on the generated texture:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


This topic is closed to new replies.

Advertisement