資源描述:
《基于openGL的三階魔方程序代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、/*Magic2D.cpp文件:可以播放《愛你一萬年》歌曲,需要在工程文件夾中新建文件夾“sound”并存放“愛你一萬年.wav”文件需要在Data文件夾中上傳y2.bmp到y(tǒng)7.bmp的圖片,當然也可以在程序中相應(yīng)部分自己修改該程序有兩個文件,Magic2D.cpp和MoFang.cpp,可以實現(xiàn)三階魔方任意層面的旋轉(zhuǎn)并能使魔方在界面來回移動反彈,具體的建工程的步驟就不說了,祝大家好運*/#include"MoFang.h"#include//提供與多媒體有關(guān)的接口#pragmacomment(lib,"WINMM.LIB")//導(dǎo)入
2、winmm.lib庫,實現(xiàn)對多媒體編程的支持HDChDC=NULL;//PrivateGDIDeviceContextHGLRChRC=NULL;//PermanentRenderingContextHWNDhWnd=NULL;//HoldsOurWindowHandleboolkeys[256];//ArrayUsedForTheKeyboardRoutineHINSTANCEhInstance;//HoldsTheInstanceOfTheApplicationboolactive=TRUE;//WindowActiveFlagSetToTRUEByDef
3、aultboolfullscreen=TRUE;//FullscreenFlagSetToFullscreenModeByDefaultGLfloatxrot;//XRotation(NEW)GLfloatyrot;//YRotation(NEW)GLfloatzrot;//ZRotation(NEW)GLfloatRX=0;GLfloatRY=0;GLuinttexture[7];//StorageForOneTexture(NEW)GLbooleanb_RX,b_RY;GLfloatturn_x=1,turn_y=1;LRESULTCALLBACKWndP
4、roc(HWND,UINT,WPARAM,LPARAM);//CALLBACK代表回調(diào)函數(shù)DeclarationForWndProc,函數(shù)聲明,監(jiān)聽windowsAUX_RGBImageRec*LoadBMP(char*Filename)//LoadsABitmapImage{FILE*File=NULL;//FileHandleif(!Filename)//MakeSureAFilenameWasGiven{returnNULL;//IfNotReturnNULL}File=fopen(Filename,"r");//CheckToSeeIfTheFileE
5、xistsif(File)//DoesTheFileExist?{fclose(File);//CloseTheHandlereturnauxDIBImageLoad(Filename);//LoadTheBitmapAndReturnAPointer}returnNULL;//IfLoadFailedReturnNULL}voidloadsound(){PlaySound("sound\愛你一萬年.wav",NULL,SND_LOOP
6、SND_ASYNC
7、SND_FILENAME);}intLoadGLTextures()//LoadBitmapsAndC
8、onvertToTextures{intStatus=FALSE;//StatusIndicatorAUX_RGBImageRec*TextureImage[1];//CreateStorageSpaceForTheTexturememset(TextureImage,0,sizeof(void*)*1);//SetThePointerToNULL//LoadTheBitmap,CheckForErrors,IfBitmap'sNotFoundQuitif(TextureImage[0]=LoadBMP("Data/NeHe.bmp")){Status=TRU
9、E;//SetTheStatusToTRUEglGenTextures(1,&texture[0]);//CreateTheTexture//TypicalTextureGenerationUsingDataFromTheBitmapglBindTexture(GL_TEXTURE_2D,texture[0]);glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);
10、glTexParameteri(GL_