標(biāo)準(zhǔn)實(shí)驗(yàn)報(bào)告-模板_第1頁(yè)
標(biāo)準(zhǔn)實(shí)驗(yàn)報(bào)告-模板_第2頁(yè)
標(biāo)準(zhǔn)實(shí)驗(yàn)報(bào)告-模板_第3頁(yè)
標(biāo)準(zhǔn)實(shí)驗(yàn)報(bào)告-模板_第4頁(yè)
標(biāo)準(zhǔn)實(shí)驗(yàn)報(bào)告-模板_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

電子科技大學(xué)實(shí)驗(yàn)報(bào)告學(xué)生姓名:學(xué)號(hào):指導(dǎo)教師:實(shí)驗(yàn)地點(diǎn):實(shí)驗(yàn)時(shí)間:一、實(shí)驗(yàn)室名稱:計(jì)算機(jī)學(xué)院軟件實(shí)驗(yàn)室二、實(shí)驗(yàn)項(xiàng)目名稱:三維特效技術(shù)三、實(shí)驗(yàn)學(xué)時(shí):8學(xué)時(shí)四、實(shí)驗(yàn)原理很多的現(xiàn)象都可以用粒子系統(tǒng)精確的或者近似的模擬,如火焰、噴泉、爆炸、魚群和星空等等。一個(gè)粒子系統(tǒng)由擁有各種屬性的對(duì)象組成,它們必須遵循一定的行為規(guī)范。具體的這些屬性和行為規(guī)范取決于需要模擬的內(nèi)容是什么。一些粒子系統(tǒng)可能需要很多屬性和復(fù)雜的規(guī)則,而有的則可能極為簡(jiǎn)單。根據(jù)粒子設(shè)置的復(fù)雜性,可以產(chǎn)生:簡(jiǎn)單的可以實(shí)現(xiàn)噴泉、煙霧、火焰等;復(fù)雜一點(diǎn)的可以實(shí)現(xiàn)flocking等;再?gòu)?fù)雜一點(diǎn)就可以利用粒子系統(tǒng)模擬實(shí)現(xiàn)衣物等彈性物體。粒子系統(tǒng)是一種物理模型,粒子系統(tǒng)的核心不在于如何顯示圖形,而是在于對(duì)某個(gè)物理模型的理解和分析。只有基于物理模型的方法,才能模擬出隨機(jī)而逼真的自然景象。粒子的運(yùn)動(dòng)(變化)規(guī)律可以很簡(jiǎn)單也可以很復(fù)雜,這取決于模擬的物理模型的復(fù)雜程度。對(duì)于每一個(gè)粒子,它應(yīng)具有以下屬性:(1)坐標(biāo)(Coordinates) :對(duì)于每一個(gè)粒子,最終都要把它映射到屏幕上,所以坐標(biāo)成為一個(gè)粒子最為重要的屬性之一。每個(gè)粒子的坐標(biāo)隨時(shí)間的變化而變化,它通過每個(gè)粒子自身在各時(shí)刻的速度求得。(2)速度(Velocity):運(yùn)動(dòng)的粒子都有速度,每個(gè)粒子的速度可以各不相同。速度用來計(jì)算下一時(shí)刻粒子的坐標(biāo)(位置)。(3)加速度(Acceleration): 粒子可以做變速運(yùn)動(dòng),此時(shí)加速度便會(huì)發(fā)生作用。它用來計(jì)算下一時(shí)刻粒子的速度。(4)生命值(Life):每個(gè)粒子都有著自己的生命值,隨著時(shí)間的推移,粒子的生命值不斷減小,直到粒子死亡(生命值為0)。一個(gè)生命周期結(jié)束時(shí),另一個(gè)生命周期隨即開始,有時(shí)為了使粒子能夠源源不斷地涌出,必須使一部分粒子在初始后立即死亡,這個(gè)技巧在后面的實(shí)現(xiàn)中會(huì)具體說明。(5)衰減(Decay):就象人會(huì)衰老一樣,每個(gè)粒子也有它自己的生命周期,Decay就是用來控制粒子生命周期的一個(gè)物理量。五、實(shí)驗(yàn)?zāi)康谋緦?shí)驗(yàn)要實(shí)現(xiàn)一個(gè)基本的粒子系統(tǒng),該基本粒子系統(tǒng)必須具有以下模塊:粒子生成、給粒子施加力(例如:重力、拖力等)、粒子的碰撞效果(例如與其他幾何體碰撞,并反彈回來)?;鞠到y(tǒng)實(shí)現(xiàn)之后,學(xué)生可以選擇一些針對(duì)粒子繪制和物理仿真方面的擴(kuò)展。針對(duì)繪制的擴(kuò)展可以產(chǎn)生如:煙霧、火光、火花等特效。針對(duì)物理方面的擴(kuò)展可以產(chǎn)生如:衣物、繩子、甚至鳥群、魚群等。六、實(shí)驗(yàn)內(nèi)容利用OpenGL實(shí)現(xiàn)一個(gè)標(biāo)準(zhǔn)的粒子系統(tǒng)特效,如:煙花、噴泉等。七、實(shí)驗(yàn)器材(設(shè)備、元器件)操作系統(tǒng):WindowsXP開發(fā)工具:VC2003,OpenGLl庫(kù)普通PC即可八、實(shí)驗(yàn)步驟創(chuàng)建工程啟動(dòng)VC++2003,創(chuàng)建空白工程項(xiàng)目。選擇菜單中的“文件”->“新建”->“項(xiàng)目”,在彈出的對(duì)話框中,左邊的“項(xiàng)目類型”框中,選擇“VisualC++項(xiàng)目”,在右邊框中,選擇“空項(xiàng)目(.Net)”,在對(duì)話框下邊,選擇工程文件存放目錄及輸入名稱,如Example1,單擊“確定”。設(shè)置此工程所需的OpenGL庫(kù)選擇菜單中的“項(xiàng)目”->“Example1屬性”,在彈出的“Example1屬性頁(yè)”對(duì)話框中,單擊“鏈接器”->“輸入”,選擇右邊框中的“附加依賴項(xiàng)”,單擊最右端的“…”小按鈕,彈出“附加依賴項(xiàng)”對(duì)話框,輸入“opengl32.lib

