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?
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?