Ok - here goes.
These are all the initialisations.
All members belong to the view - the document has nothing apart from the RenderScence() method which draws a a sphere.
BOOL CBaseOpenGLMDIView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | CS_VREDRAW);
return CView::PreCreateWindow(cs);
}
BOOL CBaseOpenGLMDIView::CreateViewGLContext(HDC hDC)
{
m_hGLContext = wglCreateContext(hDC);
if (m_hGLContext == NULL)
{
return FALSE;
}
if (wglMakeCurrent(hDC, m_hGLContext)==FALSE)
{
return FALSE;
}
return TRUE;
}
BOOL CBaseOpenGLMDIView::SetWindowPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pixelDesc;
pixelDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixelDesc.nVersion = 1;
pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER |
PFD_STEREO_DONTCARE;
pixelDesc.iPixelType = PFD_TYPE_RGBA;
pixelDesc.cColorBits = 32;
pixelDesc.cRedBits = 8;
pixelDesc.cRedShift = 16;
pixelDesc.cGreenBits = 8;
pixelDesc.cGreenShift = 8;
pixelDesc.cBlueBits = 8;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 64;
pixelDesc.cAccumRedBits = 16;
pixelDesc.cAccumGreenBits = 16;
pixelDesc.cAccumBlueBits = 16;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 32;
pixelDesc.cStencilBits = 8;
pixelDesc.cAuxBuffers = 0;
pixelDesc.iLayerType = PFD_MAIN_PLANE;
pixelDesc.bReserved = 0;
pixelDesc.dwLayerMask = 0;
pixelDesc.dwVisibleMask = 0;
pixelDesc.dwDamageMask = 0;
m_GLPixelIndex = ChoosePixelFormat( hDC, &pixelDesc);
if (m_GLPixelIndex==0) // Let's choose a default index.
{
m_GLPixelIndex = 1;
if (DescribePixelFormat(hDC, m_GLPixelIndex,
sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc)==0)
{
return FALSE;
}
}
if (SetPixelFormat( hDC, m_GLPixelIndex, &pixelDesc)==FALSE)
{
return FALSE;
}
return TRUE;
}
int CBaseOpenGLMDIView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_pCDC= new CClientDC(this);
if (SetWindowPixelFormat(m_pCDC->GetSafeHdc())==FALSE)
return 0;
if (CreateViewGLContext(m_pCDC->GetSafeHdc())==FALSE)
return 0;
return 0;
}
void CBaseOpenGLMDIView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
GLsizei w,h;
GLdouble aspect;
w = cx;
h = cy;
if (cy==0)
aspect = (GLdouble)w;
else
aspect = (GLdouble)w/(GLdouble)h;
wglMakeCurrent(m_pCDC->GetSafeHdc(), m_hGLContext);
glClearColor(1.0,1.0,1.0,1.0);
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(20, aspect, 1, m_viewDepth);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawBuffer(GL_BACK);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
wglMakeCurrent(NULL,NULL);
}
void CBaseOpenGLMDIView::OnPaint()
{
CPaintDC dc(this);
CBaseOpenGLMDIDoc* pDoc = GetDocument();
wglMakeCurrent(m_pCDC->GetSafeHdc(), m_hGLContext);
pDoc->RenderScene();
SwapBuffers(m_pCDC->GetSafeHdc());
wglMakeCurrent(NULL,NULL);
}
thanks,
kev.