# HG changeset patch # User Matti Hamalainen # Date 1350580231 -10800 # Node ID eb5b793c8867845ca220c25f6c6d022b0e96de73 # Parent e5220ff48bc8451d652028bc212b9c26080124ed GL display widget skeleton. diff -r e5220ff48bc8 -r eb5b793c8867 edview.cpp --- /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(); +} diff -r e5220ff48bc8 -r eb5b793c8867 edview.h --- /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 + +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