rick_st3
16th June 2008, 11:58
I wrote a simple code to create an opengl window with a square in it...
here are the relevent files....
#ifndef HEADER_H
#define HEADER_H
#include<QtOpenGl>
class QGLWidget;
class ric:public QGLWidget
{
public:
GLvoid glInitialize();
GLvoid glResize(int width,int height);
GLvoid paintGL();
};
#endif
#include<QGLWidget>
#include"header.h"
GLvoid ric::glInitialize()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
GLvoid ric::glResize(int width,int height)
{
if (height==0)
height = 1;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLvoid ric::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glColor3f(0.0f,1.0f,0.25f);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25f,0.25f,0.0f);
glVertex3f(0.25f,0.75f,0.0f);
glVertex3f(0.75f,0.75f,0.0f);
glVertex3f(0.75f,0.25f,0.0f);
glEnd();
glFlush();
}
#include<QApplication>
#include"header.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
ric window;
window.glInitialize();
window.glResize(640,480);
window.paintGL();
window.show();
return app.exec();
}
now after compiling and running the project, all I get is a plane blank window... I cannot understand the problem... please help..!! thanks..
here are the relevent files....
#ifndef HEADER_H
#define HEADER_H
#include<QtOpenGl>
class QGLWidget;
class ric:public QGLWidget
{
public:
GLvoid glInitialize();
GLvoid glResize(int width,int height);
GLvoid paintGL();
};
#endif
#include<QGLWidget>
#include"header.h"
GLvoid ric::glInitialize()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
GLvoid ric::glResize(int width,int height)
{
if (height==0)
height = 1;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLvoid ric::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glColor3f(0.0f,1.0f,0.25f);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25f,0.25f,0.0f);
glVertex3f(0.25f,0.75f,0.0f);
glVertex3f(0.75f,0.75f,0.0f);
glVertex3f(0.75f,0.25f,0.0f);
glEnd();
glFlush();
}
#include<QApplication>
#include"header.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
ric window;
window.glInitialize();
window.glResize(640,480);
window.paintGL();
window.show();
return app.exec();
}
now after compiling and running the project, all I get is a plane blank window... I cannot understand the problem... please help..!! thanks..