void drawBox ( GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); void drawScene ( HDC, int );
int WINAPI WinMain ( HINSTANCE hlnstance, HINSTANCE hPrevlnstance,
LPSTR cmdLine, int cmdShow )
{
static char appName Q = "Robot Arm"; WNDCLASS wc; HWND hWnd; MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc ='(WNDPROC) wndProc;
wc.cbClsExtra =0;
wc.cbWnd Extra =0;
wc.hlnstance = hlnstance;
wc.hlcon = Loadlcon ( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = appName;
RegisterClass (&wc );
hWnd = CreateWindow ( appName, appName,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN |
WS_CLIPS!BLINGS, CW_USEDEFAULT, CWJJSEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hlnstance, NULL );
ShowWindow ( hWnd, cmdShow ); UpdateWindow (hWnd );
while ( GetMessage ( &msg, NULL, 0, 0 )) {
TranslateMessage ( &msg ); DispatchMessage ( &msg );
}
return msg.wParam;
}
LONG WINAPI wndProc ( HWND hWnd, UINT msg,
WPARAM wParam, LP AR AM IParam )
{
static HDC hdc; static HGLRC hrc; PAINTSTRUCT ps;

12. Работа с библиотекой OpenGL

GLdouble aspect; GLsizei width, height; static int angle = 0; static BOOL up = TRUE; static UINT timer,
switch (msg ) {
case WM_CREATE:
hdc = GetDC ( hWnd ); setDCPixelFormat (hdc); hrc = wglCreateContext ( hdc ); wglMakeCurrent ( hdc, hrc ); initializeRC ();
timer = SetTimer (hWnd, 1, 50, NULL );
return 0;
case WM_SIZE:
width = (GLsizei) LOWORD (IParam ); height = (GLsizei) HIWORD (IParam ); aspect = (GLdouble) width / (GLdouble) height;
glMatrixMode (GL_PROJECTION ); glLoadldentity ();
gluPerspective ( 30.0, aspect, 1.0, 100.0 );
glViewport ( 0, 0, width, height);
return 0;
case WM_PAINT:
BeginPaint ( hWnd, &ps ); drawScene ( hdc, angle ); EndPaint ( hWnd, &ps );
return 0;
case WM_TIMER: if(up)
{
angle += 2; if ( angle == 90 ) up = FALSE;
}
else
{
angle -= 2; if ( angle == 0 ) up = TRUE;
}
InvalidateRect ( hWnd, NULL, FALSE );

⇐ Предыдущая| |Следующая ⇒