Hi, I am having a problem that I just cannot figure out. I am trying to create a simple rotating cube with a texture on it. I wanted to make the code as simple as possible so I have a derived class GLWidget from QGLWidget and in main I create an instance of it and call show. I use bindTexture to load the texture and here is some code from the paintGL function:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);
glBindTexture(GL_TEXTURE_2D, texture[0]);
...
Now, here is my problem. When I comment out the glRotatef commands, I see the texture. If I comment out the first two glRotatef commands, I still see the texture and it rotates. But if I don't comment out the first two glRotatef commands, I don't see anything. Now the code is fine, here is how I can get it to work, it's strange and I don't understand why it works. If I create another derived class MainWindow from QWidget and in that class I create an instance of GLWidget, everything works fine. So, to summerize...
main -> GLWidget (doesn't work)
main -> MainWindow -> GLWidget (works)
Now, I understand that the latter approach would be used in most cases and if it wasn't, why not just use GLUT. I am just curious as to why the first approach doesn't work. Here is the code from main.cpp
#include <QtGui/QApplication>
#include "glwidget.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(data);
QApplication a(argc, argv);
//GLWidget glWidget;
MainWindow glWidget;
glWidget.show();
return a.exec();
}
As you can see, I commented out the GLWidget line and am using the second approach which works.
Any help would greatly be appreciated. I have tried everything I could think of, it just doesn't make sense. I have tried different ways to load the texture, same thing. It's not the code, it's the setup. Why do I have to create a QGLWidget inside a QWidget, why can't I just create a QGLWidget?
-- Aleks
Bookmarks