changeset 385:eb5b793c8867

GL display widget skeleton.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 18 Oct 2012 20:10:31 +0300
parents e5220ff48bc8
children 69ca8a83c25a
files edview.cpp edview.h
diffstat 2 files changed, 95 insertions(+), 0 deletions(-) [+]
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();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/edview.h	Thu Oct 18 20:10:31 2012 +0300
@@ -0,0 +1,27 @@
+#ifndef EDVIEW_H
+#define EDVIEW_H
+
+#include <QtOpenGL>
+
+class DemoView : public QGLWidget
+{
+    Q_OBJECT
+
+public:
+    DemoView(QWidget *parent);
+    ~DemoView();
+
+    void saveGLState();
+    void restoreGLState();
+
+    void paintEvent(QPaintEvent *);
+
+public slots:
+    void draw();
+
+private:
+    QGLFramebufferObject *render_fbo;
+    QGLFramebufferObject *texture_fbo;
+};
+
+#endif