Original Post
I've been banging my head against this one for about four days! I've got a basic OpenGL app working pretty well inside a QGLWidget (Qt environment). Now I want to add texture mapping to the polygons. No matter what I do they come out blank. I've found other apps both with and without Qt that I have downloaded and compiled and they CAN do texture mapping. Naturally I have carefully compared all my initializations etc and my code all seems correct. The FIRST sign of trouble is the call to glGenTextures(int, *int). This call is supposed to place a free texture ID in the second int but in my app it does not modify the second arg at all. I have found on the net that you do not HAVE to use glGenTextures if you keep track of tags yourself. Since I have only one texture I tried this to no avail. I figure the focus should be on the glGenTextures problem since in the other apps I can compile it cheerfully returns 1. I also read that this can happen if there is not a valid opengl context. So, consider the following code: When this runs it produces I have found an app on the net which compiles and works and I have carefully compared all the initializations and calls and made them the same, yet still A) glGenTextures doesn't return an ID and B) textures don't render. Any ideas out there? THX
jpeg_tex->id = 0x99;
fprintf(stderr, "Asking for a texture ID: (current val: %X)\n", jpeg_tex->id);
fprintf(stderr,"loadJPEGTexture: ");
if(isValid()) {
fprintf(stderr, "valid GL Context\n");
}
else {
fprintf(stderr, "*INVALID* GL Context\n");
}
glGenTextures (1, &jpeg_tex->id);
fprintf(stderr, "Got texture ID: %X Error code: %X GL_No_Error = %X\n", jpeg_tex->id, glGetError(), GL_NO_ERROR);
if(jpeg_tex->id == 0x99) {
fprintf(stderr,"glGenTextures does NOT act like it has a valid OpenGL context ... exiting.\n");
exit(1);
}
glBindTexture (GL_TEXTURE_2D, jpeg_tex->id);
Gl_model: valid GL Context
ReadJPEGFromFile: opened "bh.jpg"!
Texture Image Dimensions: 256 x 256 (bh.jpg)
Asking for a texture ID: (current val: 99)
loadJPEGTexture: valid GL Context
Got texture ID: 99 Error code: 0 GL_No_Error = 0
glGenTextures does NOT act like it has a valid OpenGL context ... exiting.