Advertisement

OpenGL - can't get textures!!

Started by December 25, 2001 01:02 AM
1 comment, last by krogoth 23 years, 2 months ago
I have a simple 3D engine where I''m trying to do a few things with textures, but they never work. Right now I just want to load a texture from a BMP and use it on a simple model (a cube), but it doesn''t show the texture. I''ve disabled all glColor() calls, so the model is just white. I initialize OpenGL with: glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); glClearDepth( 1.0f ); glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); glDepthFunc( GL_LESS ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LINE_SMOOTH ); glEnable( GL_POINT_SMOOTH ); glEnable( GL_POLYGON_SMOOTH ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_TEXTURE_2D ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); and store the texture with: glGenTextures( 1, (GLuint*)pm->data ); glBindTexture( GL_TEXTURE_2D, (GLuint)pm->data ); glTexImage2D( GL_TEXTURE_2D, 0, 4, pm->width, pm->height, 0, GL_RGBA, GL_FLOAT, data ); where pm->data is the texture ID (a void*) and data is the correct pixmap data, and load the model with: mdl->displayList = glGenLists( 1 ); glNewList( mdl->displayList, GL_COMPILE ); glBegin( GL_TRIANGLE_STRIP ); // a loop that goes through triangle data... #define VTX( x, y, z ) glTexCoord2f( x*z, y*z ); glVertex3f( x, y, z ) VTX( verts[data[c]*3], verts[data[c]*3+1], verts[data[c]*3+2] ); // end loop glEnd( ); glEndList( ); The code here outputs the texture co-ordinates I use, and they are all 1.0 or -1.0. I display the model with: glBindTexture( GL_TEXTURE_2D, *(GLuint*)tx->data ); glCallList( model->displayList ); where tx->data and model->displayList are the texture object ID and display list ID. After I do all this, I get a white cube. What am I missing?
Did you even look at the tutorials on NEHEs site?

Don''t look like it.

(note, I am not trying to be mean, but it would help if you would read the tutorials FIRST, they really do help.)

Advertisement
I did, really. I looked at the texture tutorial and the last text tutorial and compared my OpenGL code. I know I''m missing something, but I can''t figure out what.

This topic is closed to new replies.

Advertisement