texture mapping in opengl

hseokman

New member
I'm having trouble with texture mapping in opengl.
I looked at some of tutorials.
Demos are working fine, but I made my program, and my program does not making any texture.

Here is my code

glEnable (GL_DEPTH_TEST);
int width, height;

unsigned char* data = readBMP("test.bmp", width, height);

glBindTexture (GL_TEXTURE_2D, 1);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);

This is initializing part.

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_MODELVIEW);
glColor3f(0.5,1.0,1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 1);
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f);
glVertex3f (-0.5f, -0.5f, 0.0f);
glTexCoord2f (1.0f, 0.0f);
glVertex3f (0.5f, -0.5f, 0.0f);
glTexCoord2f (1.0f, 1.0f);
glVertex3f (0.5f, 0.5f, 0.0f);
glTexCoord2f (0.0f, 1.0f);
glVertex3f (-0.5f, 0.5f, 0.0f);
glEnd ();
glDisable(GL_TEXTURE_2D);
glFlush();

This is draw part.
I don't know what each line does.
Is there anything that I'm missing?
It just shows rectangle without texture.
 
Back
Top