PDA

View Full Version : Textures not working



mikau
12-09-2009, 07:59 PM
I can't get textures working for the life of me. I'm trying to put a texture on a square, but its just showing up as a plain white square. I read some trouble shooting tips but none of them fixed the problem.

Here's my code. First an initialization function:



void initializeTexture(char * file, unsigned int * texture)
{
glEnable(GL_TEXTURE_2D);

texImage=new BMP_OBJ(file);

glGenTextures(1,texture);
glBindTexture(GL_TEXTURE_2D,*texture);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

glTexImage2D(GL_TEXTURE,0,GL_RGB,texImage->width,texImage->height,
0,GL_RGB,GL_UNSIGNED_INT,texImage->image);
}


heres my drawing function:



void drawTexQuad(float x, float y, float z, float width)
{
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texture);
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex3f(x, y, z);
glTexCoord2d(1.0,0.0); glVertex3f(x+width/2, y, z);
glTexCoord2d(1.0,1.0); glVertex3f(x+width/2, y+width/2, z);
glTexCoord2d(0.0,1.0); glVertex3f(x, y+width/2, z);
glEnd();
glDisable(GL_TEXTURE_2D);
}


can anyone see what the problem could be?

mikau
12-09-2009, 08:01 PM
nevermind.. it was just two subtle typos.. i used GL_TEXTURE instead of GL_TEXTURE_2D and GL_UNSIGNED_INT instead of GL_UNSIGNED_BYTE.

Silly me!