Here the code I use.
CODE
// ********************************************************************************
****************************************************
void CMainWindow::OnSize(UINT nType, INT iX, INT iY)
// ********************************************************************************
****************************************************
//
//
{
// Set up the OpenGL size.
if (SizeOpenGL(iX, iY)) m_bExitApplication = TRUE;
// Default with a redraw.
CWnd::OnSize(nType, iX, iY);
Invalidate(FALSE);
}
// ********************************************************************************
****************************************************
BOOL CMainWindow::SizeOpenGL(INT iX, INT iY)
// ********************************************************************************
****************************************************
//
//
{
// Variable declaration.
GLdouble gldAspect;
GLsizei glnWidth, glnHeight;
CPaintDC cPaintDC(this);
// Select the rendering context.
wglMakeCurrent(cPaintDC.m_ps.hdc, m_hRC);
// Get the size of the client window.
glnWidth = GLsizei(iX);
glnHeight = GLsizei(iY);
gldAspect = GLdouble(glnWidth) / GLdouble(glnHeight);
// Set up a projection matrix to fill the client window.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 30.0, // Field-of-view angle
gldAspect, // Aspect ratio of view volume
0.1, // Distance to near clipping plane
1.0e+10F ); // Distance to far clipping plane
glViewport(0, 0, glnWidth, glnHeight);
// Choose smooth and blended drawing.
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
// Set the light.
GLfloat glfLocalAmbient[] = {0.20F, 0.20F, 0.20F, 1.0F};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glfLocalAmbient);
GLfloat glfSpecular[] = {0.8F, 0.8F, 0.8F, 1.0F};
GLfloat glfAmbient [] = {0.8F, 0.8F, 0.8F, 1.0F};
GLfloat glfDiffuse [] = {0.7F, 0.7F, 0.7F, 1.0F};
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT , glfAmbient );
glLightfv(GL_LIGHT0, GL_DIFFUSE , glfDiffuse );
glLightfv(GL_LIGHT0, GL_SPECULAR, glfSpecular);
// Deselect the rendering context.
wglMakeCurrent(NULL, NULL);
return FALSE;
}