Jump to content

  • Log In with Google      Sign In   
  • Create Account

Qt and OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Laval B   Crossbones+   -  Reputation: 5670

Like
0Likes
Like

Posted 28 November 2013 - 05:04 AM

Hello everyone.

 

I have started porting our map editor from a MFC sdi application to a Qt application and i'm having issues with OpenGL. By the way i'm quite new to Qt. I'm nusing Qt 5.1.1 with Visual Studio 2012 toolchain and Qt Creator 2.8.1.

 

I have a QApplication with a main window derived from QMainWindow. The main window contains a few docking windows on the right, left and bottom docking area. For the main widget of the main window i subclassed QGLWidget for rendering. For some reason this widget is all black.

 

The QGLWidget subclass overrides only the initializeGL, resizeGL and painGL methods. The code for these methods is minimal :

/////////////////////////////////////////////////////////////////////////////////////////
/// One time initialization.
void SceneView::initializeGL()
{
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Called when the widget is resized.
void SceneView::resizeGL(int w, int h)
{
    // Setup viewport, projection etc.
    glViewport(0, 0, (GLint)w, (GLint)h);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Called when the widget is redrawn.
void SceneView::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT);
}

Whatever the clear color i chose, the widget is always black.

 

I have tried creating the widget with and without parent, creating the widget alone (only window in the application) and it didn't change anything. I have tried to call swapBuffers (which, according to the documentation i shouln't do) and it didn't work.

 

Also, i have notices that, when resizing either one of the docking widget, there is some flickering (only when the widgets are docked). This doesn't appen if i replace the central widget by a QTextEdit for example.

 

Anyone have any idea what the problem could be ? Some of the examples used basically the same method and they work.


Edited by Laval B, 28 November 2013 - 05:53 AM.

We think in generalities, but we live in details.
 
Alfred North Whitehead

Sponsor:

#2 Sponji   Members   -  Reputation: 1399

Like
0Likes
Like

Posted 28 November 2013 - 05:23 AM

GL_COLOR_CLEAR_VALUE? I think you want to use GL_COLOR_BUFFER_BIT instead.


Derp

#3 Laval B   Crossbones+   -  Reputation: 5670

Like
0Likes
Like

Posted 28 November 2013 - 05:54 AM

GL_COLOR_CLEAR_VALUE? I think you want to use GL_COLOR_BUFFER_BIT instead.

 

 

I'm sorry, wrong copy/past, GL_COLOR_BUFFER_BIT doesn't work.


We think in generalities, but we live in details.
 
Alfred North Whitehead

#4 Sponji   Members   -  Reputation: 1399

Like
0Likes
Like

Posted 28 November 2013 - 06:13 AM

Have you tried using qglClearColor? Or calling glClearColor before clearing? Qt probably calls glClearColor by itself before going in the paintGL method.


Derp

#5 BitMaster   Crossbones+   -  Reputation: 4660

Like
0Likes
Like

Posted 28 November 2013 - 06:56 AM

Check exactly which Qt version you have downloaded. The 5.x generation of Qt is so far available in two versions: one using real OpenGL and one using OpenGL ES via a DirectX emulator. If you are using the emulated OpenGL you need to make sure all your OpenGL is including the emulator headers (somewhere in Qt 3rdparty folder) and you cannot just link to the usual OpenGL libraries.

#6 Brother Bob   Moderators   -  Reputation: 8713

Like
1Likes
Like

Posted 28 November 2013 - 07:57 AM

I think I remember some members here having "problems" with Qt and OpenGL before, and I believe the problem was, in short, that Qt deactivated the rendering context at certain points. The solution was simply to reactivate it in the rendering function. Looking at the Qt tutorials and the documentation for the QGLWidget, it looks like you need to call the makeCurrent member on the QGLWidget as soon as you enter the rendering function.

 

I haven't used any of the OpenGL interfaces in Qt yet so I don't know if this is relevant, but take a look at it at least.



#7 Laval B   Crossbones+   -  Reputation: 5670

Like
0Likes
Like

Posted 28 November 2013 - 08:11 AM

Have you tried using qglClearColor? Or calling glClearColor before clearing? Qt probably calls glClearColor by itself before going in the paintGL method.

 

qglClearColor doesn't change anything. According to the documentation the only functions that are called by the framework are makeCurrent and swapBuffers. I have also tried calling makeCurrent in renderGL, initializeGL and resizeGL to make sure the right context was used and it didn't change anything. According to the documentation, you only need to call makeCurrent if you call gl functions outside of those functions (the overriden ones).

 

 

