How can i render opengl to an MFC Frame Control ?
I believe That OpenGL can be render to any win32 control,Since
I have done this in the past but with win32 api not MFC.
When I do the same thing with MFC it won’t work.
//----------------code------------------------
void MainDialog::EnableOpenGL(int colorbits,HWND openGLHwnd,int width,int height)
{
int iFormat;
PIXELFORMATDESCRIPTOR pfd={
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
colorbits,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
hDC = GetDC (hWnd);
iFormat = ChoosePixelFormat (hDC, &pfd);
SetPixelFormat (hDC, iFormat, &pfd);
hRC = wglCreateContext(hDC );
wglMakeCurrent(hDC,hRC);
if (height==0)
{
height=1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,width,0,height,-1,1);
}
int MainDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
HWND openGLFrameHandle = ::GetDlgItem(this->m_hWnd,FRAME_OPENGL); //---(1)
EnableOpenGL(32,openGLFrameHandle,600,400); //---(2)
//EnableOpenGL(32,this->m_hWnd,800,600); --(3)
SetTimer(1,15,NULL);
return 0;
}
void MainDialog::OnTimer(UINT nIDEvent)
{
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SwapBuffers();
CDialog::OnTimer(nIDEvent);
}
//-------------code--------------------------------------
1.This application doesn’t do anything,it just suppose to clear FRAME_OPENGL static(frame)
Control to black color
2.EnableOpenGL is just a function for initialize opengl
3.hDc and hRc are member variable of this class
4.if you comment (1) and (2) and use Maindialog handle (3) instead of FRAME_OPENGL’s handle,
every thing just work fine