三维物体转动opengl程序Word文档下载推荐.docx
- 文档编号:21792735
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:15
- 大小:21.47KB
三维物体转动opengl程序Word文档下载推荐.docx
《三维物体转动opengl程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《三维物体转动opengl程序Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。
//HoldsTheInstanceOfTheApplication
boolkeys[256];
//ArrayUsedForTheKeyboardRoutine
boolactive=TRUE;
//WindowActiveFlagSetToTRUEByDefault
boolfullscreen=TRUE;
//FullscreenFlagSetToFullscreenModeByDefault
GLfloatrtri;
//AngleForTheTriangle(NEW)
GLfloatrquad;
//AngleForTheQuad(NEW)
LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);
//DeclarationForWndProc
GLvoidReSizeGLScene(GLsizeiwidth,GLsizeiheight)//ResizeAndInitializeTheGLWindow
{
if(height==0)//PreventADivideByZeroBy
{
height=1;
//MakingHeightEqualOne
}
glViewport(0,0,width,height);
//ResetTheCurrentViewport
glMatrixMode(GL_PROJECTION);
//SelectTheProjectionMatrix
glLoadIdentity();
//ResetTheProjectionMatrix
//CalculateTheAspectRatioOfTheWindow
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
//SelectTheModelviewMatrix
//ResetTheModelviewMatrix
}
intInitGL(GLvoid)//AllSetupForOpenGLGoesHere
glShadeModel(GL_SMOOTH);
//EnableSmoothShading
glClearColor(0.0f,0.0f,0.0f,0.5f);
//BlackBackground
glClearDepth(1.0f);
//DepthBufferSetup
glEnable(GL_DEPTH_TEST);
//EnablesDepthTesting
glDepthFunc(GL_LEQUAL);
//TheTypeOfDepthTestingToDo
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
//ReallyNicePerspectiveCalculations
returnTRUE;
//InitializationWentOK
intDrawGLScene(GLvoid)//Here'
sWhereWeDoAllTheDrawing
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//ClearScreenAndDepthBuffer
//ResetTheCurrentModelviewMatrix
glTranslatef(-1.5f,0.0f,-6.0f);
//MoveLeft1.5UnitsAndIntoTheScreen6.0
glRotatef(rtri,0.0f,1.0f,0.0f);
//RotateTheTriangleOnTheYaxis(NEW)
glBegin(GL_TRIANGLES);
//StartDrawingATriangle
glColor3f(1.0f,0.0f,0.0f);
//Red
glVertex3f(0.0f,1.0f,0.0f);
//TopOfTriangle(Front)
glColor3f(0.0f,1.0f,0.0f);
//Green
glVertex3f(-1.0f,-1.0f,1.0f);
//LeftOfTriangle(Front)
glColor3f(0.0f,0.0f,1.0f);
//Blue
glVertex3f(1.0f,-1.0f,1.0f);
//RightOfTriangle(Front)
//TopOfTriangle(Right)
//LeftOfTriangle(Right)
glVertex3f(1.0f,-1.0f,-1.0f);
//RightOfTriangle(Right)
//TopOfTriangle(Back)
//LeftOfTriangle(Back)
glVertex3f(-1.0f,-1.0f,-1.0f);
//RightOfTriangle(Back)
//TopOfTriangle(Left)
glVertex3f(-1.0f,-1.0f,-1.0f);
//LeftOfTriangle(Left)
//RightOfTriangle(Left)
glEnd();
//DoneDrawingThePyramid
glTranslatef(1.5f,0.0f,-7.0f);
//MoveRight1.5UnitsAndIntoTheScreen7.0
glRotatef(rquad,1.0f,1.0f,1.0f);
//RotateTheQuadOnTheXaxis(NEW)
glBegin(GL_QUADS);
//DrawAQuad
//SetTheColorToGreen
glVertex3f(1.0f,1.0f,-1.0f);
//TopRightOfTheQuad(Top)
glVertex3f(-1.0f,1.0f,-1.0f);
//TopLeftOfTheQuad(Top)
glVertex3f(-1.0f,1.0f,1.0f);
//BottomLeftOfTheQuad(Top)
glVertex3f(1.0f,1.0f,1.0f);
//BottomRightOfTheQuad(Top)
glColor3f(1.0f,0.5f,0.0f);
//SetTheColorToOrange
//TopRightOfTheQuad(Bottom)
//TopLeftOfTheQuad(Bottom)
//BottomLeftOfTheQuad(Bottom)
glVertex3f(1.0f,-1.0f,-1.0f);
//BottomRightOfTheQuad(Bottom)
//SetTheColorToRed
//TopRightOfTheQuad(Front)
//TopLeftOfTheQuad(Front)
//BottomLeftOfTheQuad(Front)
//BottomRightOfTheQuad(Front)
glColor3f(1.0f,1.0f,0.0f);
//SetTheColorToYellow
//TopRightOfTheQuad(Back)
//TopLeftOfTheQuad(Back)
//BottomLeftOfTheQuad(Back)
//BottomRightOfTheQuad(Back)
//SetTheColorToBlue
//TopRightOfTheQuad(Left)
//TopLeftOfTheQuad(Left)
//BottomLeftOfTheQuad(Left)
//BottomRightOfTheQuad(Left)
glColor3f(1.0f,0.0f,1.0f);
//SetTheColorToViolet
//TopRightOfTheQuad(Right)
//TopLeftOfTheQuad(Right)
//BottomLeftOfTheQuad(Right)
//BottomRightOfTheQuad(Right)
//DoneDrawingTheQuad
rtri+=0.2f;
//IncreaseTheRotationVariableForTheTriangle(NEW)
rquad-=0.15f;
//DecreaseTheRotationVariableForTheQuad(NEW)
//KeepGoing
GLvoidKillGLWindow(GLvoid)//ProperlyKillTheWindow
if(fullscreen)//AreWeInFullscreenMode?
ChangeDisplaySettings(NULL,0);
//IfSoSwitchBackToTheDesktop
ShowCursor(TRUE);
//ShowMousePointer
if(hRC)//DoWeHaveARenderingContext?
if(!
wglMakeCurrent(NULL,NULL))//AreWeAbleToReleaseTheDCAndRCContexts?
{
MessageBox(NULL,"
ReleaseOfDCAndRCFailed."
"
SHUTDOWNERROR"
MB_OK|MB_ICONINFORMATION);
}
wglDeleteContext(hRC))//AreWeAbleToDeleteTheRC?
ReleaseRenderingContextFailed."
hRC=NULL;
//SetRCToNULL
if(hDC&
&
!
ReleaseDC(hWnd,hDC))//AreWeAbleToReleaseTheDC
MessageBox(NULL,"
ReleaseDeviceContextFailed."
hDC=NULL;
//SetDCToNULL
if(hWnd&
DestroyWindow(hWnd))//AreWeAbleToDestroyTheWindow?
CouldNotReleasehWnd."
hWnd=NULL;
//SethWndToNULL
if(!
UnregisterClass("
OpenGL"
hInstance))//AreWeAbleToUnregisterClass
CouldNotUnregisterClass."
hInstance=NULL;
//SethInstanceToNULL
/*ThisCodeCreatesOurOpenGLWindow.ParametersAre:
*
*title-TitleToAppearAtTheTopOfTheWindow*
*width-WidthOfTheGLWindowOrFullscreenMode*
*height-HeightOfTheGLWindowOrFullscreenMode*
*bits-NumberOfBitsToUseForColor(8/16/24/32)*
*fullscreenflag-UseFullscreenMode(TRUE)OrWindowedMode(FALSE)*/
BOOLCreateGLWindow(char*title,intwidth,intheight,intbits,boolfullscreenflag)
GLuintPixelFormat;
//HoldsTheResultsAfterSearchingForAMatch
WNDCLASSwc;
//WindowsClassStructure
DWORDdwExStyle;
//WindowExtendedStyle
DWORDdwStyle;
//WindowStyle
RECTWindowRect;
//GrabsRectangleUpperLeft/LowerRightValues
WindowRect.left=(long)0;
//SetLeftValueTo0
WindowRect.right=(long)width;
//SetRightValueToRequestedWidth
WindowRect.top=(long)0;
//SetTopValueTo0
WindowRect.bottom=(long)height;
//SetBottomValueToRequestedHeight
fullscreen=fullscreenflag;
//SetTheGlobalFullscreenFlag
hInstance=GetModuleHandle(NULL);
//GrabAnInstanceForOurWindow
wc.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
//RedrawOnSize,AndOwnDCForWindow.
wc.lpfnWndProc=(WNDPROC)WndProc;
//WndProcHandlesMessages
wc.cbClsExtra=0;
//NoExtraWindowData
wc.cbWndExtra=0;
wc.hInstance=hInstance;
//SetTheInstance
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
//LoadTheDefaultIcon
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
//LoadTheArrowPointer
wc.hbrBackground=NULL;
//NoBackgroundRequiredForGL
wc.lpszMenuName=NULL;
//WeDon'
tWantAMenu
wc.lpszClassName="
;
//SetTheClassName
RegisterClass(&
wc))//AttemptToRegisterTheWindowClass
MessageBox(NUL
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 三维 物体 转动 opengl 程序