user-0 提问: 基于opengl的场景漫游，粒子系统出问题了怎么不下雨啊？求大神指教！！救命啊！！！

回复:
user: user-0
content: VC下运行的，我运行也是一堆错误，当时想知道粒子系统怎么运行的就

user: user-1
content: 编译问题请说明编译环境,操作系统

user: user-2
content: 楼主，你的代码要在什么环境下运行啊，我用VC++运行之后有一大堆错误啊，能否重发一下正确代码。里面有一些OpenGL的函数还不了解惹。

user: user-3
content: 搜网络教程“学OpenGL编3D游戏”。

user: user-0
content: bool ChangeResolution(int w,int h,int bitdepth)   //改变屏幕分辨率 	{ 		DEVMODE devMode; 		int modeSwitch; 		int closeMode=0;  		EnumDisplaySettings(NULL, closeMode,&devMode);  		devMode.dmBitsPerPel=bitdepth; 		devMode.dmPelsWidth=w; 		devMode.dmPelsHeight=h; 		devMode.dmFields=DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;  		modeSwitch=ChangeDisplaySettings(&devMode,CDS_FULLSCREEN);  		if(modeSwitch==DISP_CHANGE_SUCCESSFUL) 		{ 			return true; 		} 		else  		{ 			ChangeDisplaySettings(NULL,0); 			return false; 		} 	}  	LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) //消息处理函数 	{ 		switch(message) 		{ 		case WM_CREATE: 		GetWindowRect(hWnd,&rect); 		sw=rect.right-rect.left; 		sh=rect.bottom-rect.top; 		SceneResizeViewport(sw,sh); 		return 0;  		case WM_SIZE: 			if(!fullscreen) 			{ 				GetWindowRect(hWnd,&rect); 				sw=rect.right-rect.left; 				sh=rect.bottom-rect.top; 				if(sw>0&&sh>0) 					SceneResizeViewport(sw,sh); 			} 			else 			{ 				SceneResizeViewport(GetSystemMetrics(SM_CXSCREEN), 									GetSystemMetrics(SM_CYSCREEN)); 			} 			return 0; 		 		case WM_CLOSE: 			ShowWindow(hWnd,SW_HIDE); 			PostQuitMessage(0); 			return 0;  		case WM_DESTROY: 			return 0;  		case WM_KEYDOWN: 			switch(wParam) 			{ 			case VK_ESCAPE: 				PostMessage(hWnd,WM_CLOSE,0,0); 				break; 			case VK_PRIOR: //page up 				lookupdown -= 1.0f; 				break; 			case VK_NEXT:  //page down 				lookupdown +=1.0f; 				break; 			case VK_UP://////// 					xpos -=q* (float)sin(heading*piover180)*0.5f; 					zpos -=q* (float)cos(heading*piover180)*0.5f; 				//	if (walkbiasangle>=359.0f){walkbiasangle=0.0f;} 				//	else {walkbiasangle+=10;} 				//	walkbias=(float)sin(walkbiasangle*piover180)/20.0f; 				break; 			case VK_DOWN:///// 					xpos +=q* (float)sin(heading*piover180)*0.5f; 					zpos +=q* (float)cos(heading*piover180)*0.5f; 				//	if (walkbiasangle<=1.0f){walkbiasangle=359.0f;} 				//	else {walkbiasangle-=10;} 				//	walkbias=(float)sin(walkbiasangle*piover180)/20.0f; 				break; 			case VK_RIGHT:///////////// 				heading -=2.0f; 				yrot = heading; 				break; 			case VK_LEFT: 				heading +=2.0f; 				yrot = heading; 				break; //////////-----XY轴旋转 			case 'A':   					xup +=q* (float)cos(-heading*piover180)*0.25f; 					zup +=q* (float)sin(-heading*piover180)*0.25f;				 				break; 			case 'D':  //y 					xup -=q* (float)cos(-heading*piover180)*0.25f; 					zup -=q* (float)sin(-heading*piover180)*0.25f;		 				break; 			case 'W':  //y上 				yup -=q*0.4f; 				break; 			case 'S':  //y下 				yup +=q*0.4f; 				break; ////////////////////////////////////// 			case 'B': 				if(!bp) 				{ 					bp=TRUE; 					blend=!blend; 					if(blend) 					{ 						glEnable(GL_BLEND);			//打开混合功能 						glDisable(GL_DEPTH_TEST);	//关闭深度测试 					} 					else 					{ 						glDisable(GL_BLEND);		//关闭混合功能 						glEnable(GL_DEPTH_TEST);	//打开深度测试 					} 				} 					else  					{ 						bp=FALSE; 					} 					break; //////////------路灯开关------------ 			case 'G': 				if(!goodlight) 				{ 					goodlight=TRUE; 				} 				else  				{ 					goodlight=FALSE; 				} 				break; //////////-----透明开关------------ 			case 'L': 				if(!lp) 				{ 					lp=TRUE; 					light=!light; 					if(!light) 					{ 						glDisable(GL_LIGHTING); 					} 					else 					{ 						glEnable(GL_LIGHTING); 					} 				} 				else 				{ 					lp=FALSE; 				} 				break; 			} 			return 0; 			case WM_LBUTTONDOWN:          //是否按下鼠标左键 				{ 					bRender=!bRender; 					return 0; 				}  			default: 				return DefWindowProc(hWnd,message,wParam,lParam); 		}  	} GLvoid KillGLWindow(GLvoid)								 	{ 		if (fullscreen)										 		{ 			ChangeDisplaySettings(NULL,0);					 			ShowCursor(TRUE);								 		}  		if (hRC)											 		{ 			if (!wglMakeCurrent(NULL,NULL))					 			{ 				MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 			}  			if (!wglDeleteContext(hRC))						 			{ 				MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 			} 			hRC=NULL;									 		}  		if (hDC && !ReleaseDC(hWnd,hDC))				 		{ 			MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 			hDC=NULL;										 		}  		if (hWnd && !DestroyWindow(hWnd))					 		{ 			MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 			hWnd=NULL;									 		}  		if (!UnregisterClass("OpenGL",hInstance))			 		{ 			MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 			hInstance=NULL;									 		} 	}

