forked from torriem/QtAgOpenGPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaogrenderer.cpp
131 lines (106 loc) · 3.53 KB
/
aogrenderer.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "aogrenderer.h"
#include <QOpenGLContext>
#include <QQuickWindow>
#include <QOpenGLFramebufferObject>
#include <QOpenGLFunctions_2_1>
#include "formgps.h"
void AOGRenderer::render()
{
/*
QOpenGLContext *c = QOpenGLContext::currentContext();
QOpenGLFunctions_2_1 *gl = c->versionFunctions<QOpenGLFunctions_2_1>();
gl->initializeOpenGLFunctions(); //necessary here?
gl->glClearColor(0.22f,0.2858f,0.16f , 1.0f);
gl->glClear(GL_COLOR_BUFFER_BIT);
//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);
//gl->glFrustum(-2.0, 2.0, -2.0, 2.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(5);
// 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(+,+,+); gl->glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); gl->glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); gl->glEnd();
gl->glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); gl->glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); gl->glEnd();
gl->glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); gl->glEnd();
gl->glLineWidth(1);
# undef V
# undef N
gl->glFlush();
*/
/*
//f->glClearColor( red, green, blue, 1.0f);
f->glClearColor(0.22f,0.2858f,0.16f , 1.0f);
f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
f->glCullFace(GL_BACK);
f->glClear(GL_COLOR_BUFFER_BIT);
ourwindow->resetOpenGLState();
std::cout << "." << std::flush;
*/
/*
if(paintCallback) {
//std::cout << "Attempting to call paint callback." << std::endl;
paintCallback(c);
}
*/
//update();
if(mf) {
if (!isInitialized) {
//call the main form initialize gl function
mf->openGLControl_Initialized();
isInitialized = true;
}
mf->openGLControl_Draw();
}
//win->resetOpenGLState();
}
AOGRenderer::AOGRenderer():
isInitialized(false),win(0),calledInit(false), samples(0)
{
qDebug() << "AOGRenderer constructor here.";
}
AOGRenderer::~AOGRenderer()
{
//call gl cleanup method in main form.
}
void AOGRenderer::synchronize(QQuickFramebufferObject *fbo)
{
//get window
win = fbo->window();
QVariant prop = fbo->property("mainform");
if (prop.isValid()) {
mf = (FormGPS *)prop.value<void *>();
}
prop = fbo->property("samples");
if (prop.isValid()) {
samples = prop.toInt();
}
}
AOGRendererInSG::AOGRendererInSG()
{
theRenderer = NULL;
}
QOpenGLFramebufferObject *AOGRenderer::createFramebufferObject(const QSize &size)
{
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
if(samples) {
format.setSamples(samples);
}
return new QOpenGLFramebufferObject(size,format);
}
AOGRenderer *AOGRendererInSG::createRenderer() const
{
return new AOGRenderer();
}