DarthVictor

Untitled

Apr 18th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. //glwidget.h
  2.  
  3.  
  4. #ifndef _GLWIDGET_H
  5. #define _GLWIDGET_H
  6.  
  7. #include <QtOpenGL/QGLWidget>
  8.  
  9. class GLWidget : public QGLWidget {
  10.  
  11. Q_OBJECT // must include this if you use Qt signals/slots
  12.  
  13. public:
  14. GLWidget(QWidget *parent = NULL);
  15. int op;
  16. int cirx, ciry;
  17. protected:
  18. void initializeGL();
  19. void resizeGL(int w, int h);
  20. void paintGL();
  21.  
  22.  
  23. };
  24.  
  25. #endif /* _GLWIDGET_H */
  26.  
  27. //glwidget.cpp
  28.  
  29. #include <QtGui/QMouseEvent>
  30. #include <QtOpenGL>
  31. #include <GL/freeglut.h>
  32. #include "glwidget.h"
  33.  
  34. GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
  35. setMouseTracking(true);
  36. op=0;
  37. }
  38.  
  39. void GLWidget::initializeGL() {
  40. glDisable(GL_TEXTURE_2D);
  41. glDisable(GL_DEPTH_TEST);
  42. glDisable(GL_COLOR_MATERIAL);
  43. glEnable(GL_BLEND);
  44. glEnable(GL_POLYGON_SMOOTH);
  45. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  46. glClearColor(0, 0, 0, 0);
  47. }
  48.  
  49. void GLWidget::resizeGL(int w, int h) {
  50. glViewport(0, 0, w, h);
  51. glMatrixMode(GL_PROJECTION);
  52. glLoadIdentity();
  53. gluOrtho2D(0, w, 0, h); // set origin to bottom left corner
  54. glMatrixMode(GL_MODELVIEW);
  55. glLoadIdentity();
  56.  
  57.  
  58.  
  59. }
  60.  
  61. void GLWidget::paintGL() {
  62. glClear(GL_COLOR_BUFFER_BIT);
  63.  
  64.  
  65.  
  66. glColor3f(0,1,0);
  67. glBegin(GL_QUADS);
  68. glVertex2f(450,450);
  69. glVertex2f(600,450);
  70. glVertex2f(600,600);
  71. glVertex2f(450,600);
  72. glEnd();
  73. swapBuffers();
  74. }
  75.  
  76. //main.cpp
  77.  
  78.  
  79. #include <QtGui/QApplication>
  80. #include <QtOpenGL/QGLWidget>
  81. #include "glwidget.h"
  82.  
  83. int main(int argc, char *argv[]) {
  84.  
  85. QApplication app(argc, argv);
  86.  
  87. GLWidget window;
  88. window.resize(1600,1200);
  89. window.show();
  90.  
  91. return app.exec();
  92. }
Add Comment
Please, Sign In to add comment