PDA

View Full Version : QGLWidget trouble again



John82
4th August 2009, 08:13
I am trying a simple Qt Application using OpenGL to display a triangle on screen.

But my QGLWidget is not display anything except the background color.

Here is the code :


intializeGL () { } // Blank for now. not initializing any states

resizeGL () {
if (h==0) // Prevent A Divide By Zero By
{
h=1; // Making Height Equal One
}

glViewport(0,0,w,h); // Reset The Current Viewport

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}

paintGL ()
{
clearWindow(); // Clear window to black

glColor3f (1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
}

It is a simple enough code downloaded from Nehe. But the triangle is not being displayed at all!! can someone help please?

profoX
4th August 2009, 10:58
Prepend those functions with void. If you don't specify a type, C++ will assume it's int. Also, you're not following the ANSI programming standard.

If you want a more complete example of the NeHe tutorial in Qt, check out my port of them - http://wesley.vidiqatch.org/03-08-2009/nehe-opengl-lessons-in-qt-chapter-1-and-2/