PDA

View Full Version : Bug with glTexSubImage2D with Texture NPOT



mop
10-17-2008, 02:50 AM
Hi,

I have a problem to upload a texture NPOT with glTexSubImage2D.


So I've a texture ( RGB 34x34 ) and I upload this texture by block of 4 lines. The pitch of the buffer is alignment on 4 bytes so the size of a line is equal to 104 bytes

here my GL code :

FIBITMAP* pTexData2 = FreeImage_Load(FreeImage_GetFIFFromFilename("avion_roll2.png"), "avion_roll2.png");
vBpp = FreeImage_GetBPP(pTexData2);
vW = FreeImage_GetWidth(pTexData2);
vH = FreeImage_GetHeight(pTexData2);

if( pTexData2 != NULL )
{
glGenTextures( 1, &IDTexture );
glBindTexture( GL_TEXTURE_2D, IDTexture );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

glPixelStorei( GL_UNPACK_ALIGNMENT, 4 ) ;

int pitch = FreeImage_GetPitch(pTexData2);
glTexImage2D( GL_TEXTURE_2D, 0, 3, vW, vH, 0,
GL_BGR_EXT, GL_UNSIGNED_BYTE, NULL);
for(int i = 0; i < 32; i+=4 )
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, i, 34,10, GL_BGR_EXT, GL_UNSIGNED_BYTE, FreeImage_GetBits(pTexData2) + pitch * i);


The problem is that for each block of 4 lines, the fourth line has its last 2 pixels that are black.

Here the original texture :
http://img136.imageshack.us/img136/2110/testlh7.png (http://imageshack.us)


Here a capture of the OpenGL Rendering : http://img355.imageshack.us/img355/4825/captureresultat2bc1.th.png (http://img355.imageshack.us/my.php?image=captureresultat2bc1.png)http://img355.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)

So if I increase the number of line per block, it's always the last of each block where there are black pixels


I work on Windows XP with a Geforce 7900 GTS. My driver is OK.

Is it a bug in OpenGL driver ??

Thanks a lot for your help

_NK47
10-17-2008, 05:57 AM
something is wrong with GL_PACK_ALIGNMENT/GL_UNPACK_ALIGNMENT options. you specify BGR texture format and use 4 in glPixelStorei which is UNSIGNED_INT i guess. try experimenting with glPixelStorei.

mop
10-17-2008, 06:51 AM
I've test my program on a mobile computer with Windows XP and an ATI Mobility FireGL T2, and the rendering was correct !

So, on a computer with Windows XP and a GeForce 8600 GTS, the bug appears but the rendering is different.
See the next capture :
http://img380.imageshack.us/img380/9873/bugtexturenpotgeforce89yn8.png (http://imageshack.us)
http://img380.imageshack.us/img380/bugtexturenpotgeforce89yn8.png/1/w420.png (http://g.imageshack.us/img380/bugtexturenpotgeforce89yn8.png/1/)

It seems that this bug is only on the NVidia Graphic Cards...


So, _NK47 thanks for your answer, I will try to experiment with glPixelStorei.

thanks