PDA

View Full Version : QGLWidget renders black even though it's supposed to be green



manucsek
5th February 2013, 21:16
Hi,

I'm using Qt 5.0 (I checked on the forums if there were similar issues, I tried them all, but they were related to Qt 4.x).
My problem is that my QGLWidget subclass is black even though I'm clearing it to green.

GLIntercept reports similar errors for all of my GL calls:
Function glClearColor is being called before context creation
Call to glClearColor made outside of context/init

Here is my code:

HEADER FILE


#include <QtOpenGL>

#ifndef GLWIDGET_H
#define GLWIDGET_H

class GLWidget : public QGLWidget
{
Q_OBJECT
protected:
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
public:
GLWidget();
};

#endif
CPP FILE

#include "stdafx.h";

GLWidget::GLWidget()
{
setFixedWidth(256);
setFixedHeight(256);
}

void GLWidget::initializeGL()
{
glClearColor(0.0, 1.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}

void GLWidget::resizeGL(int w, int h)
{
glViewport(0, 0, (GLint)w, (GLint)h);
}

void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
}

I might as well mention that I use the precompiled Qt binaries for Visual Studio.

Can somebody please advise me on what to do to fix this?
Thanks in advance!