385
|
1 #include "edview.h"
|
|
2
|
|
3
|
|
4 DemoView::DemoView(QWidget *parent)
|
|
5 : QGLWidget(QGLFormat(QGL::SampleBuffers|QGL::AlphaChannel), parent)
|
|
6 {
|
|
7 makeCurrent();
|
|
8
|
|
9 if (QGLFramebufferObject::hasOpenGLFramebufferBlit())
|
|
10 {
|
|
11 QGLFramebufferObjectFormat format;
|
|
12 format.setSamples(4);
|
|
13 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
|
|
14
|
|
15 render_fbo = new QGLFramebufferObject(512, 512, format);
|
|
16 texture_fbo = new QGLFramebufferObject(512, 512);
|
|
17 }
|
|
18 else
|
|
19 {
|
|
20 render_fbo = new QGLFramebufferObject(1024, 1024);
|
|
21 texture_fbo = render_fbo;
|
|
22 }
|
|
23 }
|
|
24
|
|
25 DemoView::~DemoView()
|
|
26 {
|
|
27 delete texture_fbo;
|
|
28 if (render_fbo != texture_fbo)
|
|
29 delete render_fbo;
|
|
30 }
|
|
31
|
|
32
|
|
33 void DemoView::paintEvent(QPaintEvent *)
|
|
34 {
|
|
35 draw();
|
|
36 }
|
|
37
|
|
38
|
|
39 void DemoView::draw()
|
|
40 {
|
|
41 QPainter p(this); // used for text overlay
|
|
42
|
|
43 // save the GL state set for QPainter
|
|
44 saveGLState();
|
|
45
|
|
46 // restore the GL state that QPainter expects
|
|
47 restoreGLState();
|
|
48 }
|
|
49
|
|
50
|
|
51 void DemoView::saveGLState()
|
|
52 {
|
|
53 glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
54 glMatrixMode(GL_PROJECTION);
|
|
55 glPushMatrix();
|
|
56 glMatrixMode(GL_MODELVIEW);
|
|
57 glPushMatrix();
|
|
58 }
|
|
59
|
|
60
|
|
61 void DemoView::restoreGLState()
|
|
62 {
|
|
63 glMatrixMode(GL_PROJECTION);
|
|
64 glPopMatrix();
|
|
65 glMatrixMode(GL_MODELVIEW);
|
|
66 glPopMatrix();
|
|
67 glPopAttrib();
|
|
68 }
|