Alex Rivera | Logout

Overpainting and post-render effects on QGLView (not QGLWidget) in Qt3D

Asked 2012-09-12T23:40:44.950
13

I'm currently writing a game in C++/Qt5 using the Qt3D module.

I can render the scene (QGLSceneNodes) on a QGLView but am now stuck on overpainting the scene with some GUI elements. I haven't decided yet whether to use QML or C++ to define the look and feel of the interface, so I'm open to solutions for both. (Note that the QML module is called QtQuick3D, the C++ module is called Qt3D and they are both part of Qt5.)

I'm very much preferring a QML based solution.

How can I do some overpainting?

The following things have to be possible:

  • Draw 2D items (images) at given screen coordinates, of course with support for alpha channels.
  • Draw text using system fonts, maybe by first painting on a image and using this as a texture in the Qt3D OpenGL context.
  • Reacting on mouse input in screen coordinates (in contrast to 3D scene object picking).

I think this is all possible using just another QGLSceneNode for the 2D GUI part. But I think positioning and orienting some scene node in order to just be re-oriented and re-positioned during rendering (using the vertex shader) doesn't make sense, introduces numerical errors and seems inefficient.

Is using another "GUI" vertex shader the correct way?

(How) can I make post-rendering effects and overpainting work together?

It would be really nice if I can do the following post-rendering effects:

  • Read the previously rendered scene, apply some 2D image effects (I can imagine to implement those as a fragment shader and render the previously rendered buffer on the final screen using this effect shader). This enables me to make some parts of the GUI look like glass with a blur effect.
  • Some more advanced effects could make the scene look more realistic: depth & motion blur, heat dependent air flickering, glow effects. They can all be described us
Edit
Report

1 Answer

1

resize and events are easy to implement specially if you make a class inherit from qglwidget here is a short video that should help you get started

https://www.youtube.com/watch?v=1nzHSkY4K18

in regards to drawing images and text qt has the qpainter that can help you in doing that, use QGLContext (http://qt-project.org/doc/qt-4.8/qglcontext.html) to pass it the current context and render your label/image/widget at the specific cordinate, but make sure that this function call is the last in your paint event otherwise it will not be on top

to react to mouse event make your class include QMouseEvent header then you can get the coordinates of the mouse within the widget and pass them to opengl by overloading the protected event mouseMoveEvent(QMouseEvent *event){event->pos();}

answered 2013-03-25T21:26:57.807

Your Answer