-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLWidget.cpp
99 lines (91 loc) · 2.23 KB
/
GLWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <QtGui/QMouseEvent>
#include "GLWidget.h"
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
setMouseTracking(true);
}
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);
glRotatef(test,1,1,0);
//bot
glBegin(GL_POLYGON);
glColor3f(1,1,1);
glVertex3f(-0.5,-0.5,0);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
glVertex3f(0.5,-0.5,0);
glEnd();
//back
glBegin(GL_POLYGON);
glColor3f(1,0,0);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
glEnd();
//right
glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex3f(0.5,-0.5,0);
glVertex3f(0.5,0.5,0);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
glEnd();
//front
glBegin(GL_POLYGON);
glColor3f(1,0,0);
glVertex3f(-0.5,-0.5,0);
glVertex3f(-0.5,0.5,0);
glVertex3f(0.5,0.5,0);
glVertex3f(0.5,-0.5,0);
glEnd();
//left
glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex3f(-0.5,-0.5,0);
glVertex3f(-0.5,0.5,0);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(-0.5,-0.5,-0.5);
glEnd();
//top
glBegin(GL_POLYGON);
glColor3f(1,0,1);
glVertex3f(-0.5,0.5,0);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,0.5,0);
glEnd();
}
void GLWidget::mousePressEvent(QMouseEvent *event) {
printf("%d, %d\n", event->x(), event->y());
test = event->x()*0.01;
paintGL();
}
void GLWidget::mouseMoveEvent(QMouseEvent *event) {
}
void GLWidget::keyPressEvent(QKeyEvent* event) {
switch(event->key()) {
case Qt::Key_Escape:
close();
break;
default:
event->ignore();
break;
}
}