#ifndef __TEST_HPP#define __TEST_HPP#include <QGLWidget>class QPaintEvent;class Test : public QGLWidget{ Q_OBJECTpublic: Test(QWidget * parent = NULL); ~Test() {};protected: void resizeGL(int w, int h); void paintEvent(QPaintEvent * event); void initializeGL();};#endif
#include <QtOpenGL>#include <QPainter>#include <QPaintEvent>#include <Test.hpp>using namespace MPCAM;Test::Test(QWidget * parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent){ setAttribute(Qt::WA_NoSystemBackground);};void Test::initializeGL(){ glClearColor(0.7, 0.0, 0.0, 0.7);};void Test::resizeGL(int width, int height){ glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, +1.0, +1.0, -1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW);}void Test::paintEvent(QPaintEvent * event){ QPainter painter; painter.begin(this); painter.setRenderHint(QPainter::Antialiasing); glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); resizeGL(width(), height()); glEnable(GL_CULL_FACE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glPopAttrib(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glDisable(GL_CULL_FACE); painter.end();
#include <QApplication>#include <Test.hpp>int main(int argc, char ** argv){ QApplication app(argc, argv); Test * test(new Test()); test->show(); return app.exec();};
void paintEvent( QPaintEvent * e );void paintGL();
glColor3d(0.0, 0.0, 1.0);glBegin(GL_QUADS);glVertex2d(-0.5, 0.5);glVertex2d(0.5, 0.5);glVertex2d(0.5, -0.5);glVertex2d(-0.5, -0.5);glEnd();