版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
电子科技大学实验报告学生姓名:学号:指导教师:实验地点:实验时间:一、实验室名称:计算机学院软件实验室二、实验项目名称:三维特效技术三、实验学时:8学时四、实验原理很多的现象都可以用粒子系统精确的或者近似的模拟,如火焰、喷泉、爆炸、鱼群和星空等等。一个粒子系统由拥有各种属性的对象组成,它们必须遵循一定的行为规范。具体的这些属性和行为规范取决于需要模拟的内容是什么。一些粒子系统可能需要很多属性和复杂的规则,而有的则可能极为简单。根据粒子设置的复杂性,可以产生:简单的可以实现喷泉、烟雾、火焰等;复杂一点的可以实现flocking等;再复杂一点就可以利用粒子系统模拟实现衣物等弹性物体。粒子系统是一种物理模型,粒子系统的核心不在于如何显示图形,而是在于对某个物理模型的理解和分析。只有基于物理模型的方法,才能模拟出随机而逼真的自然景象。粒子的运动(变化)规律可以很简单也可以很复杂,这取决于模拟的物理模型的复杂程度。对于每一个粒子,它应具有以下属性:(1)坐标(Coordinates) :对于每一个粒子,最终都要把它映射到屏幕上,所以坐标成为一个粒子最为重要的属性之一。每个粒子的坐标随时间的变化而变化,它通过每个粒子自身在各时刻的速度求得。(2)速度(Velocity):运动的粒子都有速度,每个粒子的速度可以各不相同。速度用来计算下一时刻粒子的坐标(位置)。(3)加速度(Acceleration): 粒子可以做变速运动,此时加速度便会发生作用。它用来计算下一时刻粒子的速度。(4)生命值(Life):每个粒子都有着自己的生命值,随着时间的推移,粒子的生命值不断减小,直到粒子死亡(生命值为0)。一个生命周期结束时,另一个生命周期随即开始,有时为了使粒子能够源源不断地涌出,必须使一部分粒子在初始后立即死亡,这个技巧在后面的实现中会具体说明。(5)衰减(Decay):就象人会衰老一样,每个粒子也有它自己的生命周期,Decay就是用来控制粒子生命周期的一个物理量。五、实验目的本实验要实现一个基本的粒子系统,该基本粒子系统必须具有以下模块:粒子生成、给粒子施加力(例如:重力、拖力等)、粒子的碰撞效果(例如与其他几何体碰撞,并反弹回来)。基本系统实现之后,学生可以选择一些针对粒子绘制和物理仿真方面的扩展。针对绘制的扩展可以产生如:烟雾、火光、火花等特效。针对物理方面的扩展可以产生如:衣物、绳子、甚至鸟群、鱼群等。六、实验内容利用OpenGL实现一个标准的粒子系统特效,如:烟花、喷泉等。七、实验器材(设备、元器件)操作系统:WindowsXP开发工具:VC2003,OpenGLl库普通PC即可八、实验步骤创建工程启动VC++2003,创建空白工程项目。选择菜单中的“文件”->“新建”->“项目”,在弹出的对话框中,左边的“项目类型”框中,选择“VisualC++项目”,在右边框中,选择“空项目(.Net)”,在对话框下边,选择工程文件存放目录及输入名称,如Example1,单击“确定”。设置此工程所需的OpenGL库选择菜单中的“项目”->“Example1属性”,在弹出的“Example1属性页”对话框中,单击“链接器”->“输入”,选择右边框中的“附加依赖项”,单击最右端的“…”小按钮,弹出“附加依赖项”对话框,输入“opengl32.lib
glu32.lib
glaux.lib”(注意,输入双引号中的内容,各个库用空格分开;否则会出现链接错误),单击“确定”结束,返回“属性页”对话框,单击“确定”。OpenGL库设置完成。在工程项目中添加源文件在解决方案资源管理器中,鼠标右击“源文件”,弹出浮动菜单,选择“添加”->“添加新项”,弹出“添加新项-Example1”对话框,在右边的模板框中,选择“C++文件(.cpp)”,输入文件名,单击“打开”,添加源文件结束。如果需要添加头文件,其操作方法相似。本例没有编写的头文件。录入源程序将预习时编写的源程序录入到计算机中。本例的源代码来自OpenGL的编程教程,仅作为本实验的参考代码。学生可以自己编写粒子系统,也以此为基础,修改源代码生成不同的粒子系统。说明:准备好粒子显示图片,取名为Particle.bmp,并放在当前目录的子目录data下。该图片将作为粒子的纹理,如图1所示。图1粒子纹理图片图1粒子纹理图片九、实验数据及结果分析程序执行后,看到粒子爆炸、散开,然后粒子不断往往下坠落。如图2所示。通过修改粒子速度、加速度、生命期等参数,可以看到粒子效果的差别。图2粒子特效截图图2粒子特效截图十、实验结论利用OpenGL能够实现粒子系统特效,如:喷泉、烟雾等。十一、总结及心得体会OpenGL具有强大的图形绘制功能,能很好地支持图形设计。十二、对本实验过程及方法、手段的改进建议程序设计合理,代码可进一步优化。报告评分:指导教师签字:本实验参考源代码如下:/** 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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年农产品追溯体系优化建议
- 2026年会计电算化实操考核试题题库及答案
- 2025 年中考数学押题预测卷解析版(山东青岛卷)
- 金属屋面安装方案
- 食品检验室清洗消毒和维修保养制度
- 康复学基础练习题库(含参考答案)
- 化工企业甲醛泄漏中毒应急演练脚本
- 消防设施防晒防雨操作和维护保养规程
- 流量计检修规程
- 2026年江苏省扬州市网格员招聘考试参考题库及答案解析
- IT项目外包人员管理制度
- 小红书种草营销师模拟题及答案(单选+多选+判断)
- 粮油食材配送投标方案(大米食用油食材配送服务投标方案)(技术方案)
- 新解读《JTGT 3660-2020公路隧道施工技术规范》
- JTG-H30-2015公路养护安全作业规程
- 采用矿山法、盾构法、顶管法施工的隧道、洞室工程
- MH-T 5059-2022民用机场公共信息标识系统设置规范
- 思皓E10X保养手册
- 安全监理考试题库
- 市政道路改造管网施工组织设计
- 海外项目科技技术管理探讨汇报材料
评论
0/150
提交评论