Advertisement

several independent glut windows

Started by December 21, 2001 01:23 PM
4 comments, last by guille 23 years, 1 month ago
Hi people!! I would like to make a little application that uses several (let''s say 4) OpenGL GLUT windows. I''ve tried to create a thread (CWinThread) for each window, and from the InitInstance method, I do my initialization and finally I call glutMainLoop(). This, of course, creates the window and starts its loop. The problem is when I want to finish. How can the application kill each thread and how can each thread kill its glut window? I''ve tried using a timer attached to each thread. When the application wants to finish, it sets a boolean variable so each thread knows (checks this boolean in its timer) that has to end. Something like... VOID CALLBACK TimerProc( HWND hwnd, // handle of window for timer messages UINT uMsg, // WM_TIMER message UINT idEvent, // timer identifier DWORD dwTime // current system time ) { if (bFinishTheThread) { // CLEAN UP } } The point is what to do in the CLEAN UP. I''ve tried (but I don''t how it works...) to call glutDestroyWindow with the id of its glut window ->crash and call :ostQuitMessage(0) to end with this thread ->ends with all the threads and the application with memory leaks. The point is that I want to use several independent glut windows (not subwindows), and I want to create and destroy them whenever I want. I hope I was clear, even my poor english. Thanks for your time! Cheers =], guille ps: for those who have holidays, enjoy them!!!
I do not think that you can use GLUT with multiple threads running at the same time. You can have several windows open the same time but only one would be active and running. If you have this is it confusing to call it multiple threads since that word is used for several programs running at the same time.

Yes, call glutDestroyWindow to destroy one of the windows. Do not mix GLUT and native Windows code that can be the reason for your crash.

Edited by - Obelix on December 22, 2001 5:54:28 AM
Advertisement
I can''t find the way to do that (multiple windows, only one active at one time).
Do you have any ideas?
I tried to do the same thing a while back, and got similar results. Your problem is that OpenGL cannot have multiple ACTIVE rendering contexts. You have to switch them on/off when needed.

First off, I have to let you know, that I''ve only done this with the standard GL lib''s. I don''t use GLUT. But it can be done.
But it does take some setup.
1. Setup an event handler so that when the window is activted it sets its personal rendering context as current.

wglMakeCurrent(hdc, hrc);
(I usually call a refresh right here)

2. Setup an event handler so that when the window is deactivated it sets the rendering context to NULL

wglMakeCurrent(hdc,NULL);

3. Lastly you''ll need an event handler for when the window is created. This will get the Device Context of the current window, and set the personal rendering context of the window.

hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);

I think that''s all of it.
Good luck!
I think that GLUT is taking care of all Win32 and wgl calls. As a sidenote, do you really have to do 2 in the list above?

For GLUT is it something like this:
win1=glutCreateWindow(...);
/* setup the callbacks for win1 */
...
win2=glutCreateWindow(...)
/* setup the callbacks for win2 */

Every window will have a own context so resources available for one window, like textures, is not shared with the other window. It is not like one OpenGL machine with several windows but more like several machines with their own windows.

If you want one machine with several displays is it much better to use one window and divides it into "subwindows". You can do that in a similar way with GLUT. Here is a tutorial about GLUT subwindows but it is the same for normal Windows.
http://www.lighthouse3d.com/opengl/glut/index.php3?subwin

I''ve find out that with GLUT I can not do what I wanted, so I''m using the standard GL lib''s.

I''ve created some opengl windows, and I set their personal rendering context like Codeboy said. It goes perfect.

Lets say that I have four windows. In the first one I have the scene that I am using and I just want to move from one point to another of the scene, using gluLookAt.

When I want to update one of the windows, I do it directly from the code: setting its rendering context, do my geometry stuff (gluLookAt, etc) and swaping buffers. At this stage, the window does not reflect the changes until I set the focus on it. The only way I can do this is showing the window (ShowWindow), because the function SetFocus does not reflect the changes (?).

So, there is a window flickering everytime I do an "animation".

Any ideas of how can I fix this?

cheers,
g

This topic is closed to new replies.

Advertisement