|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Texture Mapping prob in OpenGL |
|
![]() blake5634 Member since: 1/13/2008 From: seattle, WA, United States |
||||
|
|
||||
| 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:
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);
When this runs it produces 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. 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 |
||||
|
||||
![]() Arex Member since: 7/1/2004 From: Helsinki, Finland |
||||
|
|
||||
| I don't see anything wrong in there, glGenTextures should return a different name. So if you have a valid context, etc. then it might be a driver bug? Have you updated your opengl drivers? Sincerely, Arto Ruotsalainen Dawn Bringer 3D - Tips & Tricks |
||||
|
||||
![]() blake5634 Member since: 1/13/2008 From: seattle, WA, United States |
||||
|
|
||||
| Thanks Arex, The thing is, I have another app (mview) that I downloaded from internet, which I CAN compile and DOES work. In that app, glGenTextures consistently works and the texture does appear. So I think I have the right libraries. What I have been doing is replacing my blocks of code with analogous blocks from mview so that I am initializing OpenGl the exact same way and calling everything exactly the same. What are remaining differences? Well in my app I am building it with Qt's standard qmake Makefile. Mview has it's own hand crafted makefile. Do I have to dig into that? If something were wrong there, wouldn't errors show up? |
||||
|
||||
![]() kolrabi Member since: 6/17/2000 From: Berlin, Germany |
||||
|
|
||||
There might be a hidden error here. glGenTextures fails if either n is negative (GL_INVALID_VALUE) or it was called between glBegin() and glEnd() (GL_INVALID_OPERATION). n clearly isn't negative, so I assume it's the latter case. Unfortunately glGetError() won't help you find this one because the glGetError man page says:Quote: That might explain this behaviour of failing while saying everything is fine. I think it's possible you forgot an glEnd() somewhere. |
||||
|
||||
![]() blake5634 Member since: 1/13/2008 From: seattle, WA, United States |
||||
|
|
||||
| Kolrabi, Nice idea - thanks. However, this is not possible because all the code takes place BEFORE any drawing, i.e. before glBegin or glEnd is ever called. Just to make sure I greppped them and there are no stray glBegins. My latest thinking is that it must be something in the way the app is set up within Qt. The only difference I can see at this point is that mview (the working app) starts out like: [source lang=c++] class MView: public QMainWindow { Q_OBJECT while mine looks like [source lang=c++]
Gl_model::Gl_model(QWidget *parent) : QGLWidget(parent)
{
This is because in Gl_model opengl code is in a secondary window instead of the "QMainWindow". Any Qt experts know if this is the cause? |
||||
|
||||
![]() blake5634 Member since: 1/13/2008 From: seattle, WA, United States |
||||
|
|
||||
| Kolrabi, Nice idea - thanks. However, this is not possible because all the code takes place BEFORE any drawing, i.e. before glBegin or glEnd is ever called. Just to make sure I greppped them and there are no stray glBegins. My latest thinking is that it must be something in the way the app is set up within Qt. The only difference I can see at this point is that mview (the working app) starts out like: class MView: public QMainWindow { Q_OBJECT while mine looks like
Gl_model::Gl_model(QWidget *parent) : QGLWidget(parent)
{
This is because in Gl_model opengl code is in a secondary window instead of the "QMainWindow". Any Qt experts know if this is the cause? |
||||
|
||||
![]() V-man Member since: 3/2/2002 From: Montreal, Canada |
||||
|
|
||||
| I'm not a QT expert but the issues are the same no matter what wrapper and OS you use. If you are creating another GL window and your program is single threaded, you need to make the GL context of the first window non current and in the second window, make the GL context current. There can only be 1 GL context current per thread. Just stick a call to glXMakeCurrent (X window) or wglMakeCurrent (Windows) in the right place. |
||||
|
||||
![]() Geometrian Member since: 4/10/2007 From: Boulder Creek, CA, United States |
||||
|
|
||||
| It says here: http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/gentextures.html that: The generated textures have no dimensionality; they assume the dimensionality of the texture target to which they are first bound. I am by no means a C expert. Does that mean that it wouldn't work anyway? Perhaps this means there is no problem? HTH G |
||||
|
||||
![]() TiredofSleep GDNet+ Member since: 7/16/2007 From: Orlando, FL, United States |
||||
|
|
||||
| glEnable(GL_TEXTURE_2D) maybe texturing isnt turned on? Do you all your UV Coordinates set correctly? Texture is the correctly loaded in? |
||||
|
||||
![]() blake5634 Member since: 1/13/2008 From: seattle, WA, United States |
||||
|
|
||||
| Thanks V-Man!! This was the missing piece! Even though the code was based on an example in the Qt documentation (without the texture mapping)! However just for reference, in Qt the call is makeCurrent(); with no args. I've been banging my head against this one for over a week! |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|