0

I can't render my scene under a child window which is in my main window. I got two Registered windows:

mainwindow = CreateWindow(bgwinNAME,     
                    TEXT("Benchmark"),
                    WS_OVERLAPPEDWINDOW,   
                    CW_USEDEFAULT,     
                    CW_USEDEFAULT,     
                    CW_USEDEFAULT,     
                    CW_USEDEFAULT,     
                    NULL,              
                    NULL,              
                    hInstance,         
                    NULL);             

ShowWindow(mhwnd, SW_MAXIMIZE);
UpdateWindow(mainwindow);

childwindow = CreateWindow(benchwinNAME,       
                    NULL,
                    WS_CHILD, 
                    (GetSystemMetrics(SM_CXSCREEN)-width)/2,     
                    (GetSystemMetrics(SM_CYSCREEN)-hight)/2,     
                    width,       
                    hight,       
                    mainwindow,              
                    NULL,              
                    hInstance,         
                    NULL);             

UpdateWindow(childwindow);

(the childwindow is later shown)

My loop looks like:

while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;

StartOpenGL(childwindow, &hdc, &hrc );
   // .... my GL functions
SwapBuffers(hdc);
}
StopOpenGL(childwindow, hdc, hrc );
return msg.wParam;  
}

When childwindow is set as a hwnd in StartOpenGL(); there is no reaction I can only see a window with a white bg defined in window class (hbrBackground). When hwnd is set to mainwindow scene renders in it at range of SW_MAXIMIZE.

My StartOpenGL & StopOpenGL functions are from: Link

1 Answer 1

1

Please stop using that Start/Stop OpenGL functions. StartOpenGL sets the windows PIXELFORMATDESCRIPTOR (PFD) which can be done only one time. You do that at best right after creating the window. If your two windows share a compatible PFD (which is the case if you create the child window after the PFDs of the parent has been set; you still need to set the very same PFD for the child then), you can simply use wglMakeCurrent to switch a single OpenGL context between both windows, identified by their HDC.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. I did that (also with wglMakeCurrent) but I Still got nothing. I have noticed that wen I set HWND to NULL in childwindow scene renders but on SW_MAXIMIZE. I will keep looking.
@user2674257: I'd need to see your full code to make any usefull suggestions regarding the SW_MAXIMIZE issue. However Creating a OpenGL context using just the pure Win32 API is not hard; in fact when I was learning OpenGL some 17 years ago, I was constantly hitting roadblocks in using one of the existing, simple OpenGL frameworks (GLUT). So after some frustrating afternoon I quickly hacked my oen Win32-API OpenGL framework, which I used for a long time after.
Here you go: [link]podidnbusko.pl/uploads/images/Main.zip pass: 123456 . Don't worry it is safe I set a password on file so it can pass anti-plagiarism system (this is for study purpose). I would be very grateful if you check it. I did not included opengl code and int width , int hight are: int width = GetSystemMetrics(SM_CXSCREEN)/2 int hight = GetSystemMetrics(SM_CYSCREEN)/2; StartOpenGL and StopOpenGL are in the question link (don't worry I will mention about those source codes in my work and also help that I get here!). Sorry for being such a newbie. Thank you!
also it should be chwnd = CreateWindow(ChildNAME... insted of chwnd = CreateWindow(MainNAME...
ok I finaly got it :) I have put my startopenGL function in the child's WM_PAINT method. Also added few flags so scene can be rendered on demand. Thank you for your time :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.