Sign in to follow this  
blueshogun96

glCopyTexSubImage2D fails

Recommended Posts

blueshogun96    2264
This is the first time I've come across this problem. In my latest game, the function known as glCopyTexSubImage2D constantly fails. When I check glGetError, it returns GL_INVALID_ENUM. I have absolutely no idea why either. It doesn't matter what I do, it always does this. I'll post my code so I can explain it to you.

[CODE]

//--------------------------------------------------------------------------------------
// Name: create_texture_rectangle
// Desc: Creates a blank texture rectangle
//--------------------------------------------------------------------------------------
GLuint create_texture_rectangle( int width, int height, int bpp )
{
GLuint handle;
GLuint pixel_format = ( bpp == 32 ) ? GL_RGBA : GL_RGB ;

glGenTextures( 1, &handle );
glBindTexture( GL_tex_rect, handle );
glTexImage2D( GL_tex_rect, 1, pixel_format, width, height, 0, pixel_format, GL_UNSIGNED_BYTE, NULL );
glTexParameteri( GL_tex_rect, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_tex_rect, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

return handle;
}

//--------------------------------------------------------------------------------------
// Name: copy_scene_to_texture
// Desc:
//--------------------------------------------------------------------------------------
void copy_scene_to_texture( GLuint *tex, int width, int height )
{
GLenum error;

glEnable( GL_tex_rect );
glBindTexture( GL_tex_rect, *tex );
error = glGetError();

glCopyTexSubImage2D( GL_tex_rect, 0, 0, 0, 0, 0, width, height );
glDisable( GL_tex_rect );

error = glGetError();

if( error != GL_NO_ERROR )
{
// Do whatever...
}
}[/CODE]

Now, this is the code I use to initialize the texture and copy the scene to it. When I set GL_tex_rect to GL_TEXTURE_2D, glBindTexture doesn't fail, but when I use GL_TEXTURE_RECTANGLE_ARB, I get an error for both functions. This usually works for me, but this time, it keeps failing and I don't understand why. This sucks. Any ideas? Thanks.

Share this post


Link to post
Share on other sites
V-man    813
glTexImage2D( GL_tex_rect, 1, pixel_format, width, height, 0, pixel_format, GL_UNSIGNED_BYTE, NULL );


Why is your level parameter equal to 1?

Share this post


Link to post
Share on other sites
dpadam450    2357
Also, read what the function parameters are. Your first parameter is not even valid.
[url="http://www.opengl.org/sdk/docs/man/xhtml/glCopyTexSubImage2D.xml"]http://www.opengl.org/sdk/docs/man/xhtml/glCopyTexSubImage2D.xml[/url]

Share this post


Link to post
Share on other sites
Brother Bob    10344
[quote name='dpadam450' timestamp='1329925027' post='4915523']
Also, read what the function parameters are. Your first parameter is not even valid.
[url="http://www.opengl.org/sdk/docs/man/xhtml/glCopyTexSubImage2D.xml"]http://www.opengl.or...xSubImage2D.xml[/url]
[/quote]
Both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB are valid parameters, so I don't see anything wrong with that. Although the latter is only valid if either the rectangle texture extension or sufficiently high OpenGL version is available.

Share this post


Link to post
Share on other sites
bubu LV    1436
Hidden
[quote name='Brother Bob' timestamp='1329925534' post='4915529']
Both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB are valid parameters, so I don't see anything wrong with that. Although the latter is only valid if either the rectangle texture extension or sufficiently high OpenGL version is available.
[/quote]
[left]Yes, GL_TEXTURE_RECTANGLE_ARB is valid, but [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]GL_tex_rect? What is that?[/size][/font][/color][/left]

Share this post


Link to post
blueshogun96    2264
[quote name='V-man' timestamp='1329917059' post='4915480']
glTexImage2D( GL_tex_rect, 1, pixel_format, width, height, 0, pixel_format, GL_UNSIGNED_BYTE, NULL );


Why is your level parameter equal to 1?
[/quote]
Ah, that's the problem. I stupidly got the mip-level parameter confused with that of Direct3D's D3DXCreateTexture! I can't believe that it was the problem the whole time! Thanks.

[quote name='Brother Bob' timestamp='1329925534' post='4915529']
[quote name='dpadam450' timestamp='1329925027' post='4915523']
Also, read what the function parameters are. Your first parameter is not even valid.
[url="http://www.opengl.org/sdk/docs/man/xhtml/glCopyTexSubImage2D.xml"]http://www.opengl.or...xSubImage2D.xml[/url]
[/quote]
Both GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_ARB are valid parameters, so I don't see anything wrong with that. Although the latter is only valid if either the rectangle texture extension or sufficiently high OpenGL version is available.
[/quote]
Well, I did forget to mention that my OpenGL implementation does support GL_TEXTURE_RECTANGLE_ARB and NV.

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