How to call OpenGL draw calls from non QOpenGLWidget object?
-
wrote on 11 May 2019, 20:24 last edited by kduvnjak15 5 Nov 2019, 20:26
Hi all,
Sorry for noob question, but I am new to this and desperately need help. I am making a CAD model viewer; that is OpenGL 3D viewer in QT application.
In short, code looks like this:
class Viewer: public QOpenGLWidget, protected QOpenGLFunctions_4_3_Core;
Viewer has InitializeGL, ResizeGL and PaintGL implemented and Viewer works fine. Imported model renders fine and interacts with mouse.
Problems is that I want different paintGL modes(default, pick, polygon). If I create interface object :
// interface class ViewerMode{ virtual void paintGL() = 0; }; class DefaultViewerMode: public ViewerMode; class PickViewerMode: public ViewerMode; class PolygonViewerMode: public ViewerMode;
While implementing paintGL, why OpenGL draw calls from these object crash application ? Why ? What am I missing?
Do these modes also need to be widgets? Why
Is it a context problem? Why?Any help, reference, link, explanation or hint is very much appreciated!!!
-
Hi and welcome to devnet,
How are you using these ViewerMode subclasses ?
-
wrote on 11 May 2019, 22:43 last edited by kduvnjak15 5 Nov 2019, 23:04
Thanks for your reply.
Viewer class is my QOpenGLWidget, added to my central widget. And its paintGL overriden function initially has glDraw**** functions.
I don't want to have three different Viewer::paintGL functions for three different viewer modes, my idea is to create these new ViewerMode subclasses which have "paintGL" function and place OpenGL draw calls in it.
And simply call paintGL function from current mode:
ViewerMode* tmpViewerMode = new DefaultViewerMode();
Viewer::paintGL(){ tmpViewerMode->paintGL(); }
-
Can you show the code of one of the ViewerMode subclass ?
And the stack trace of the crash ?From the looks of it, you might be using something uninitialised.
-
Can you show the code of one of the ViewerMode subclass ?
And the stack trace of the crash ?From the looks of it, you might be using something uninitialised.
wrote on 12 May 2019, 08:28 last edited byWhen I run my debugger, this is the line its says its the problem:
inline void QOpenGLFunctions_4_3_Core::glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { d_1_1_Core->f.DrawElements(mode, count, type, indices); //<- this line }
But what can be uninitialized ?
Viewer class is initialized, and I also call initializeOpenGLFunctions() once before running DefaultViewerMode::paintGL().
If I leave only this in paint function:
DefaultViewerMode::paintGL(){ glClear(GL_COLOR_BUFFER_BIT); return; }
then application runs fine, renders color I defined.
For some reason, draw call from viewerModes crash with segmentation fault and I have no idea why.Is it because it doesn't know where to render? That it doesn't know "where", on "which" window to render? That it is missing some context? I don't understand how this works?
I realize that if Viewer class inherits from QOpenGLWidget, it has some "context"(whatever that is), but what do I need to do to make my ViewerMode subclasses to successfully run glDraw**** functions? Since they are initialized properly and can successfully run glClear function? Does ViewerMode classes also need to be QOpenGLWidgets and why ? Is it enough that they simply inherit from QOpenGLFunctions_4_3_Core?
class ViewerMode : public QOpenGLFunctions_4_3_Core
-
I would both inherit from the QOpenFunctions_XXX class needed and initialise it.
-
wrote on 13 May 2019, 12:09 last edited by
Thanks for the tip. It is enough if object called initializeOpenGLFunctions().
The problem was that I haven't properly defined VAO. That is why draw calls always crashed.
1/7