Advertisement Jump to content
Sign in to follow this  
Laval B

OpenGL Qt and OpenGL

This topic is 1881 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!