PDA

View Full Version : OpenGL and windows.



IronPeter
12-06-2000, 10:14 AM
I want to create multi-windowed application, but I don't
want to create many threads.
I try:

loop
{
wglMakeCurrent(hdc1,ghlrc1);

//paint in first window

wglMakeCurrent(hdc2,ghlrc2);

//paint in second window
}

But system crushes. Help me, please.

Thanks, Peter.

[This message has been edited by IronPeter (edited 12-09-2000).]

memo
12-07-2000, 04:41 AM
I'm not sure about it (I use glut) but maybe you should try:

loop
{
wglMakeCurrent(hdc1,ghlrc1);

//paint in first window

wglMakeCurrent(hdc1,NULL);

wglMakeCurrent(hdc2,ghlrc2);

//paint in second window

wglMakeCurrent(hdc2,NULL);
}

Or something like that.

martin_marinov
12-08-2000, 01:23 AM
Haw many device contexes r u using?
For example there is a limitaiton in Win9x for the number of the reserved HDCs. NT doesn't have such a problem. In 9x platform you can use CS_OWNDC in your window class style...(this will help preventing the crash)
Also I may point, that using wglMakeCurrent & MDI app is very slow solution - wglMakeCurrent is really a slow operations - I have tried it, and so it's written on the NVidia developers FAQ. Try to use SDI app, and to divide the view with glViewport...

softland_gh
12-13-2000, 02:39 AM
I am not sure, but maybe OpenGL can't switch to another rendering context if it didn't finish rendering previous one. So, you shouldn't call wglMakeCurrent until you are sure that all GL commands for the other rendering context are processed. You do so by calling glFinish instead of glFlush. glFlush returns immediately before finishing rendering. Try it.

George

SUALK2
12-13-2000, 07:12 AM
From your pice of Code I see that you create a single rendering Context for each Window. This is not nescessary and uses huge amounts of MEM especially on GForce Cards btw. ! You should create one rendering context and then bind it to the Device context of the window you are currently drawing in. Then in your WM_PAINT handler of every window you call:
wglMakeCurrent(CurDC, GlobalRC);
// Draw
wglMakeCurrent(NULL, NULL); // Make the rendering context usable to other device contexts i.e windows. This will work.

If you want to keep your code you should try the following:
loop
{
wglMakeCurrent(hdc1,ghlrc1);

//paint in first window

glFlush(); or glFinish();
wglMakeCurrent(NULL, NULL);

wglMakeCurrent(hdc2,ghlrc2);

//paint in second window

glFlush(); or glFinish();
wglMakeCurrent(NULL, NULL);
}

IronPeter
12-13-2000, 12:37 PM
Thank you SUALK2. It works fine. I did not
think that single rendering context can be used for multi-window rendering.

Also please excuse my English.