-
Notifications
You must be signed in to change notification settings - Fork 22
/
gltest.cpp
55 lines (38 loc) · 1.78 KB
/
gltest.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
#include <QOpenGLFunctions_2_1>
#include <QOpenGLContext>
#include <QSurface>
#include "openglcontrol.h"
void gltest_init (){
}
void gltest_draw (){
QOpenGLContext *glContext = QOpenGLContext::currentContext();
QOpenGLFunctions_2_1 *gl = glContext->versionFunctions<QOpenGLFunctions_2_1>();
int width = glContext->surface()->size().width();
int height = glContext->surface()->size().height();
//glViewport(0, 0, c->viewportSize.width(), c->viewportSize.height());
//gl->glViewport(0, 0, 400, 400);
gl->glMatrixMode(GL_PROJECTION);
gl->glLoadIdentity();
gl->glOrtho(-2.0, 2.0, -2.0, 2.0, -1.5, 1.5);
//glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
gl->glMatrixMode(GL_MODELVIEW);
glClearColor(0.22f, 0.2858f, 0.16f, 1.0f);
gl->glClear(GL_COLOR_BUFFER_BIT);
gl->glLoadIdentity();
//gluLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
gl->glColor3f(1.0f, 1.0f, 1.0f);
double size = 2 * 0.5;
# define V(a,b,c) gl->glVertex3d( a size, b size, c size );
# define N(a,b,c) gl->glNormal3d( a, b, c );
gl->glLineWidth(3);
/* PWO: I dared to convert the code to use macros... */
gl->glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
gl->glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
# undef V
# undef N
gl->glFlush();
}