Translate

tutorial graphic halaman 11

Selamat datang di eagleboot dan selamat membaca.

 /*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(r,g,b); glRectf(‐0.2,0.2,0.2,‐0.2); glPopMatrix(); SwapBuffers(hDC); if(count>160) { theta‐=0.01f; alpha‐=0.01f; if(count==320) { 
count=0; theta=‐0.8f; alpha=‐0.8f; } else count+=1; r=0.0f; g=1.0f; b=0.0f; } elseif(count<=160) { theta+=0.01f; alpha+=0.01f; count+=1; r=1.0f; g=0.0f; b=1.0f; } 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 12

Share this

Related Posts

Previous
Next Post »