View Full Version : OPENGL MUTILPLE WINDOW RENDERING
03-28-2012, 08:28 AM
Im quite new to opengl rendering.
My problem is that I want to render multiple opengl windows and load different textures to each window to a cube for example.(this is a VIDEO texure).I know how to do all this and render it to a opengl window, but my problem is that when creating another instance of the class it looks like opengl is mixing the textures and i get weird issues, like this:
Window is rendering video 2
Window 2 is rendering video 1
I get image flickering in the textures
I believe this has to do with creating different threads but im not totally sure. Im working with Qt sdk and opengl.
Thanks and hope for your help.
03-28-2012, 09:22 AM
I haven't actually done that myself but I beleive the key is ensuring your contexts are created properly.
You need to enable the sharing of resources using wglxxxx calls to share textures, displaylist and the like.
Framebuffers are not shared across contexts however.
Also, one one thread can be active at any one time, so you need to call wglMakeCurrent to ensure the thread 'owns' the context that it's about to draw to.
03-28-2012, 11:50 AM
03-28-2012, 01:44 PM
Hi thanks for your help both.
Im not sure how to apply your reply V-man.
I do this in the paintgl function?
what am currently doing is:
dc =this->getDC();//this is a qt function
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//my rendering stuff goes here ,creating the cube,creating the //texture,etc....
Whats happens is a black imgage,video is playing in the background as I hear sound playback but cant see it in the openglwidget :(. What am I doing wrong?
Thanks for your help
03-28-2012, 02:35 PM
Creating GL contexts in each drawing call is terrible wrong! Don't do that!
Using GL in Qt is quite simple (at least for basic usage):
1. Derive your widget from QGLWidget
2. Override functions
- resizeGL(int width, int height)
3. Fill the previous functions with appropriate code.
In paintGL you already have active GL context so you can call GL commands immediately. Please, take a look at any Qt OpenGL tutorial.
For sharing contexts use the following constructor:
QGLWidget::QGLWidget ( QGLContext * context, QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WindowFlags f = 0 )
Take a look at Qt help (http://doc.qt.nokia.com/4.7-snapshot/qglwidget.html#QGLWidget-2)
03-28-2012, 04:15 PM
ok ive deleted the context part from tha paintgl, thank you, but im still having the same issue.
I know,creating glwidgets and reimplementing initializegl,resizegl,paintgl is quite easy in qt, for basic stuff.
So i dont know if im wrong, should i create a new qglcontext for each instance of my glwidget?(please any sample would be great)
The problems is that Im creating multiple widgets from the same mainwindow thread and displaying them in the maindwindow but got no idea how to change each of the qglwidgets to another thread ,or it is not necessary to do that?
Again thanks for all your help.
03-29-2012, 12:38 AM
Each window device context need its own OpenGL context. When you want to draw into a window, select the window device context and its matching own OpenGL context before rendering that view.
OpenGL is not thread safe so it is usually easier to have only one thread rendering windows.
something like this
for (int i = 0; i < window_count; i++
you can share most resources but I would try getting things going without sharing first then look at shared resources
03-29-2012, 05:24 PM
Thanks everybody, all your comments were very helpful!!
I solve my issue with wglMakeCurrent :D. I know can play over 12 video files at the same time with no lag or flickering or any weird stuff happening and in different windows!
Again thanks for your help all!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.