user: user-0
content: GLvoid glDrawCube()					// 绘制立方体 { 		glBegin(GL_QUADS);			 		// 前面 		glNormal3f( 0.0f, 0.0f, 1.0f);		 		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	 		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	 		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	 		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	 		// 后面 		glNormal3f( 0.0f, 0.0f,-1.0f);		 		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	 		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	 		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	 		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	 		// 上面 		glNormal3f( 0.0f, 1.0f, 0.0f);		 		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	 		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	 		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	 		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	 		// 下面 		glNormal3f( 0.0f,-1.0f, 0.0f);		 		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	 		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	 		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	 		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	 		// 右面 		glNormal3f( 1.0f, 0.0f, 0.0f);		 		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	 		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	 		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	 		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	 		// 左面 		glNormal3f(-1.0f, 0.0f, 0.0f);		 		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	 		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	 		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	 		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	 	glEnd();					 }  //天空盒的函数实现 void skybox() { glBindTexture(GL_TEXTURE_2D, texture[30]);//南 glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 50.0f, -50.0f, 50.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( -50.0f, -50.0f, 50.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( -50.0f, 50.0f, 50.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 50.0f, 50.0f, 50.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[1]);//东 glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 50.0f, -50.0f, -50.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 50.0f, -50.0f, 50.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 50.0f, 50.0f, 50.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 50.0f, 50.0f, -50.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[2]);//北 glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -50.0f, -50.0f, -50.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 50.0f, -50.0f, -50.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 50.0f, 50.0f, -50.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -50.0f, 50.0f, -50.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[3]);//西 glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( -50.0f, -50.0f, 50.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( -50.0f, -50.0f, -50.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( -50.0f, 50.0f, -50.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( -50.0f, 50.0f, 50.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[4]);//底 glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 50.0f, -50.0f, -50.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( -50.0f, -50.0f, -50.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( -50.0f, -50.0f, 50.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 50.0f, -50.0f, 50.0f); glEnd(); glBindTexture(GL_TEXTURE_2D, texture[5]);//顶 glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f( 50.0f, 50.0f, 50.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( -50.0f, 50.0f, 50.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( -50.0f, 50.0f, -50.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 50.0f, 50.0f, -50.0f); glEnd(); } void EnableOpenGL() { 	PIXELFORMATDESCRIPTOR pfd; 	int iFormat;  	hDC=GetDC(hWnd);  	ZeroMemory(&pfd,sizeof(pfd)); 	pfd.nSize=sizeof(pfd); 	pfd.nVersion=1; 	pfd.dwFlags= PFD_DRAW_TO_WINDOW | 				 PFD_SUPPORT_OPENGL | 				 PFD_DOUBLEBUFFER; 	pfd.iPixelType=PFD_TYPE_RGBA; 	pfd.cColorBits=16; 	pfd.cDepthBits=16; 	pfd.iLayerType=PFD_MAIN_PLANE;  	iFormat=ChoosePixelFormat(hDC,&pfd);  	SetPixelFormat(hDC,iFormat,&pfd);  	hRC=wglCreateContext(hDC); 	wglMakeCurrent(hDC,hRC); }  //取消OPENGL void DisableOpenGL() { 	wglMakeCurrent(NULL,NULL); 	wglDeleteContext(hRC); 	ReleaseDC(hWnd,hDC); 		if (fullscreen)										 	{ 		ChangeDisplaySettings(NULL,0);					 		ShowCursor(TRUE);								 	}  	if (hRC)											 	{ 		if (!wglMakeCurrent(NULL,NULL))					 		{ 			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 		}  		if (!wglDeleteContext(hRC))						 		{ 			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 		} 		hRC=NULL;									 	}  	if (hDC && !ReleaseDC(hWnd,hDC))				 	{ 		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 		hDC=NULL;										 	}  	if (hWnd && !DestroyWindow(hWnd))					 	{ 		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 		hWnd=NULL;									 	}  	if (!UnregisterClass("OpenGL",hInstance))			 	{ 		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); 		hInstance=NULL;									 	}   }

