PDA

View Full Version : wglMakeCurrent for multiple windows in MFC



sguTiger
08-31-2009, 07:34 PM
Hi,
This is a dialog-based application. The dialog holds 2 windows of the same class CWndT with nID=0 and nID=1;
The class CWnd has data member m_hDC, m_hRC to hold its device context and rendering context. I did an experiment as follows.
In the render() of one window (nID=0), I call the render() of another window (nID=1) where I call wglMakeCurrent();
What I expect is that a red line will be draw on the window with nID=1 (I thought that by the time the program reaches the line #1, the render context is associated to the m_hDC and m_hRC of the window with nID=1). But nothing is draw in both window. Why?
The problem can be fixed by uncommenting the line #1. Are there any good ways to make sure that gl functions always draw to the correct window? It seems to me a difficult problem considering the situation that a function may call another function(e.g. MessageBox) which change the flow of control(for example, the control is go to the message handler of another window which call the wglMakeCurrent). I guess there should be a good way to do that.

The segment of code is as follows.
void CWndT::render(void)
{
if(m_hRC != NULL){
wglMakeCurrent(m_hDC, m_hRC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(nID==1) glColor3f(1.0f,0.0f,0.0f);
if(nID==0){
glColor3f(0.0f,1.0f,0.0f);
wndB.render();
//wglMakeCurrent(m_hDC, m_hRC); //#1
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(10.0f,0.0f,0.0f);
glEnd();
}
}
}

Brolingstanz
09-01-2009, 08:23 AM
I'm no MFC expert, but this may be of help to you...

http://msdn.microsoft.com/en-us/library/ms970745.aspx