Sign in to follow this  
Decrius

OpenGL Multiple OpenGL scene's in win32?

Recommended Posts

Hi, How to draw 4 different OpenGL scene's in 4 different Child windows? In the glViewport function I see no variable which says which window it should be drawn in. I have 4 boxxes (child windows), in each of them I want to show something different with OpenGL. How to do this? Thanks for any suggestion or solving reply :D Decrius

Share this post


Link to post
Share on other sites
To draw to multiple windows, you must use different opengl contexts.

HGLRC wglCreateContext(HDC dc) is the function used to do it. It will take the device context of one of your windows, and return an opengl rendering context.

Then use the following function to tell opengl wich context to use:
BOOL wglMakeCurrent(HDC device context, HGLRC rendering context);
if your windows have the same pixel format, it may be possible to use the same rendering context for all windows (I am not sure about this);

I hope this will solve your problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by Decrius
Thanks for the reply! :)

Should I place that code in the WM_CREATE of the ChildProc?

Decrius


Yes, it's the best place to create a GL context. You will have to setup the GL states for each window.
You can read this as an intro to GL on Windows

http://www.opengl.org/wiki/index.php/Platform_specifics:_Windows

For multiple context GL programming, if all the windows as part of the same thread, then only one context can be current at a time. If you create the windows in different threads (yes, it's possible), then each window can have its context current

glViewport sets up the viewport transform for the vertices, nothing else!

Share this post


Link to post
Share on other sites
Okay, thank you :)

I have the 4 child windows, this is the code of the ChildProc:

LONG WINAPI ChildProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static PAINTSTRUCT ps;

switch(uMsg)
{
case WM_CREATE:
{
...
...
return 0;
}
case WM_SIZE:
{
...
...
return 0;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}


What to fill in? Cant get it to work, not even with getDc etc.

int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst, LPSTR lpszCmdLine, int nCmdShow)
{
HDC hDC;
HGLRC hRC;
HWND hWnd;
MSG msg;

hWnd = Create_Window_Main(0, 0, win_width, win_height, PFD_TYPE_RGBA, 0);
if (hWnd == NULL)
exit(1);

hDC = GetDC(hWnd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);

ShowWindow(hWnd, nCmdShow);

while(GetMessage(&msg, hWnd, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

wglMakeCurrent(NULL, NULL);
ReleaseDC(hWnd, hDC);
wglDeleteContext(hRC);
DestroyWindow(hWnd);

return msg.wParam;
}


That is for hWnd, the main window, but I want it for hChild1, which is not working, neither if I change hWnd, into hChild1.

Any further help would be very appreciated :D

Decrius

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this