Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //glwidget.h
- #ifndef _GLWIDGET_H
- #define _GLWIDGET_H
- #include <QtOpenGL/QGLWidget>
- class GLWidget : public QGLWidget {
- Q_OBJECT // must include this if you use Qt signals/slots
- public:
- GLWidget(QWidget *parent = NULL);
- int op;
- int cirx, ciry;
- protected:
- void initializeGL();
- void resizeGL(int w, int h);
- void paintGL();
- };
- #endif /* _GLWIDGET_H */
- //glwidget.cpp
- #include <QtGui/QMouseEvent>
- #include <QtOpenGL>
- #include <GL/freeglut.h>
- #include "glwidget.h"
- GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
- setMouseTracking(true);
- op=0;
- }
- void GLWidget::initializeGL() {
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_COLOR_MATERIAL);
- glEnable(GL_BLEND);
- glEnable(GL_POLYGON_SMOOTH);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glClearColor(0, 0, 0, 0);
- }
- void GLWidget::resizeGL(int w, int h) {
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0, w, 0, h); // set origin to bottom left corner
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void GLWidget::paintGL() {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0,1,0);
- glBegin(GL_QUADS);
- glVertex2f(450,450);
- glVertex2f(600,450);
- glVertex2f(600,600);
- glVertex2f(450,600);
- glEnd();
- swapBuffers();
- }
- //main.cpp
- #include <QtGui/QApplication>
- #include <QtOpenGL/QGLWidget>
- #include "glwidget.h"
- int main(int argc, char *argv[]) {
- QApplication app(argc, argv);
- GLWidget window;
- window.resize(1600,1200);
- window.show();
- return app.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment