资源描述:
《基于openGL的三阶魔方程序代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/*Magic2D.cpp文件:可以播放《爱你一万年》歌曲,需要在工程文件夹中新建文件夹“sound”并存放“爱你一万年.wav”文件需要在Data文件夹中上传y2.bmp到y7.bmp的图片,当然也可以在程序中相应部分自己修改该程序有两个文件,Magic2D.cpp和MoFang.cpp,可以实现三阶魔方任意层面的旋转并能使魔方在界面来回移动反弹,具体的建工程的步骤就不说了,祝大家好运*/#include"MoFang.h"#include//提供与多媒体有关的接口#pragmacomment(lib,"WINMM.LIB")//导入
2、winmm.lib库,实现对多媒体编程的支持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代表回调函数DeclarationForWndProc,函数声明,监听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_