Jump to content



glCopyTexSubImage2D fails

  • You cannot reply to this topic
5 replies to this topic

#1 blueshogun96   Members   -  Reputation: 139

Like
0Likes
Like

Posted 22 February 2012 - 03:27 AM

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.

Ad:

#2 V-man   Members   -  Reputation: 694

Like
0Likes
Like

Posted 22 February 2012 - 07:24 AM

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


Why is your level parameter equal to 1?
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);

#3 dpadam450   Members   -  Reputation: 184

Like
0Likes
Like

Posted 22 February 2012 - 09:37 AM

Also, read what the function parameters are. Your first parameter is not even valid.
http://www.opengl.or...xSubImage2D.xml
http://www.ultimategamedevelopment.com - My game development DVD tutorials. Learn to make complete 2D/3D games step by step.

http://www.youtube.c...ev?feature=mhee - Follow my video blog on making a 3D flight sim game.

#4 Brother Bob   Moderators   -  Reputation: 1767

Like
0Likes
Like

Posted 22 February 2012 - 09:45 AM

View Postdpadam450, on 22 February 2012 - 09:37 AM, said:

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.

#5 dpadam450   Members   -  Reputation: 184

Like
0Likes
Like

Posted 22 February 2012 - 12:34 PM

I skimmed the code so quick, I thought it was a texture integer handle.
http://www.ultimategamedevelopment.com - My game development DVD tutorials. Learn to make complete 2D/3D games step by step.

http://www.youtube.c...ev?feature=mhee - Follow my video blog on making a 3D flight sim game.

#6 blueshogun96   Members   -  Reputation: 139

Like
0Likes
Like

Posted 22 February 2012 - 07:05 PM

View PostV-man, on 22 February 2012 - 07:24 AM, said:

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.

View PostBrother Bob, on 22 February 2012 - 09:45 AM, said:

View Postdpadam450, on 22 February 2012 - 09:37 AM, said:

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.
Well, I did forget to mention that my OpenGL implementation does support GL_TEXTURE_RECTANGLE_ARB and NV.






We are working on generating results for this topic
PARTNERS