NPOT textures does not work!

Hi to all,

i have an NVidia video card GeForce 9600M GT/PCI/SSE2. This hardwre support GL_ARB_non_power_of_two textures.

I have a simple app (nehe tutorial) that load a texture and display it (i texture map a quad). The texture has size 256x160.

I load the texture in this way (TextureImage[0] has the following type :

typedef struct _AUX_RGBImageRec {
GLint sizeX, sizeY;
unsigned char *data;
} AUX_RGBImageRec;

)

// Code to load the texture (RGB format) NOT SHOWED

glGenTextures(1, &texture[0]);

// Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);

// Create the texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX,
TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

After this, i render the quad in this way (scale is computed
as :
scale = (float)TextureImage[0]->sizeX / TextureImage[0]->sizeY;
while xrot, zrot are angles and ipx, ipy is the coordinate of a point inside the texture):

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, cameradist);
glRotatef(xrot, 1, 0, 0);
glRotatef(zrot, 0, 0, 1);
glTranslatef(ipx, ipy, 0);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(+1.0fscale, +1.0f, -0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(+1.0f
scale, -1.0f, -0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0fscale, -1.0f, -0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f
scale, +1.0f, -0.0f);
glEnd();
glFlush();

Ok, if the texture has size 256x160, it works. If the texture has size 310x176 it show the texture (one can recognize it) in the quad but it is wrongly placed (skewed, translated and wrong colors…).

I need help!
Any idea?

Luca

Have you tried with glPixelStorei(GL_UNPACK_ALIGNMENT, 1) before glTexImage2D?

Omg!!
It works now!!!
Thank you very much. What is the reason for this?

Luca

Your data is byte aligned, not word aligned. The default value for GL_UNPACK_ALIGNMENT is 4.

Cheers!