Check exactly which Qt version you have downloaded. The 5.x generation of Qt is so far available in two versions: one using real OpenGL and one using OpenGL ES via a DirectX emulator. If you are using the emulated OpenGL you need to make sure all your OpenGL is including the emulator headers (somewhere in Qt 3rdparty folder) and you cannot just link to the usual OpenGL libraries.

 

I'm using Qt 5.1.1 for Windows 64 bits VS2012. There is a version of Qt 5.1.1 for Windows 64 bits VS2012 OpenGL which is not the one i'm using. Is that what you are referring to ?

 

An emulated framework limited to OpenGL ES is definitely not what i need. The engine uses core profile 3.3 and above. 


Edited by Laval B, 28 November 2013 - 08:20 AM.

We think in generalities, but we live in details.
 
Alfred North Whitehead

#8 BitMaster   Crossbones+   -  Reputation: 4660

Like
0Likes
Like

Posted 28 November 2013 - 08:28 AM

I'm pretty sure you are using the OpenGL ES emulator version. To be sure check if there is a libEGL.dll and libGLESv2.dll in your bin directory with the rest of the Qt DLLs.

#9 Laval B   Crossbones+   -  Reputation: 5670

Like
0Likes
Like

Posted 28 November 2013 - 08:57 AM

I'm pretty sure you are using the OpenGL ES emulator version. To be sure check if there is a libEGL.dll and libGLESv2.dll in your bin directory with the rest of the Qt DLLs.

 

Yes, these dll are present. I have downloaded the OpenGL version. It works but now when i resize the docking windows, or the application for that matter, everything is flickering alot whether or not i am running in debug or in release. Before, there was only a small flicker in debug mode.


We think in generalities, but we live in details.
 
Alfred North Whitehead

#10 BitMaster   Crossbones+   -  Reputation: 4660

Like
0Likes
Like

Posted 28 November 2013 - 09:07 AM

I can think of two possible causes:
1) You are rendering in the update thread. At least when using QtQuick the thread that is doing all the rendering (and is the only one allowed to) is always a different thread from the normal update thread.
2) You are polluting the GL state. At least QtQuick is a bit picky about anyone changing the GL state. Make sure any buffers bound (especially vertex and index buffer) are restored to their orginal value when you are done rendering. Also, the cull mode (whether or not it is enabled and the cull face) need to be preserved. Saving these states allowed me to integrate the rather monolithic renderer I have to work with with Qt.

#11 Laval B   Crossbones+   -  Reputation: 5670

Like
0Likes
Like

Posted 28 November 2013 - 09:33 AM


You are rendering in the update thread. At least when using QtQuick the thread that is doing all the rendering (and is the only one allowed to) is always a different thread from the normal update thread.

 

The only place i'm calling opengl functions are in initializeGL, paintGL and resizeGL as recomended in the documentation.

 

 

 


You are polluting the GL state. At least QtQuick is a bit picky about anyone changing the GL state. Make sure any buffers bound (especially vertex and index buffer) are restored to their orginal value when you are done rendering. Also, the cull mode (whether or not it is enabled and the cull face) need to be preserved. Saving these states allowed me to integrate the rather monolithic renderer I have to work with with Qt.

 

I'm not sure when i need to save and restore these states. Everything is flickering when i'm resizing something, even the scrollbars of the docking windows. The problem is related to the OpenGL Widget though since it doesn't happen if i replace it with a standard widget like QTextEditor.


Edited by Laval B, 28 November 2013 - 01:43 PM.

We think in generalities, but we live in details.
 
Alfred North Whitehead

#12 BitMaster   Crossbones+   -  Reputation: 4660

Like
1Likes
Like

Posted 28 November 2013 - 09:41 AM

Unfortunately I don't think I can be of more help then. My experience is primarily with QtQuick, the application uses no widgets (just a top level window and the contained QtQuick UI). You might have better luck producing a minimum code sample that shows the problem and posting it on a Qt-dedicated forum like over at qt-project.org.

#13 Laval B   Crossbones+   -  Reputation: 5670

Like
0Likes
Like

Posted 28 November 2013 - 09:43 AM

Unfortunately I don't think I can be of more help then. My experience is primarily with QtQuick, the application uses no widgets (just a top level window and the contained QtQuick UI). You might have better luck producing a minimum code sample that shows the problem and posting it on a Qt-dedicated forum like over at qt-project.org.

 

Thank you very much for your help, it's appreciated.

 

As a complementary info : if i remove the docking windows to keep only the GLWidget, it is flickering when i resize the app. If i compile and run the examples, they are flickering too. They were not with the other Qt version.

 

I'll follow your advice and post the code on a Qt forum.


Edited by Laval B, 28 November 2013 - 09:52 AM.

We think in generalities, but we live in details.
 
Alfred North Whitehead




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS