PDA

View Full Version : GraphicViews And OpenGL



RobStar
15th January 2014, 11:44
Hi,

I am a recently retired software developer and total newcomer to QT and OpenGL ( Although I did have some exposure to OpenGL in the late 80's , has it changed ) . My interests are in Astronomy and astronomy software applications. For the last twenty years I have been developing computational geometry algorithms for a major graphics software vendor. I haven't developed a GUI since 1995 so what an eye opener QT is. It was a choice between QT or .Net . After exposure to a number of very professional and stable QT astronomy applications and a desire to move away from managed code I decided to spend my retirement graphics programming in QT and OpenGL and with maybe a bit of Angle.

I have a problem with OpenGL not drawing ( not displaying ) after the initial draw. The call to do the draw is invoked from QGraphicsView::drawBackground and I am using glDrawElements to draw 2 million triangles. On the first call the triangles are drawn correctly in an incredible 60 milli seconds. For the second and subsequent calls they just don't appear on the screen. I have set the view port to a QGLWidget and I am using gLOrtho to set the transformation from my real world coordinates. The problem could be due to my inexperience in initializing and sequencing the OpenGL calls correctly. However on the second and subsequent calls I can draw lines with openGL if I express their coordinates in screen coordinates.

I would appreciate some advice on the correct sequencing of the OpenGL calls for this requirement or referral to some OpenGL example that shows this. Or consequently any advice on what I may be doing incorrectly.

Rob

stampede
15th January 2014, 12:11
Typically for OpenGL you want to subclass QGLWidget and reimplement three methods:
1) initializeGL() (http://qt-project.org/doc/qt-4.8/qglwidget.html#initializeGL)
2) resizeGL() (http://qt-project.org/doc/qt-4.8/qglwidget.html#resizeGL)
3) paintGL() (http://qt-project.org/doc/qt-4.8/qglwidget.html#paintGL)
Using opengl calls for rendering outside of QGLWidget requires to call beginNativePainting() (http://qt-project.org/doc/qt-5.0/qtgui/qpainter.html#beginNativePainting) method of QPainter object.
some opengl + Qt examples : link (http://qt-project.org/doc/qt-4.8/examples-opengl.html)
Btw. nice retirement plan :)

RobStar
16th January 2014, 05:04
Thanks for the response Stampede.

I fixed the problem. I wasn't pushing and popping the current transformation matrix. Explains why the coordinates were being screwed.

As I am using a QGLWidget for the QGraphicView view port there was no need to wrap the opengl calls with begin and end native painting calls.

Rob