view edview.cpp @ 388:015f2da65841

Add edview to the build.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 18 Oct 2012 20:11:34 +0300
parents eb5b793c8867
children 28a74940f2b6
line wrap: on
line source

#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();
}