diff edview.cpp @ 385:eb5b793c8867

GL display widget skeleton.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 18 Oct 2012 20:10:31 +0300
parents
children 28a74940f2b6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edview.cpp	Thu Oct 18 20:10:31 2012 +0300
@@ -0,0 +1,68 @@
+#include "edview.h"
+
+
+DemoView::DemoView(QWidget *parent)
+    : QGLWidget(QGLFormat(QGL::SampleBuffers|QGL::AlphaChannel), parent)
+{
+    makeCurrent();
+
+    if (QGLFramebufferObject::hasOpenGLFramebufferBlit())
+    {
+        QGLFramebufferObjectFormat format;
+        format.setSamples(4);
+        format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
+
+        render_fbo = new QGLFramebufferObject(512, 512, format);
+        texture_fbo = new QGLFramebufferObject(512, 512);
+    }
+    else
+    {
+        render_fbo = new QGLFramebufferObject(1024, 1024);
+        texture_fbo = render_fbo;
+    }
+}
+
+DemoView::~DemoView()
+{
+    delete texture_fbo;
+    if (render_fbo != texture_fbo)
+        delete render_fbo;
+}
+
+
+void DemoView::paintEvent(QPaintEvent *)
+{
+    draw();
+}
+
+
+void DemoView::draw()
+{
+    QPainter p(this); // used for text overlay
+
+    // save the GL state set for QPainter
+    saveGLState();
+
+    // restore the GL state that QPainter expects
+    restoreGLState();
+}
+
+
+void DemoView::saveGLState()
+{
+    glPushAttrib(GL_ALL_ATTRIB_BITS);
+    glMatrixMode(GL_PROJECTION);
+    glPushMatrix();
+    glMatrixMode(GL_MODELVIEW);
+    glPushMatrix();
+}
+
+
+void DemoView::restoreGLState()
+{
+    glMatrixMode(GL_PROJECTION);
+    glPopMatrix();
+    glMatrixMode(GL_MODELVIEW);
+    glPopMatrix();
+    glPopAttrib();
+}