class MyOGL : public QGLWidget{protected: virtual void initializeGL(); virtual void resizeGL(int nWidth,int nHeight); virtual void paintGL();public: MyOGL(QWidget *parent = 0);};
MyOGL::MyOGL(QWidget *parent) : QGLWidget(parent){}void MyOGL::initializeGL(){ qglClearColor(Qt::black); glViewport(0,0,200,200);}void MyOGL::resizeGL(int nWidth,int nHeight){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0,0,(GLint)nWidth,(GLint) nHeight); glOrtho (0,100,100,0,-1,-1);} void MyOGL::paintGL(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glColor3f(1,0,0); glVertex2f(0,0); glColor3f(1,0,0); glVertex2f(0,200); glColor3f(1,0,0); glVertex2f(100,200); glColor3f(1,0,0); glVertex2f(100,0); glEnd();}
int main(int argc, char *argv[]){ QApplication a(argc, argv); MyOGL test; test.resize(200,200); test.show(); return a.exec();}
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );
glOrtho(0, nWidth, 0, nHeight, -1, 1 );