Archived

This topic is now archived and is closed to further replies.

nowaydown

Texture Mapping Not Showing

Recommended Posts

Hello everyone. I have a question about texture mapping. I''m totally new to OpenGL (within the last 24 hours kinda new) so please bear with me. I''m on NeHe''s tutorial number 6, about the textured map cube. His demonstration works fine for me. I''ve been able to load another texture that I''ve made onto his rotating cube and everything works great. So, I got thinking that I would try to make a single quad face, and slap a texture on it just to do my own thing. I thought a title screen logo would be an appropriate example. Instead of using his DrawGLScene() function, I''ve written my own, renderTitleScreen(). Here''s the code for that function: nt renderTitleScreen(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glRotatef(g_RotationAngle,0.0f,1.0f,0.0f); glBindTexture(GL_TEXTURE_2D, texture[0]); // Texture Mapped Quad-- glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glEnd(); g_RotationAngle+=3.0f; return TRUE; } I don''t recieve any errors regarding the loading of my texture, so I''m assuming this is working fine. The dimensions of the image I am trying to load is 382x87. Just a normal 16bit .bmp file that should be stored in texture[0]. My square displays fine on the screen, but without a texture. I added the rotation to see if maybe the texture was actually on the back of my quad, but this isnt the case either. I know its hard to diagnose an issue like this out of the context of the rest of the program. Is it because I''m trying to map a non-square texture? Not sure what the key is here. Any input for this n00b would be greatly appreciated. Thanks very much....

Share this post


Link to post
Share on other sites
Switching the image to a 512x512 bitmap seems to have resolved this issue. Could anyone explain to me why this is the case? Just would like to know for future reference. Thanks!

Share this post


Link to post
Share on other sites
Unless you use advanced extensions, all textures need to have widths and heights that are power of two (plus possibly two pixels for border). glTexImage2D() will return an error when you try to allocate another width or height, so saying you didn''t get any errors seems to indicate that you didn''t correctly check for them.

When I program OpenGL, I put this code after EACH OpenGL call:

assert( !glGetError() );

I also #include <assert.h> at the top of my source files. This ensures that, if I do something wrong, I''m told about it as soon as possible.

The width and height don''t need to be the same, but they each need to be taken from the following set:

1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 (possibly 2048 or 4096 for very new cards)

You can test that a width/height is OK by using


bool IsTextureWidthAndHeightOk( int width, int height )
{
return !(width & (width-1)) && !(height & (height-1));
}

Share this post


Link to post
Share on other sites
Thanks for the clarification as well as the error checking routines. Hopefully one day I will be able to give something back to the community. Thanks again for everything.

Share this post


Link to post
Share on other sites