Sign in to follow this  
Aph3x

glCopyTexSubImage2D = error "invalid operation"

Recommended Posts

Aph3x    288
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?

Share this post


Link to post
Share on other sites
HellRaiZer    1001
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

Share this post


Link to post
Share on other sites
Aph3x    288
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]

Share this post


Link to post
Share on other sites
Aph3x    288
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...

Share this post


Link to post
Share on other sites
Aph3x    288
...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);



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this