Translate

tutorial graphic halaman 9

Selamat datang di eagleboot dan selamat membaca.

wc.cbWndExtra=0; wc.hInstance=hInstance; wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName=NULL; wc.lpszClassName="GraphGL"; RegisterClass(&wc); /*createmainwindow*/ hWnd=CreateWindow( "GraphGL","OpenGLGraphicsAnimation", WS_CAPTION|WS_POPUPWINDOW|WS_VISIBLE, 0,0,512,512, NULL,NULL,hInstance,NULL); /*enableOpenGLforthewindow*/ EnableOpenGL(hWnd,&hDC,&hRC); /*programmainloop*/ while(!bQuit) { /*checkformessages*/ if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { /*handleordispatchmessages*/ if(msg.message==WM_QUIT) { bQuit=TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { /*OpenGLanimationcodegoeshere*/ glClearColor(1.0f,1.0f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(theta,alpha,0.0f); glColor3f(1.0f,0.0f,1.0f); glRectf(‐0.2,0.2,0.2,‐0.2); glPopMatrix(); SwapBuffers(hDC); if(theta>=1.0) { theta=‐1.0f; alpha=‐1.0f; } elseif(theta<=1.0) { theta+=0.01f; alpha+=0.01f; } Sleep(10); } } /*shutdownOpenGL*/ DisableOpenGL(hWnd,hDC,hRC); /*destroythewindowexplicitly*/ DestroyWindow(hWnd); returnmsg.wParam; } /******************** *WindowProcedure ********************/ LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage, WPARAMwParam,LPARAMlParam) { switch(message) { caseWM_CREATE: return0; caseWM_CLOSE: PostQuitMessage(0); return0; caseWM_DESTROY: return0; caseWM_KEYDOWN: switch(wParam) { caseVK_ESCAPE: PostQuitMessage(0); return0; } return0; default: returnDefWindowProc(hWnd,message,wParam,lParam); } } /******************* *EnableOpenGL *******************/ voidEnableOpenGL(HWNDhWnd,HDC*hDC,HGLRC*hRC) { PIXELFORMATDESCRIPTORpfd; intiFormat; /*getthedevicecontext(DC)*/ *hDC=GetDC(hWnd); /*setthepixelformatfortheDC*/ ZeroMemory(&pfd,sizeof(pfd)); pfd.nSize=sizeof(pfd); pfd.nVersion=1; pfd.dwFlags=PFD_DRAW_TO_WINDOW| PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER; pfd.iPixelType=PFD_TYPE_RGBA; pfd.cColorBits=24; pfd.cDepthBits=16; 

Next read halaman 10.

Share this

Related Posts

Previous
Next Post »