width = (GLsizei) LOWORD (IParam ); height = (GLsizei) HIWORD (IParam ); aspect = (GLdouble) width /
(GLdouble) height;
gIMatrixMode (GL_PROJECTION ); gILoadldentity ();
gluPerspective ( 30.0, aspect, 1.0, 100.0 );
glViewport ( 0, 0, width, height);
wglMakeCurrent ( NULL, NULL ); ReleaseDC ( hWnd, hdc );
return 0;
case WM_PAINT:
hdc = BeginPaint ( hWnd, &ps ); wglMakeCurrent ( hdc, hrc ); drawScene ( hdc, angle );
Компьютерная графика. Полигональные модели
wglMakeCurrent ( NULL, NULL ); EndPaint ( hWnd, &ps );
return 0;
case WM_DESTROY:
wglMakeCurrent ( NULL, NULL ); wglDeleteContext ( hrc );
PostQuitMessage (0 );
return 0;
}
return DefWindowProc ( hWnd, msg, wParam, IParam );
}
void setDCPixelFormat ( HDC hdc ) {
static PIXELFORMATDESCRIPTOR pfd = {
sizeof ( PIXELFORMATDESCRIPTOR ), 1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT__OPENGL,//flags
PFD_TYPE_RGBA, // RGBA pixel values
24, //24-bit color
0, 0, 0, 0, 0, 0, // don't care about these
0, 0, // no alpha buffer
0, 0, 0, 0, 0, // no accumulation buffer
32, // 32-bit depth buffer
0, //no stencil buffer
0, // no auxiliary buffers
PFD_MAIN_PLANE, // layer type
0, // reserved (must be 0)
0, 0, 0 // no layer masks
};
int pixelFormat;
pixelFormat = ChoosePixelFormat ( hdc, &pfd ); SetPixelFormat ( hdc, pixelFormat, &pfd ); DescribePixelFormat (hdc, pixelFormat,
sizeof (PIXELFORMATDESCRIPTOR), &pfd );
if ( pfd.dwFlags & PFD_NEED_PALETTE )
MessageBox ( NULL, "Wrong video mode", "Attention", MBJDK );
}
void initializeRC () {
GLfloat lightAmbient [] = {0.1, 0.1, 0.1, 1.0}; GLfloat lightDiffuse 0 = { 0.7, 0.7, 0.7, 1.0 }; GLfloat lightSpecular [] = { 0.0, 0.0, 0.0, 1.0 };
gIFrontFace ( GL_CCW ); glCullFace ( GL_BACK ); glEnable ( GL__CULL_FACE );
gIDepthFunc ( GL_LEQUAL );
12. Работа с библиотекой OpenGL
glEnable ( GL_DEPTH_TEST ); glClearColor ( 0.0, 0.0, 0.0, 0.0 );
gILightfv ( GL_LIGHT0, GL_AMBIENT, lightAmbient); gILightfv ( GL_LIGHT0, GL_DIFFUSE, lightDiffuse ); gILightfv ( GLJJGHT0, GL_SPECULAR, lightSpecular); glEnable (GL_LIGHTING ); glEnable (GLJ.IGHT0 );