user: user-0
content: void SceneInit (int w,int h) {	 	LoadGLTextures();			//条到处理调用位图并用此位图建立纹理的子程序 	glEnable(GL_TEXTURE_2D);	//纹理被创建，并允许2D纹理贴图  	glShadeModel(GL_SMOOTH); 	glClearColor(0.0,0.0,0.0,0.5); 	glClearDepth(1.0f); 	glEnable(GL_DEPTH_TEST); 	glDepthFunc(GL_LEQUAL); 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 	//设置光源参数 	glLightfv(GL_LIGHT1,GL_AMBIENT,LightAmbient);		//设置环境光 	glLightfv(GL_LIGHT1,GL_DIFFUSE,LightDiffuse);		//设置漫反射光 	glLightfv(GL_LIGHT1,GL_POSITION,LightPosition);		//光源的位置 	glEnable(GL_LIGHT1);								//允许光源一  	glColor4f( 1.0f, 1.0f, 1.0f, 0.5);					//全亮度，50%的透明 	glBlendFunc(GL_SRC_ALPHA,GL_ONE);					//基于半透明的混合方式 } void SceneResizeViewport(GLsizei w, GLsizei h) { 	if(h==0) 	{h=1;} 	aspect=(GLfloat)w/(GLfloat)h; glViewport(0,0,w,h); 	glMatrixMode(GL_PROJECTION);						//选择投影句镇 	glLoadIdentity(); gluPerspective(45.f,aspect,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } ///////////////这里进行说有的绘图工作//////////////////////////////////////// int SceneShow(GLvoid) { 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	//清屏和清除深度缓冲区 	glLoadIdentity();									//重置当前MODELVIEW矩阵 	glDisable(GL_BLEND); 	glDisable(GL_COLOR_BUFFER_BIT); 	glEnable(GL_TEXTURE_2D); GLfloat xtrans=-xpos; GLfloat ztrans=-zpos; 	GLfloat ytrans=-0.25f; 	GLfloat sceneroty=360.0f-yrot; 	//开始绘图     //开始绘图    glRotatef(lookupdown,1.0f,0,0);					//X旋转    glRotatef(sceneroty,0,1.0f,0);					//y旋转    skybox();    glTranslatef(xtrans+xup,ytrans+yup,ztrans+zup);	//移动    	//-------------------------------------------------------------------- 	if(keys[VK_TAB]) 	{ 	glBindTexture(GL_TEXTURE_2D,texture[22]);//绘制雨滴粒子 	 	for(int i=SOURCE/2;i<SOURCE;i++) 	{ 		for (loop=(i)*(MAX_PARTICLES/SOURCE);loop<(i+1)*(MAX_PARTICLES/SOURCE);loop++)					 		{ 			if (particle[loop].active)							 			{ 				float x=particle[loop].x=-25+(i-SOURCE/2)*(100/SOURCE);					 				float y=particle[loop].y+40;					 				float z=particle[loop].z+zoom;				  				 				glColor4f(particle[loop].r,particle[loop].g,particle[loop].b,particle[loop].life);  				glBegin(GL_TRIANGLE_STRIP);						 				glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); 				glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); 				glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z);  				glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); 				glEnd();										  				particle[loop].x+=particle[loop].xi/(slowdown*1000); 				particle[loop].y+=particle[loop].yi/(slowdown*1000); 				particle[loop].z+=particle[loop].zi/(slowdown*1000);  				particle[loop].xi+=particle[loop].xg;		 				particle[loop].yi+=particle[loop].yg;			 				particle[loop].zi+=particle[loop].zg;			 				particle[loop].life-=particle[loop].fade;		  				if (particle[loop].life<0.0f)				 				{ 					particle[loop].life=1.0f;					 					particle[loop].fade=float(rand()%100)/FADE+0.002f;	 					particle[loop].x=0.0f;						 					particle[loop].y=0.0f;						 					particle[loop].z=0.0f;						 					particle[loop].xi=xspeed+float((rand()%60)-32.0f); 					particle[loop].yi=yspeed+float((rand()%60)-30.0f);	 					particle[loop].zi=float((rand()%60)-30.0f); 					particle[loop].r=colors[0];			 					particle[loop].g=colors[1];			 					particle[loop].b=colors[2];			 				}  			} 				 			} 		} 	} return TRUE;											 }