Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test.hpp
- #ifndef TEST_H_
- #define TEST_H_
- #include <QWindow>
- class QBackingStore;
- class QTimer;
- class QResizeEvent;
- class QOpenGLContext;
- class QOpenGLPaintDevice;
- class Test
- : public QWindow
- {
- Q_OBJECT
- public:
- Test();
- private slots:
- void mainLoop();
- private:
- void resizeEvent(QResizeEvent *);
- void init();
- void render();
- QTimer *timer;
- QOpenGLContext *glContext;
- };
- #endif
- //test.cpp:
- #include "test.hpp"
- #include <QtGui>
- #include <iostream>
- #include <stdlib.h>
- #include <QOpenGLFunctions_4_3_Compatibility>
- Test::Test()
- :QWindow()
- ,timer(new QTimer())
- ,glContext(new QOpenGLContext)
- {
- setSurfaceType(QWindow::OpenGLSurface);
- setGeometry(100, 100, 600, 500);
- glContext->setFormat(requestedFormat());
- glContext->create();
- connect(timer, SIGNAL(timeout()),
- this, SLOT(mainLoop()));
- timer->start(1000/60);
- }
- void Test::init()
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glViewport(0, 0, width(), height());
- glOrtho(0, width(), 0, height(), -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void Test::resizeEvent(QResizeEvent *e)
- {
- init();
- }
- void Test::mainLoop()
- {
- if(isExposed())
- render();
- }
- void Test::render()
- {
- //init
- glContext->makeCurrent(this);
- static bool inited = false;
- if(!inited)
- {
- inited = true;
- init();
- }
- //reder
- static int x=0;
- static int y=0;
- x++; y++;
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3d(1, 1, 1);
- glBegin(GL_LINE_LOOP);
- glVertex2d(x, y);
- glVertex2d(x+50, y);
- glVertex2d(x+50, y+50);
- glVertex2d(x, y+50);
- glEnd();
- glContext->swapBuffers(this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement