-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainview.cpp
82 lines (63 loc) · 1.89 KB
/
mainview.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
#include "scenebasic.h"
#include "mainview.h"
#include "glutils.h"
#include <iostream>
#include <cstdio>
using std::cout;
using std::endl;
MainView::MainView(const QGLFormat & format, QWidget *parent) : QGLWidget(format, parent)
{
// This tells the widget to accept keyboard focus when the widget is clicked.
this->setFocusPolicy(Qt::ClickFocus);
timer = new QTimer(this);
connect( timer, SIGNAL(timeout()), this, SLOT(timerUpdate()) );
timer->start(50);
this->setMinimumSize(800,600);
}
void MainView::initializeGL() {
//////////////// PLUG IN SCENE HERE /////////////////
scene = new SceneBasic();
////////////////////////////////////////////////////
GLenum err = glewInit();
if( GLEW_OK != err )
{
cout <<"Error initializing GLEW: " << glewGetErrorString(err) << endl;
}
// GLUtils::checkForOpenGLError(__FILE__,__LINE__);
GLUtils::checkForOpenGLError();
QGLFormat format = this->format();
printf("QGLFormat reports profile: ");
if( format.profile() == QGLFormat::CompatibilityProfile )
printf("compatability.\n");
else if( format.profile() == QGLFormat::CoreProfile )
printf("core.\n");
else
printf("none.\n");
GLUtils::dumpGLInfo();
glClearColor(0.0f,0.0f,0.0f,1.0f);
scene->initScene();
}
void MainView::paintGL() {
GLUtils::checkForOpenGLError();
scene->render();
}
void MainView::resizeGL(int w, int h ) {
scene->resize(w,h);
}
void MainView::toggleAnimation() {
if( timer->isActive() )
timer->stop();
else
timer->start();
}
void MainView::timerUpdate() {
scene->update(1.0f);
updateGL();
}
void MainView::takeScreenShot() {
QImage img = this->grabFrameBuffer(true);
img.save("screen.png", "PNG");
}
Scene* MainView::getScene(){
return this->scene;
}