OPENGL MUTILPLE WINDOW RENDERING

HI everyone,
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.

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.

http://www.opengl.org/wiki/Platform_specifics:_Windows#Multiple_Windows

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:

void glwidget::paintGl()
{
HDC dc;
dc =this->getDC();//this is a qt function

HGLRC rc;
rc =wglCreateContext(dc);

wglMakeCurrent(hdc, glrc);
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…
SwapBuffers(hdc);
wglMakeCurrent(NULL, NULL);

}

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

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
  • initializeGL()
  • resizeGL(int width, int height)
  • paintGL()
  1. 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

hi thanks,
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.

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++
{
  wglMakeCurrent(hdc[i], glrc[i]);
  call_render_for_window(i);
}

you can share most resources but I would try getting things going without sharing first then look at shared resources

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!