Results 1 to 2 of 2

Thread: QGLWidget not updating / drawing / rendering, stays black

  1. #1
    Join Date
    Sep 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QGLWidget not updating / drawing / rendering, stays black

    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
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "WindowWidget.h"
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. WindowWidget w;
    7. w.show();
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    my window class WindowWidget, that does nothing but to add the ogl-widget.
    Qt Code:
    1. #include "WindowWidget.h"
    2. #include "ui_WindowWidget.h"
    3. WindowWidget::WindowWidget(QWidget *parent) : QWidget(parent), ui(new Ui::WindowWidget) {
    4. ui->setupUi(this);
    5. viewer = new MyGLViewer(this);
    6. QHBoxLayout* layout = new QHBoxLayout();
    7. layout->addWidget(viewer);
    8. setLayout(layout);
    9. }
    10. WindowWidget::~WindowWidget() { delete ui; }
    11.  
    12. ---
    13.  
    14. #ifndef WINDOWWIDGET_H
    15. #define WINDOWWIDGET_H
    16. #include <QWidget>
    17. #include "MyGLViewer.h"
    18.  
    19. namespace Ui { class WindowWidget; }
    20.  
    21. class WindowWidget : public QWidget {
    22. Q_OBJECT
    23. public:
    24. explicit WindowWidget(QWidget *parent = 0);
    25. ~WindowWidget();
    26. protected:
    27. Ui::WindowWidget *ui;
    28. MyGLViewer* viewer;
    29. };
    30. #endif // WINDOWWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    my QGLWidget subclass with method stubs. I check if they are called with breakpoints.
    Qt Code:
    1. #ifndef MYGLVIEWER_H
    2. #define MYGLVIEWER_H
    3.  
    4. #include <QGLWidget>
    5. #include <QtOpenGL>
    6.  
    7. class MyGLViewer : public QGLWidget {
    8. Q_OBJECT
    9. public:
    10. MyGLViewer(QWidget *parent=0) : QGLWidget(parent) {}
    11. protected:
    12. void initializeGL() {
    13. // Set up the rendering context, define display lists etc.:
    14. ...
    15. }
    16.  
    17. void resizeGL(int w, int h) {
    18. // setup viewport, projection etc.:
    19. ...
    20. }
    21.  
    22. void paintGL() {
    23. // draw the scene:
    24. ...
    25. }
    26. };
    27. #endif // MYGLVIEWER_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGLWidget not updating / drawing / rendering, stays black

    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.

Similar Threads

  1. Replies: 2
    Last Post: 27th November 2014, 21:28
  2. Rendering offscreen with QGLWidget
    By jcox23 in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2013, 14:37
  3. QGLWidget renders black
    By jonasbalmer in forum General Programming
    Replies: 2
    Last Post: 24th January 2010, 15:32
  4. 3D rendering on Ubuntu using QGLWidget
    By sanjayshelke in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2009, 12:05
  5. Tile rendering with QGLWidget
    By h123 in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 22:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.