32 pixel gap at top of opengl es texture
I am trying for the first time to render to a texture using openGL ES (for iPhone) and then display the texture on the screen. Everything works except that there is a 32 row gap at the top of the texture and the bottom 32 rows are cut off. It's like all of my drawing is being offset 32 pixels down, which results in the bottom 32 rows not being drawn as they are outside of the texture.
Here's a very simple example:
void RenderToTexture( int texture )
{
unsigned char buffer[4 * 320 * 480];
unsigned char colour[4];
colour[0] = 255;
colour[1] = 0;
colour[2] = 0;
colour[3] = 128;
for ( int i = 0; i < 4 * 320 * 480; i += 4 )
{
buffer[i] = colour[0];
buffer[i+1] = colour[1];
buffer[i+2] = colour[2];
buffer[i+3] = colour[3];
}
glBindTexture( GL_TEXTURE_2D, texture );
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 320, 480, GL_RGBA, GL_UNSIGNED_BYTE, buffer );
}
And here's the result:
http://img10.imageshack.us/img10/2113/screenjc.th.jpg http://img10.imageshack.us/img10/2113/screenjc.th.jpg
Just setting the colour using glColor4f() instead of calling RenderToTexture() results in a red screen as expected.
Any help would be much appreciated, thanks.
That 32 pixels are the missing ones to 512: 512 - 480 = 32. The reason is you can use only texture sizes that are powers of two with GL_TEXTURE_2D. So you have to round up your width and height to 512. You can still display only the part of the texture you want by using texture coordinates or by setting a texture matrix.
The iPhone 3GS supports non power-of-two textures under certain conditions. All the following must be true:
上一篇: 在iPhone上的较大的OpenGL纹理上绘制较小的纹理
下一篇: opengl es纹理顶部32像素的差距