Skip to main content
GameDev.net gamedev.net
🔒 Locked

glCopyTexSubImage2D fails

Started by blueshogun96 Feb 22, 2012 at 9:27 AM 4 replies 1.9k views
Original Post
blueshogun96
blueshogun96
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.



//--------------------------------------------------------------------------------------
// 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...
}
}


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.
V-man
V-man
glTexImage2D( GL_tex_rect, 1, pixel_format, width, height, 0, pixel_format, GL_UNSIGNED_BYTE, NULL );


Why is your level parameter equal to 1?
Brother Bob
Brother Bob

Also, read what the function parameters are. Your first parameter is not even valid.
http://www.opengl.or...xSubImage2D.xml

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.
dpadam450
dpadam450
[sub]I skimmed the code so quick, I thought it was a texture integer handle.[/sub]
NBA2K, Madden, Maneater, Killing Floor, Sims 
blueshogun96
blueshogun96

glTexImage2D( GL_tex_rect, 1, pixel_format, width, height, 0, pixel_format, GL_UNSIGNED_BYTE, NULL );


Why is your level parameter equal to 1?

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='dpadam450' timestamp='1329925027' post='4915523']
Also, read what the function parameters are. Your first parameter is not even valid.
http://www.opengl.or...xSubImage2D.xml

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.