PDA

View Full Version : QGLWidget not updating / drawing / rendering, stays black



kekz
28th September 2012, 19:02
Hi there! I am stuck with a very basic problem with the QGLWidget. The space of the widget is just black, the overwritten methods of my own subclass of QGLWidget, initializeGL resizeGL paintGL, are never called (checked with breakpoints).
So I went back to the Hello GL example, which works correctly. But I can't find noticable difference to the Hello GL example. There the resizeGL gets called with the show() of the window widget. In my program the method is NOT called.
What am I missing so the xGL methods of MyGLViewer get called?

main.cpp

#include <QtGui/QApplication>
#include "WindowWidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WindowWidget w;
w.show();
return a.exec();
}

my window class WindowWidget, that does nothing but to add the ogl-widget.


#include "WindowWidget.h"
#include "ui_WindowWidget.h"
WindowWidget::WindowWidget(QWidget *parent) : QWidget(parent), ui(new Ui::WindowWidget) {
ui->setupUi(this);
viewer = new MyGLViewer(this);
QHBoxLayout* layout = new QHBoxLayout();
layout->addWidget(viewer);
setLayout(layout);
}
WindowWidget::~WindowWidget() { delete ui; }

---

#ifndef WINDOWWIDGET_H
#define WINDOWWIDGET_H
#include <QWidget>
#include "MyGLViewer.h"

namespace Ui { class WindowWidget; }

class WindowWidget : public QWidget {
Q_OBJECT
public:
explicit WindowWidget(QWidget *parent = 0);
~WindowWidget();
protected:
Ui::WindowWidget *ui;
MyGLViewer* viewer;
};
#endif // WINDOWWIDGET_H


my QGLWidget subclass with method stubs. I check if they are called with breakpoints.

#ifndef MYGLVIEWER_H
#define MYGLVIEWER_H

#include <QGLWidget>
#include <QtOpenGL>

class MyGLViewer : public QGLWidget {
Q_OBJECT
public:
MyGLViewer(QWidget *parent=0) : QGLWidget(parent) {}
protected:
void initializeGL() {
// Set up the rendering context, define display lists etc.:
...
}

void resizeGL(int w, int h) {
// setup viewport, projection etc.:
...
}

void paintGL() {
// draw the scene:
...
}
};
#endif // MYGLVIEWER_H

kekz
29th September 2012, 08:42
New day, I figured it out. I'm sorry, just my mistakes: 1. I actually forgot to glClear, so no wonder I got black and not the clearColor I set. 2. I didn't know that breakpoints in headers don't work.