This is my first try mixing OpenGL and MFC. Up until this part I have just used GLUT. I thought that the question was a little vague, do you have any idea where I should be looking?
At the bottom of this are my OnCreate(), OnPaint(), PreCreateWindow(), and SetPixelformat(). If you can think of anything else that it might be, let me know, and I will post that.
-Drew
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_hgldc = ::GetDC(m_hWnd); // Get a device context for OpenGL
if(!SetPixelformat(m_hgldc)) // set pixel format
{
::MessageBox(::GetFocus(),"SetPixelformat Failed!","Error",MB_OK);
return -1;
}
m_hglRC = wglCreateContext(m_hgldc); // Create an OpenGL rendering context
int i= wglMakeCurrent(m_hgldc,m_hglRC); // Make rendering context current
InitGL(); // Initialize OpenGL
hIcon = GetIcon( IDI_ICON1 );
CWnd::SetIcon( hIcon, TRUE );
return 0;
}
void CMainFrame::OnPaint( void )
{
CPaintDC dc( this );
if( m_bPlay && m_pCurrent != NULL )
{
TimerWait( FRAMERATE );
}
DrawGLScene();
SwapBuffers(m_hgldc);
Invalidate(FALSE);
}
BOOL CMainFrame::PreCreateWindow( CREATESTRUCT& cs )
{
if(!CFrameWnd::PreCreateWindow(cs))
return FALSE;
cs.style &= ~FWS_ADDTOTITLE; // keep MFC from adding to title
// Set the initial size of the window
cs.cx = m_nWindowWidth;
cs.cy = m_nWindowHeight + WIN_COMPS;
cs.x = 100;
cs.y = 100;
return CFrameWnd::PreCreateWindow(cs);//TRUE;
}
BOOL CMainFrame::SetPixelformat(HDC hdc)
{
PIXELFORMATDESCRIPTOR *ppfd;
int pixelformat;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_GENERIC_FORMAT |
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
32, // 32-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
8, // no alpha buffer
0, // shift bit ignored
8, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
64, // 64-bit z-buffer
8, // stencil buffer
8, // auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
ppfd = &pfd;
if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
{
::MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
return FALSE;
}
if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
{
::MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
return FALSE;
}
return TRUE;
}