glu32.lib

glaux.lib”(注意,輸入雙引號(hào)中的內(nèi)容,各個(gè)庫(kù)用空格分開;否則會(huì)出現(xiàn)鏈接錯(cuò)誤),單擊“確定”結(jié)束,返回“屬性頁(yè)”對(duì)話框,單擊“確定”。OpenGL庫(kù)設(shè)置完成。在工程項(xiàng)目中添加源文件在解決方案資源管理器中,鼠標(biāo)右擊“源文件”,彈出浮動(dòng)菜單,選擇“添加”->“添加新項(xiàng)”,彈出“添加新項(xiàng)-Example1”對(duì)話框,在右邊的模板框中,選擇“C++文件(.cpp)”,輸入文件名,單擊“打開”,添加源文件結(jié)束。如果需要添加頭文件,其操作方法相似。本例沒有編寫的頭文件。錄入源程序?qū)㈩A(yù)習(xí)時(shí)編寫的源程序錄入到計(jì)算機(jī)中。本例的源代碼來自O(shè)penGL的編程教程,僅作為本實(shí)驗(yàn)的參考代碼。學(xué)生可以自己編寫粒子系統(tǒng),也以此為基礎(chǔ),修改源代碼生成不同的粒子系統(tǒng)。說明:準(zhǔn)備好粒子顯示圖片,取名為Particle.bmp,并放在當(dāng)前目錄的子目錄data下。該圖片將作為粒子的紋理,如圖1所示。圖1粒子紋理圖片圖1粒子紋理圖片九、實(shí)驗(yàn)數(shù)據(jù)及結(jié)果分析程序執(zhí)行后,看到粒子爆炸、散開,然后粒子不斷往往下墜落。如圖2所示。通過修改粒子速度、加速度、生命期等參數(shù),可以看到粒子效果的差別。圖2粒子特效截圖圖2粒子特效截圖十、實(shí)驗(yàn)結(jié)論利用OpenGL能夠?qū)崿F(xiàn)粒子系統(tǒng)特效,如:噴泉、煙霧等。十一、總結(jié)及心得體會(huì)OpenGL具有強(qiáng)大的圖形繪制功能,能很好地支持圖形設(shè)計(jì)。十二、對(duì)本實(shí)驗(yàn)過程及方法、手段的改進(jìn)建議程序設(shè)計(jì)合理,代碼可進(jìn)一步優(yōu)化。報(bào)告評(píng)分:指導(dǎo)教師簽字:本實(shí)驗(yàn)參考源代碼如下:/** ThisCodeWasCreatedByJeffMolofee2000* IfYou'veFoundThisCodeUseful,PleaseLetMeKnow.* VisitMySiteAt*/#include<windows.h> //HeaderFileForWindows#include<stdio.h> //HeaderFileForStandardInput/Output#include<gl\gl.h> //HeaderFileForTheOpenGL32Library#include<gl\glu.h> //HeaderFileForTheGLu32Library#include<gl\glaux.h> //HeaderFileForTheGlauxLibrary#define MAX_PARTICLES 1000 //NumberOfParticlesToCreateHDC hDC=NULL; //PrivateGDIDeviceContextHGLRC hRC=NULL; //PermanentRenderingContextHWND hWnd=NULL; //HoldsOurWindowHandleHINSTANCE hInstance; //HoldsTheInstanceOfTheApplicationbool keys[256]; //ArrayUsedForTheKeyboardRoutinebool active=TRUE; //WindowActiveFlagSetToTRUEByDefaultbool fullscreen=TRUE; //FullscreenFlagSetToFullscreenModeByDefaultbool rainbow=true; //RainbowMode?bool sp; //SpacebarPressed?bool rp; //EnterKeyPressed?float slowdown=2.0f; //SlowDownParticlesfloat xspeed; //BaseXSpeed(ToAllowKeyboardDirectionOfTail)float yspeed; //BaseYSpeed(ToAllowKeyboardDirectionOfTail)float zoom=-40.0f; //UsedToZoomOutGLuint loop; //MiscLoopVariableGLuint col; //CurrentColorSelectionGLuint delay; //RainbowEffectDelayGLuint texture[1]; //StorageForOurParticleTexturetypedefstruct //CreateAStructureForParticle{ bool active; //Active(Yes/No) float life; //ParticleLife float fade; //FadeSpeed float r; //RedValue float g; //GreenValue float b; //BlueValue float x; //XPosition float y; //YPosition float z; //ZPosition float xi; //XDirection float yi; //YDirection float zi; //ZDirection float xg; //XGravity float yg; //YGravity float zg; //ZGravity}particles; //ParticlesStructureparticlesparticle[MAX_PARTICLES]; //ParticleArray(RoomForParticleInfo)staticGLfloatcolors[12][3]= //RainbowOfColors{ {1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f}, {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f}, {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}};//DeclarationForWndProcLRESULT CALLBACKWndProc(HWND,UINT,WPARAM,LPARAM); AUX_RGBImageRec*LoadBMP(char*Filename) //LoadsABitmapImage{FILE*File=NULL; //FileHandleif(!Filename) //MakeSureAFilenameWasGiven{returnNULL; //IfNotReturnNULL}File=fopen(Filename,"r"); //CheckToSeeIfTheFileExistsif(File) //DoesTheFileExist?{ fclose(File); //CloseTheHandle returnauxDIBImageLoad(Filename); //LoadTheBitmapAndReturnAPointer}returnNULL; //IfLoadFailedReturnNULL}intLoadGLTextures() //LoadBitmapAndConvertToATexture{intStatus=FALSE; //StatusIndicatorAUX_RGBImageRec*TextureImage[1]; //CreateStorageSpaceForTheTexturesmemset(TextureImage,0,sizeof(void*)*1); //SetThePointerToNULLif(TextureImage[0]=LoadBMP("Data/Particle.bmp")) //LoadParticleTexture{ Status=TRUE; //SetTheStatusToTRUE glGenTextures(1,&texture[0]); //CreateOneTexture glBindTexture(GL_TEXTURE_2D,texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);}if(TextureImage[0]) //IfTextureExists { if(TextureImage[0]->data) //IfTextureImageExists { free(TextureImage[0]->data); //FreeTheTextureImageMemory } free(TextureImage[0]); //FreeTheImageStructure }returnStatus; //ReturnTheStatus}//ResizeAndInitializeTheGLWindowGLvoidReSizeGLScene(GLsizeiwidth,GLsizeiheight){ 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,200.0f); glMatrixMode(GL_MODELVIEW); //SelectTheModelviewMatrix glLoadIdentity(); //ResetTheModelviewMatrix}intInitGL(GLvoid) //AllSetupForOpenGLGoesHere{ if(!LoadGLTextures()) //JumpToTextureLoadingRoutine { returnFALSE; //IfTextureDidn'tLoadReturnFALSE } glShadeModel(GL_SMOOTH); //EnableSmoothShading glClearColor(0.0f,0.0f,0.0f,0.0f); //BlackBackground glClearDepth(1.0f); //DepthBufferSetup glDisable(GL_DEPTH_TEST); //DisableDepthTesting glEnable(GL_BLEND); //EnableBlending glBlendFunc(GL_SRC_ALPHA,GL_ONE); //TypeOfBlendingToPerform//ReallyNicePerspectiveCalculations glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); //ReallyNicePointSmoothing glEnable(GL_TEXTURE_2D); //EnableTextureMapping glBindTexture(GL_TEXTURE_2D,texture[0]); //SelectOurTexture for(loop=0;loop<MAX_PARTICLES;loop++) //InitialsAllTheTextures { particle[loop].active=true; //MakeAllTheParticlesActive particle[loop].life=1.0f; //GiveAllTheParticlesFullLife particle[loop].fade=float(rand()%100)/1000.0f+0.003f; //RandomFadeSpeed particle[loop].r=colors[loop*(12/MAX_PARTICLES)][0]; //SelectRedRainbowColor particle[loop].g=colors[loop*(12/MAX_PARTICLES)][1]; //SelectRedRainbowColor particle[loop].b=colors[loop*(12/MAX_PARTICLES)][2]; //SelectRedRainbowColor particle[loop].xi=float((rand()%50)-26.0f)*10.0f; //RandomSpeedOnXAxis particle[loop].yi=float((rand()%50)-25.0f)*10.0f; //RandomSpeedOnYAxis particle[loop].zi=float((rand()%50)-25.0f)*10.0f; //RandomSpeedOnZAxis particle[loop].xg=0.0f; //SetHorizontalPullToZero particle[loop].yg=-0.8f; //SetVerticalPullDownward particle[loop].zg=0.0f; //SetPullOnZAxisToZero } returnTRUE; //InitializationWentOK}intDrawGLScene(GLvoid) //Here'sWhereWeDoAllTheDrawing{ //ClearScreenAndDepthBuffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //ResetTheModelViewMatrix for(loop=0;loop<MAX_PARTICLES;loop++) //LoopThroughAllTheParticles { if(particle[loop].active) //IfTheParticleIsActive { floatx=particle[loop].x; //GrabOurParticleXPosition floaty=particle[loop].y; //GrabOurParticleYPosition floatz=particle[loop].z+zoom; //ParticleZPos+Zoom //DrawTheParticleUsingOurRGBValues,FadeTheParticleBasedOnIt'sLife glColor4f(particle[loop].r,particle[loop].g,particle[loop].b,particle[loop].life); glBegin(GL_TRIANGLE_STRIP); //BuildQuadFromATriangleStrip glTexCoord2d(1,1);glVertex3f(x+0.5f,y+0.5f,z);//TopRight glTexCoord2d(0,1);glVertex3f(x-0.5f,y+0.5f,z);//TopLeft glTexCoord2d(1,0);glVertex3f(x+0.5f,y-0.5f,z);//BottomRight glTexCoord2d(0,0);glVertex3f(x-0.5f,y-0.5f,z);//BottomLeft glEnd(); //DoneBuildingTriangleStrip//MoveOnTheXAxisByXSpeed particle[loop].x+=particle[loop].xi/(slowdown*1000);//MoveOnTheYAxisByYSpeed particle[loop].y+=particle[loop].yi/(slowdown*1000);//MoveOnTheZAxisByZSpeed particle[loop].z+=particle[loop].zi/(slowdown*1000); particle[loop].xi+=particle[loop].xg; //TakePullOnXAxisIntoAccount particle[loop].yi+=particle[loop].yg; //TakePullOnYAxisIntoAccount particle[loop].zi+=particle[loop].zg; //TakePullOnZAxisIntoAccount particle[loop].life-=particle[loop].fade; //ReduceParticlesLifeBy'Fade' if(particle[loop].life<0.0f) //IfParticleIsBurnedOut { particle[loop].life=1.0f; //GiveItNewLife //RandomFadeValue particle[loop].fade=float(rand()%100)/1000.0f+0.003f; particle[loop].x=0.0f; //CenterOnXAxis particle[loop].y=0.0f; //CenterOnYAxis particle[loop].z=0.0f; //CenterOnZAxis //XAxisSpeedAndDirection particle[loop].xi=xspeed+float((rand()%60)-32.0f); //YAxisSpeedAndDirection particle[loop].yi=yspeed+float((rand()%60)-30.0f); particle[loop].zi=float((rand()%60)-30.0f); //ZAxisSpeedAndDirection particle[loop].r=colors[col][0]; //SelectRedFromColorTable particle[loop].g=colors[col][1]; //SelectGreenFromColorTable particle[loop].b=colors[col][2]; //SelectBlueFromColorTable } //IfNumberPad8AndYGravityIsLessThan1.5IncreasePullUpwards if(keys[VK_NUMPAD8]&&(particle[loop].yg<1.5f))particle[loop].yg+=0.01f; //IfNumberPad2AndYGravityIsGreaterThan-1.5IncreasePullDownwards if(keys[VK_NUMPAD2]&&(particle[loop].yg>-1.5f))particle[loop].yg-=0.01f; //IfNumberPad6AndXGravityIsLessThan1.5IncreasePullRight if(keys[VK_NUMPAD6]&&(particle[loop].xg<1.5f))particle[loop].xg+=0.01f; //IfNumberPad4AndXGravityIsGreaterThan-1.5IncreasePullLeft if(keys[VK_NUMPAD4]&&(particle[loop].xg>-1.5f))particle[loop].xg-=0.01f; if(keys[VK_TAB]) //TabKeyCausesABurst { particle[loop].x=0.0f; //CenterOnXAxis particle[loop].y=0.0f; //CenterOnYAxis particle[loop].z=0.0f; //CenterOnZAxis particle[loop].xi=float((rand()%50)-26.0f)*10.0f; //RandomSpeedOnXAxis particle[loop].yi=float((rand()%50)-25.0f)*10.0f; //RandomSpeedOnYAxis particle[loop].zi=float((rand()%50)-25.0f)*10.0f; //RandomSpeedOnZAxis } }} returnTRUE; //EverythingWentOK}GLvoidKillGLWindow(GLvoid) //ProperlyKillTheWindow{ if(fullscreen) //AreWeInFullscreenMode? { ChangeDisplaySettings(NULL,0); //IfSoSwitchBackToTheDesktop ShowCursor(TRUE); //ShowMousePointer } if(hRC) //DoWeHaveARenderingContext? { //AreWeAbleToReleaseTheDCAndRCContexts? if(!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"ReleaseOfDCAndRCFailed.","SHUTDOWNERROR",MB_OK|MB_ICONINFORMATION); } if(!wglDeleteContext(hRC)) //AreWeAbleToDeleteTheRC? { MessageBox(NULL,"ReleaseRenderingContextFailed.","SHUTDOWNERROR",MB_OK|MB_ICONINFORMATION); } hRC=NULL; //SetRCToNULL } if(hDC&&!ReleaseDC(hWnd,hDC)) //AreWeAbleToReleaseTheDC { MessageBox(NULL,"ReleaseDeviceContextFailed.","SHUTDOWNERROR",MB_OK|MB_ICONINFORMATION); hDC=NULL; //SetDCToNULL } if(hWnd&&!DestroyWindow(hWnd)) //AreWeAbleToDestroyTheWindow? { MessageBox(NULL,"CouldNotReleasehWnd.","SHUTDOWNERROR",MB_OK|MB_ICONINFORMATION); hWnd=NULL; //SethWndToNULL } if(!UnregisterClass("OpenGL",hInstance)) //AreWeAbleToUnregisterClass { MessageBox(NULL,"CouldNotUnregisterClass.","SHUTDOWNERROR",MB_OK|MB_ICONINFORMATION); 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){ GLuint PixelFormat; //HoldsTheResultsAfterSearchingForAMatch WNDCLASS wc; //WindowsClassStructure DWORD dwExStyle; //WindowExtendedStyle DWORD dwStyle; //WindowStyle RECT WindowRect; //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//RedrawOnSize,AndOwnDCForWindow. wc.style =CS_HREDRAW|CS_VREDRAW|CS_OWNDC; wc.lpfnWndProc =(WNDPROC)WndProc; //WndProcHandlesMessages wc.cbClsExtra =0; //NoExtraWindowData wc.cbWndExtra =0; //NoExtraWindowData wc.hInstance =hInstance; //SetTheInstance wc.hIcon =LoadIcon(NULL,IDI_WINLOGO); //LoadTheDefaultIcon wc.hCursor =LoadCursor(NULL,IDC_ARROW); //LoadTheArrowPointer//NoBackgroundRequiredForGL wc.hbrBackground =NULL; wc.lpszMenuName =NULL; //WeDon'tWantAMenu wc.lpszClassName ="OpenGL"; //SetTheClassName if(!RegisterClass(&wc)) //AttemptToRegisterTheWindowClass { MessageBox(NULL,"FailedToRegisterTheWindowClass.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } if(fullscreen) //AttemptFullscreenMode? { DEVMODEdmScreenSettings; //DeviceMode//MakesSureMemory'sCleared memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); //SizeOfTheDevmodeStructure dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth =width; //SelectedScreenWidth dmScreenSettings.dmPelsHeight =height; //SelectedScreenHeight dmScreenSettings.dmBitsPerPel =bits; //SelectedBitsPerPixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;//TryToSetSelectedModeAndGetResults.//NOTE:CDS_FULLSCREENGetsRidOfStartBar. if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { //IfTheModeFails,OfferTwoOptions.QuitOrUseWindowedMode. if(MessageBox(NULL,"TheRequestedFullscreenModeIsNotSupportedBy\nYourVideoCard.UseWindowedModeInstead?","NeHeGL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; //WindowedModeSelected.Fullscreen=FALSE } else { //PopUpAMessageBoxLettingUserKnowTheProgramIsClosing. MessageBox(NULL,"ProgramWillNowClose.","ERROR",MB_OK|MB_ICONSTOP); returnFALSE; //ReturnFALSE } } } if(fullscreen) //AreWeStillInFullscreenMode? { dwExStyle=WS_EX_APPWINDOW; //WindowExtendedStyle dwStyle=WS_POPUP; //WindowsStyle ShowCursor(FALSE); //HideMousePointer } else {//WindowExtendedStyle dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; //WindowsStyle } //AdjustWindowToTrueRequestedSize AdjustWindowRectEx(&WindowRect,dwStyle,FALSE,dwExStyle); //CreateTheWindow if(!(hWnd=CreateWindowEx( dwExStyle, //ExtendedStyleForTheWindow "OpenGL", //ClassName title, //WindowTitle dwStyle| //DefinedWindowStyle WS_CLIPSIBLINGS| //RequiredWindowStyle WS_CLIPCHILDREN, //RequiredWindowStyle 0,0, //WindowPosition//CalculateWindowWidth WindowRect.right-WindowRect.left, //CalculateWindowHeight WindowRect.bottom-WindowRect.top, NULL, //NoParentWindow NULL, //NoMenu hInstance, //Instance NULL))) //DontPassAnythingToWM_CREATE { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"WindowCreationError.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE }//pfdTellsWindowsHowWeWantThingsToBe static PIXELFORMATDESCRIPTORpfd= { sizeof(PIXELFORMATDESCRIPTOR), //SizeOfThisPixelFormatDescriptor 1, //VersionNumber PFD_DRAW_TO_WINDOW| //FormatMustSupportWindow PFD_SUPPORT_OPENGL| //FormatMustSupportOpenGL PFD_DOUBLEBUFFER, //MustSupportDoubleBuffering PFD_TYPE_RGBA, //RequestAnRGBAFormat bits, //SelectOurColorDepth 0,0,0,0,0,0, //ColorBitsIgnored 0, //NoAlphaBuffer 0, //ShiftBitIgnored 0, //NoAccumulationBuffer 0,0,0,0, //AccumulationBitsIgnored 16, //16BitZ-Buffer(DepthBuffer) 0, //NoStencilBuffer 0, //NoAuxiliaryBuffer PFD_MAIN_PLANE, //MainDrawingLayer 0, //Reserved 0,0,0 //LayerMasksIgnored }; if(!(hDC=GetDC(hWnd))) //DidWeGetADeviceContext? { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"Can'tCreateAGLDeviceContext.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) //DidWindowsFindAMatchingPixelFormat? { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"Can'tFindASuitablePixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) //AreWeAbleToSetThePixelFormat? { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"Can'tSetThePixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } if(!(hRC=wglCreateContext(hDC))) //AreWeAbleToGetARenderingContext? { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"Can'tCreateAGLRenderingContext.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } if(!wglMakeCurrent(hDC,hRC)) //TryToActivateTheRenderingContext { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"Can'tActivateTheGLRenderingContext.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } ShowWindow(hWnd,SW_SHOW); //ShowTheWindow SetForegroundWindow(hWnd); //SlightlyHigherPriority SetFocus(hWnd); //SetsKeyboardFocusToTheWindow ReSizeGLScene(width,height); //SetUpOurPerspectiveGLScreen if(!InitGL()) //InitializeOurNewlyCreatedGLWindow { KillGLWindow(); //ResetTheDisplay MessageBox(NULL,"InitializationFailed.","ERROR",MB_OK|MB_ICONEXCLAMATION); returnFALSE; //ReturnFALSE } returnTRUE; //Success}LRESULTCALLBACKWndProc(HWND hWnd, //HandleForThisWindow UINT uMsg, //MessageForThisWindow WPARAMwParam, //AdditionalMessageInformation LPARAMlParam) //AdditionalMessageInformation{ switch(uMsg) //CheckForWindowsMessages { caseWM_ACTIVATE: //WatchForWindowActivateMessage { if(!HIWORD(wParam)) //CheckMinimizationState { active=TRUE; //ProgramIsActive } else //Otherwise { active=FALSE; //ProgramIsNoLongerActive } return0; //ReturnToTheMessageLoop } caseWM_SYSCOMMAND: //InterceptSystemCommands { switch(wParam) //CheckSystemCalls { caseSC_SCREENSAVE: //ScreensaverTryingToStart? caseSC_MONITORPOWER: //MonitorTryingToEnterPowersave? return0; //PreventFromHappening } break; //Exit } caseWM_CLOSE: //DidWeReceiveACloseMessage? { PostQuitMessage(0); //SendAQuitMessage return0; //JumpBack } caseWM_KEYDOWN: //IsAKeyBeingHeldDown? { keys[wParam]=TRUE; //IfSo,MarkItAsTRUE return0; //JumpBack } caseWM_KEYUP: //HasAKeyBeenReleased? { keys[wParam]=FALSE; //IfSo,MarkItAsFALSE return0; //JumpBack } caseWM_SIZE: //ResizeTheOpenGLWindow {//LoWord=Width,HiWord=Height ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return0; //JumpBack } } //PassAllUnhandledMessagesToDefWindowProc returnDefWindowProc(hWnd,uMsg,wParam,lParam);}intWINAPIWinMain( HINSTANCE hInstance, //Instance HINSTANCE hPrevInstance, //PreviousInstance LPSTR lpCmdLine, //CommandLineParameters int nCmdShow) //WindowShowState{ MSG msg; //WindowsMessageStructure BOOL done=FALSE; //BoolVariableToExitLoop //AskTheUserWhichScreenModeTheyPrefer if(MessageBox(NULL,"WouldYouLikeToRunInFullscreenMode?","StartFullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; //WindowedMode } //CreateOurOpenGLWindow if(!CreateGLWindow("NeHe'sParticleTutorial",640,480,16,fullscreen)) { return0; //QuitIfWindowWasNotCreated } if(fullscreen) //AreWeInFullscreenMode { slowdown=1.0f; //IfSo,SpeedUpTheParticles(3dfxIssue) } while(!done) //LoopThatRunsWhiledone=FALSE { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) //IsThereAMessageWaiting? { if(msg.message==WM_QUIT) //HaveWeReceivedAQuitMessage? { done=TRUE; //IfSodone=TRUE } else //IfNot,DealWithWin

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論