#include <QGLWidget>#include "ui_mygldrawer.h"#include <QtOpenGL>class MyGLDrawer : public QGLWidget { Q_OBJECT public: MyGLDrawer(QWidget *parent) ; ~MyGLDrawer (); protected: void initializeGL(); void paintGL(); void resizeGL (GLint, GLint); };MyGLDrawer :: MyGLDrawer(QWidget *parent) : QGLWidget(parent) {resize(500, 500);}MyGLDrawer::~MyGLDrawer(){}void MyGLDrawer :: resizeGL(int w, int h) { glViewport(0, 0, (GLint)w, (GLint)h); }void MyGLDrawer ::initializeGL() { glClearColor (0, 0, 0, 1); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }void MyGLDrawer ::paintGL () { glBegin (GL_LINES); glColor3ub (230, 230, 230); qglColor (qRgb (255,255,255)); glVertex2i (20, 30) ; glVertex2i (113.0, 4.0); glVertex2i (511.0, 61.0); glVertex2i (7.0, 8.0); glEnd(); }
room2::room2(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ drawer = new MyGLDrawer(this); }
room2::room2(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ drawer = new MyGLDrawer(this); setCentralWidget(drawer);}
#include <QtOpenGL>#include <QApplication>class MyGLDrawer : public QGLWidget{ Q_OBJECT public: MyGLDrawer(QWidget *parent) ; ~MyGLDrawer ();protected: void initializeGL(); void paintGL(); void resizeGL (GLint, GLint);};MyGLDrawer :: MyGLDrawer(QWidget *parent): QGLWidget(parent) { resize(500, 500);}MyGLDrawer::~MyGLDrawer(){}void MyGLDrawer :: resizeGL(int w, int h){ glViewport(0, 0, (GLint)w, (GLint)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0, w, h, 0, -1, +1 ); updateGL();}void MyGLDrawer ::initializeGL(){ glClearColor (0, 0, 0, 1);}void MyGLDrawer ::paintGL (){ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); qglColor (qRgb (255,255,255)); glBegin (GL_LINES); glVertex2i (20, 30) ; glVertex2i (113.0, 4.0); glVertex2i (511.0, 61.0); glVertex2i (7.0, 8.0); glEnd();}