PDA

View Full Version : QGL



cHaOsBrInGeR
11-18-2000, 06:35 AM
Hi, there I coded just this small test-programm, which should display a simple triangle, but it doesn't. Can any of you tell me why? I have no pale haze!
#include <qgl.h>
#include <qapplication.h>

class GWidget : public QGLWidget {
public:
GWidget(QWidget *parent=0,const char *name=0);
protected:
void initializeGL();
void resizeGL(int, int);
void paintGL();
};

static GLint obj1;

GWidget::GWidget(QWidget *parent, const char *name) {
}

void GWidget::initializeGL() {
static GLfloat pos[4] = { 1.0, 1.0, 10.0, 1.0};
static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0};
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
obj1 = glGenLists(1);
glNewList(obj1, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
glShadeModel(GL_FLAT);
glNormal3f(0.0,0.0,1.0);
glBegin(GL_TRIANGLES);
glVertex3f(1.0,1.0,1.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(2.0,2.0,2.0);
glEnd();
}

void GWidget::resizeGL(int width, int height) {
glViewport( 0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -width/height, width/height, -1.0, 1.0, 5.0, 60.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void GWidget: http://www.opengl.org/discussion_boards/ubb/tongue.gifaintGL() {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
}

int main(int argc, char* argv[]) {
QApplication app(argc,argv);
GWidget w;
app.setMainWidget(&w);
w.show();
return app.exec();
}

chennes
11-18-2000, 06:57 AM
Perhaps I'm just missing it, but it doesn't look like you end your display list (glEndList() is the command). I also don't see a glCallLists anywhere, and since you're using GL_COMPILE and not GL_COMPILE_AND_EXECUTE nothing will be drawn until you call the list.

Good luck,
Chris

cHaOsBrInGeR
11-19-2000, 01:19 AM
Oh thanx, that's it.