Exemple #1
0
static void Init(int argc, char *argv[])
{
   GLfloat fogColor[4] = {0.5,1.0,0.5,1.0};

   xrot = 0;
   yrot = 0;
   dist = -6;
   plane[0] = 1.0;
   plane[1] = 0.0;
   plane[2] = -1.0;
   plane[3] = 0.0;

   glClearColor(0.0, 0.0, 1.0, 0.0);
   glEnable( GL_DEPTH_TEST );
   glEnableClientState( GL_VERTEX_ARRAY );
   glEnableClientState( GL_NORMAL_ARRAY );

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glClipPlane(GL_CLIP_PLANE0, plane);

   InitMaterials();

   set_matrix();

   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);


   /* Green fog is easy to see */
   glFogi(GL_FOG_MODE,GL_EXP2);
   glFogfv(GL_FOG_COLOR,fogColor);
   glFogf(GL_FOG_DENSITY,0.15);
   glHint(GL_FOG_HINT,GL_DONT_CARE);

   {
      static int firsttime = 1;
      if (firsttime) {
	 firsttime = 0;
	 compactify_arrays();
	 expand_arrays();
	 make_tri_indices();

	 if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
	    printf("Error: couldn't load texture image\n");
	    exit(1);
	 }
      }
   }

   ModeMenu(SHADE_SMOOTH|
	    LIT|
	    POINT_FILTER|
	    NO_USER_CLIP|
	    NO_MATERIALS|
	    NO_FOG|
	    NO_STIPPLE|
	    IMMEDIATE|
	    STRIPS|
	    UNLOCKED|
	    GLVERTEX);

   if (PrintInfo) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
   }
}
//Función para inicializar el juego.
bool cGame::Init()
{	
	mbFinish = false;

	bool lbResult;

	lbResult = LoadResources();

	cMatrix lScaleMatrix, lOffsetMatrix;

	// Preparamos ya la escala y el offset que usaran el resto de objetos
	lScaleMatrix.LoadScale( .02f );
	lOffsetMatrix.LoadTranslation( cVec3( 0.0f, 0.0f, 0.0f ) );
	// Inicializamos el modelo de esfera
	mSphereModel.InitSphere( 1.0f, 2.0f );
	for ( unsigned int luiIndex = 0; luiIndex < 10; ++luiIndex) {
		maSphereObjects.push_back( mModelObject );
		cPhysicObject &lSphereObject = maSphereObjects.back();
		cMatrix lTransMatrix;
		lTransMatrix.LoadTranslation( cVec3( 0.0, 4.0 + 5.0 * luiIndex, 0.5 * luiIndex ) ); // Las creamos formando una columna
		lSphereObject.SetWorldMatrix( lTransMatrix );
		lSphereObject.SetScaleMatrix( lScaleMatrix );
		lSphereObject.SetDrawOffsetMatrix( lOffsetMatrix );
		lSphereObject.CreatePhysics( &mSphereModel );
	}	

	// Play idle animation 
	//lpSkeletonMesh->PlayAnim("Idle", 1.0f, 1.0f);
	

	// Posicionamiento inicial del personaje
	/*cMatrix lRotation, lTranslation;
	lTranslation.LoadTranslation(cVec3(0.f, -1.f, 0.f));
	mObject.SetDrawOffsetMatrix( lTranslation );
	mObject.SetKinematic( );	

	CharacterPos::Get().Init(cVec3(0.f, 0.f, 15.f), C_720PI, 10, 0.5f);*/

	// Estamos en modo juego, no depuración
	mbInGame = true;
	// Se inicializa en modo rasterizacion solida
	mbRasterizationMode = true;

	mMustang.Init(&mExt, &mInt, &mMet, &mTire, &mWeaponMuzzle1, &mWeaponMuzzle2, &mWeaponMuzzle3, &mArrowEnemy, &mPositiveAmmunition, &mNegativeAmmunition, 
		&mMustangExteriorDes, &mMustangInteriorDes
		, &mExplosion_sprite, &mExplosion_sprite1, &mParticle, &mCrosshair, &mhud1, &mhud1_mask, &mPositivelive, &mNegativelive);

	// Incializacion de enemigo 1 (Truck)
	mTruck.Init(cVec3(0.f, 0.0f, -90.f), &mTruckExterior, &mTruckWea, &mTruckTire, &mWeaponMuzzle1, &mWeaponMuzzle2, &mWeaponMuzzle3, &mTruckExteriorDes, &mTruckWeaponDes, &mExplosion_sprite, &mExplosion_sprite1, &mParticle);

	// Inicializa obstaculo (ruina)

	float a = - MAP_SIZE / 2;
	float b = MAP_SIZE / 2;

	for ( unsigned int luiIndex = 0; luiIndex < RUINS_NUMBER; ++luiIndex) {
		
		float random_x = ((b - a) * ((float)rand() / RAND_MAX)) + a;
		float random_z = ((b - a) * ((float)rand() / RAND_MAX)) + a;
		float random_angle = PI * rand();

		cMatrix lmRuinPos, lmRuinRotate, lmRuinPosRot;
		lmRuinPos.LoadTranslation(cVec3(random_x, -0.5f, random_z));
		lmRuinRotate.LoadRotation(cVec3(0.f, 1.f, 0.f), random_angle);

		lmRuinPosRot = lmRuinPos * lmRuinRotate;
		mRuin.Init(&mRuinObs, lmRuinPosRot);

		maRuins.push_back( mRuin );
		
	}

	// Inicializa obstaculo (matorrales)

	for ( unsigned int luiIndex = 0; luiIndex < BUSH_NUMBER; ++luiIndex) {
		
		float random_x = ((b - a) * ((float)rand() / RAND_MAX)) + a;
		float random_z = ((b - a) * ((float)rand() / RAND_MAX)) + a;
		
		cMatrix lmBushPos;
		lmBushPos.LoadTranslation(cVec3(random_x, -3.0f, random_z));

		//lmRuinPos.LoadTranslation(cVec3(0.f, -0.5f, 0.f));
		mBush.Init(&mBushTexture, &mBushTextureMask, lmBushPos);

		maBushes.push_back( mBush );
		
	}

	GLfloat density = 0.0002f;

	//GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0}; 
	GLfloat fogColor[4] = {1.0f, 0.9f, 0.7f, 1.0f};

	glEnable (GL_FOG);

	glFogi (GL_FOG_MODE, GL_EXP2);


	glFogfv (GL_FOG_COLOR, fogColor);

	glFogf (GL_FOG_DENSITY, density);

	glHint (GL_FOG_HINT, GL_NICEST);

	// Contador de animacion niebla
	miFogStep = 0;
	mfFogDensity = density;
	mbFogIncreasing = true;

	// Application start time
	mfAcTime = 0.0f;

    return lbResult;	
}
Exemple #3
0
void CSkybox::Render(float cameraX, float cameraY, float cameraZ)
{
	glPushMatrix();

	// Move the skybox so that it's centered on the camera.
	glTranslatef(cameraX, cameraY, cameraZ);

	glPushAttrib(GL_FOG_BIT | GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT);
	glDisable(GL_DEPTH_TEST);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

	// Top
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_TOP]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_size, m_size, -m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(m_size, m_size, -m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(m_size, m_size, m_size);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_size, m_size, m_size);
	glEnd();

	GLfloat fog_color[4] = {0.2f, 0.2f, 0.2f, 0.8};
	// skybox origin should be same as camera position
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE, GL_EXP2);
	glFogf(GL_FOG_START, 10.0);
	glFogf(GL_FOG_END, 1000.0);
	glFogfv(GL_FOG_COLOR, fog_color);
	glFogf(GL_FOG_DENSITY, 0.3);
	// Bottom
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_BOTTOM]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(m_size, -m_size, -m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_size, -m_size, -m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(m_size, -m_size, m_size);
	glEnd();
	glDisable(GL_FOG);

	// Front
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_FRONT]);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_size, -m_size, -m_size);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(m_size, -m_size, -m_size);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(m_size, m_size, -m_size);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_size, m_size, -m_size);
	glEnd();

	// Back
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_BACK]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_size, m_size, m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(m_size, m_size, m_size);
	glEnd();

	// Right
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_RIGHT]);
	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(m_size, -m_size, m_size);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(m_size, m_size, m_size);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(m_size, m_size, -m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(m_size, -m_size, -m_size);
	glEnd();

	// Left
	glBindTexture(GL_TEXTURE_2D, m_textures[SKY_LEFT]);
	glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_size, -m_size, -m_size);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_size, m_size, -m_size); 
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_size, m_size, m_size);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_size, -m_size, m_size);
	glEnd();

	glPopAttrib();
	glEndList();
	glPopMatrix();
}
Exemple #4
0
void	Update()
// Runs one iteration of the game loop.
{
	CurrentTicks = Timer::GetTicks() - StartTicks;
	int	DeltaTicks = CurrentTicks - LastTicks;

	// Force DeltaTicks to a fixed value if we're making a movie.
	if (Config::GetValue("RecordMoviePath") /*&& Config::GetBool("RecordMoviePause") == false*/ ) {
		DeltaTicks = 33;
		if (MovieFrameNumber % 3 == 0) DeltaTicks++;	// Exactly 30 frames/sec.

		// Monkey with the time base so that CurrentTicks
		// increments at 30 frames/sec in sync with DeltaTicks.
		// This is so code which samples CurrentTicks will behave
		// properly during movie recording.
		CurrentTicks = LastTicks + DeltaTicks;
//		StartTicks = (Timer::GetTicks() - CurrentTicks);
	}
	
	if (MovieMode == true) {
		LastTicks = CurrentTicks;

		if (DeltaTicks > 200) DeltaTicks = 200;
		
		//
		// Movie mode.
		//
		// Don't do world update and rendering.  Just show the movie, until
		// it's done, or until the user escapes past the movie.

		// Check for user escape.
		int	UpdateCount = 0;	// For protection against update functions taking longer than the sampling period.
		UpdateState	u;
		while (UpdatesPending() && UpdateCount++ < 30) {
			GetNextUpdateState(&u);
		}
		if (Input::CheckForEventDown(Input::BUTTON0) ||
		    Input::CheckForEventDown(Input::ENTER) ||
		    Input::CheckForEventDown(Input::ESCAPE) ||
		    Input::CheckForEventDown(Input::BUTTON2) ||
		    Config::GetBoolValue("SkipIntro"))
		{
			// Cut the movie short.
			MovieDuration = 0;
		}
		Input::EndFrameNotify();
		
		// Show a new frame.
		glViewport(0, 0, Render::GetWindowWidth(), Render::GetWindowHeight());
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		if (MoviePlayer) MoviePlayer->play(DeltaTicks);

		if (Config::GetValue("RecordMoviePath")) SaveMovieFrame();
		
		Render::ShowFrame();

		MovieDuration -= DeltaTicks;

		if (MovieDuration <= 0) {
			// Done with the movie, now exit movie mode.
			MovieDuration = 0;

			if (MoviePlayer) {
				MoviePlayer->unRef();
				MoviePlayer = NULL;
			}

			MovieMode = false;
		}

		// Sleep a little.
		int	SleepTime = 13 - DeltaTicks;
		if (SleepTime > 0) {
			Timer::Sleep(SleepTime);
		}
		
		return;
	}

	//
	// Update the game logic & physics.
	//

	UpdateState	u;
	
	if (Config::GetValue("RecordMoviePath") != NULL) {
		// Special case -- simulate a fixed update rate.

		// Consume input.
		do {
			GetNextUpdateState(&u);
		} while (UpdatesPending());

		u.DeltaTicks = DeltaTicks;	// Force frame time.
		u.Ticks = CurrentTicks;
		DoUpdates(u);
			
	} else {
		// Normal case -- consume input info and update in real-time.
		int	UpdateCount = 0;	// For protection against update functions taking longer than the sampling period.
		while (UpdatesPending() && UpdateCount++ < 30) {
			GetNextUpdateState(&u);
			DoUpdates(u);
		}
		if (!Config::GetBoolValue("LimitUpdateRate")) {
			UpdateCount++;
			GetNextUpdateState(&u);
			
			//xxxxxx
			Config::SetBoolValue("LastUpdateBeforeRender", true);
			//xxxxx
			
			DoUpdates(u);
		} else {
			if (UpdateCount) {
				Config::SetBoolValue("LastUpdateBeforeRender", true);
			}
		}
		
		if (UpdateCount == 0) {
			return;
		}
	}
	
	LastTicks = CurrentTicks;

	// Don't try to render if we've entered movie mode during the updates.
	if (MovieMode) return;

	// Don't render if we're about to quit.
	if (Main::GetQuit()) return;
	
	// Render visuals.

	int number_of_players = MultiPlayer::NumberOfLocalPlayers();
	
	int window_corner_x[4];
	int window_corner_y[4];
	int window_size_x[4];
	int window_size_y[4];
	
	SetWindowCoordinates(number_of_players, window_corner_x, window_corner_y, window_size_x, window_size_y);

	// For each player, draw graphics
	for (int player_index = 0; player_index < number_of_players; player_index++){

	  MultiPlayer::SetCurrentPlayerIndex(player_index);
	  
	  ViewState	s;


	  // Increment the frame number.
	  //if (player_index == 0)
	  FrameNumber++;
	  s.FrameNumber = FrameNumber;
	  
	  // Set the time value.
	  s.Ticks = u.Ticks;
	
	float	ViewAngle = Config::GetFloatValue("ViewAngle") * (PI / 180);

	// Get viewer orientation.
	vec3	ViewerDir = XAxis;
	vec3	ViewerUp = YAxis;
	vec3	ViewerLoc = ZeroVector;
	if (Viewer) {
		ViewerDir = Viewer->GetDirection();
		ViewerUp = Viewer->GetUp();
		ViewerLoc = Viewer->GetLocation();

		if (ViewerDir.checknan() || ViewerUp.checknan()) {
			// Trouble.  Fall back to a default orientation.
			ViewerDir = XAxis;
			ViewerUp = YAxis;
		}
		if (ViewerLoc.checknan()) {
			// Trouble.  Fall back to a default location.
			ViewerLoc = ZeroVector;
		}
	}

	// Establish transformation from world coordinates to view coordinates.
	s.CameraMatrix.View(ViewerDir, ViewerUp, ViewerLoc);

	s.ViewMatrix = s.CameraMatrix;
	s.Viewpoint = ViewerLoc;
	s.MinZ = 1;
	s.MaxZ = Z_MAX;
	s.OneOverMaxZMinusMinZ = 1.0f / (s.MaxZ - s.MinZ);

	// Set the clipping planes.
//	s.ClipPlaneCount = 0;

	// Near.
	s.ClipPlane[0].Normal = ZAxis;
	s.ClipPlane[0].D = s.MinZ;
//	s.ClipPlaneCount++;

	// Left.
	s.ClipPlane[1].Normal = vec3(-cosf(ViewAngle/2), 0, sinf(ViewAngle/2));
	s.ClipPlane[1].D = 0;
//	s.ClipPlaneCount++;
	
	// Right.
	s.ClipPlane[2].Normal = vec3(cosf(ViewAngle/2), 0, sinf(ViewAngle/2));
	s.ClipPlane[2].D = 0;
//	s.ClipPlaneCount++;

//	float	AspectRatio = float(Render::GetWindowHeight()) / float(Render::GetWindowWidth() * 2.0); // Bjorn
//	float	VerticalAngle2 = atanf(tanf(ViewAngle/2) * AspectRatio);
	float	AspectRatio = float(window_size_y[player_index]) / float(window_size_x[player_index]); // Bjorn
	float	VerticalAngle2 = atanf(tanf(ViewAngle/2) * AspectRatio);

	// Top.
	s.ClipPlane[3].Normal = vec3(0, -cosf(VerticalAngle2), sinf(VerticalAngle2));
	s.ClipPlane[3].D = 0;
//	s.ClipPlaneCount++;
	
	// Bottom.
	s.ClipPlane[4].Normal = vec3(0, cosf(VerticalAngle2), sinf(VerticalAngle2));
	s.ClipPlane[4].D = 0;
//	s.ClipPlaneCount++;
	
	// Far.
	s.ClipPlane[5].Normal = -ZAxis;
	s.ClipPlane[5].D = -s.MaxZ;
//	s.ClipPlaneCount++;

	// Set the projection factors so the view volume fills the screen.
	s.XProjectionFactor = (Render::GetWindowWidth() - 0.6f) / 2 / tanf(ViewAngle/2);
	s.YProjectionFactor = s.XProjectionFactor;

	// Set the x/y offsets so that 0,0 appears in the middle of the screen.
	s.XOffset = (Render::GetWindowWidth() + 1) * 0.5f;
	s.YOffset = (Render::GetWindowHeight() + 1) * 0.5f;

	// Only clear the screen the first time each frame
	if (player_index == 0){
	  Render::BeginFrame();
	  Render::ClearFrame();
	}

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	

	// Set the viewport (split the screen)
	glViewport(window_corner_x[player_index], 
		   window_corner_y[player_index], 
		   window_size_x[player_index], 
		   window_size_y[player_index]);
	
	// Set up OpenGL matrices.
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	float	w = 2 * s.MinZ * tanf(ViewAngle/2);
	float	h = w * AspectRatio;
	OGLFrustum(w, h, s.MinZ, s.MaxZ);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	OGLViewMatrix(ViewerDir, ViewerUp, ViewerLoc);

	// Update the terrain.
	TerrainMesh::Update(s);

	// Set up fog parameters.
	if (Config::GetBoolValue("Fog")) {
		glEnable(GL_FOG);
		glFogi(GL_FOG_MODE, GL_LINEAR /* GL_EXP */);
		glFogf(GL_FOG_START, 0);
		glFogf(GL_FOG_END, Weather::GetFadeDistance());	// For GL_LINEAR mode.
//		glFogf(GL_FOG_DENSITY, 4.852 / Weather::GetFadeDistance());		// For GL_EXP mode; meaningless for GL_LINEAR mode.
		glHint(GL_FOG_HINT, GL_NICEST);
		glFogfv(GL_FOG_COLOR, Weather::GetFadeColor());
	}

	// Determine far clipping plane, and decide whether or not to do two passes.
	float	MaxZ = fmin(Z_MAX, Weather::GetFadeDistance());
	bool	TwoPass = true;	// Should set to false if we have a 24- or 32-bit z-buffer...
	if (MaxZ < TWO_PASS_CUTOFF) TwoPass = false;
	if (TwoPass && Config::GetBoolValue("ZSinglePass")) TwoPass = false;	// Manual override, force single pass.
	
	float	MidZ = MaxZ;

	if (TwoPass) {
		//
		// Draw the distant part of the world.
		//

		// Pick a z value to separate the near and far passes, in order to optimize z-buffer usage.
		MidZ = sqrtf(Z_MIN * Z_MAX);

		s.MaxZ = MaxZ;
		s.MinZ = MidZ * 0.9f;
		s.OneOverMaxZMinusMinZ = 1.0f / (s.MaxZ - s.MinZ);
		// Near.
		s.ClipPlane[0].Normal = ZAxis;
		s.ClipPlane[0].D = s.MinZ;
		
		// Far.
		s.ClipPlane[5].Normal = -ZAxis;
		s.ClipPlane[5].D = -s.MaxZ;
		
		// Set up OpenGL matrices.
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		w = 2 * s.MinZ * tanf(ViewAngle/2);
		h = w * AspectRatio;
		OGLFrustum(w, h, s.MinZ, s.MaxZ);
		
		glMatrixMode(GL_MODELVIEW);
//		glLoadIdentity();
//		OGLViewMatrix(Viewer->GetDirection(), Viewer->GetUp(), Viewer->GetLocation());
		
		// Bjorn : moved this for sky to work when having two players
		// Draw a backdrop.
		glDisable(GL_FOG);
		Weather::RenderBackdrop(s);
		
		TerrainMesh::Render(s);
		
		Model::Render(s);
	}

	//
	// Draw closer part of terrain.
	//
	
	Render::ClearZBuffer();

	s.MaxZ = MidZ;
	s.MinZ = Z_MIN;
	s.OneOverMaxZMinusMinZ = 1.0f / (s.MaxZ - s.MinZ);
	// Near.
	s.ClipPlane[0].Normal = ZAxis;
	s.ClipPlane[0].D = s.MinZ;

	// Far.
	s.ClipPlane[5].Normal = -ZAxis;
	s.ClipPlane[5].D = -s.MaxZ;
	
	// Set up OpenGL matrices.
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	w = 2 * s.MinZ * tanf(ViewAngle/2);
	h = w * AspectRatio;
	OGLFrustum(w, h, s.MinZ, s.MaxZ);
	
	glMatrixMode(GL_MODELVIEW);
//	glLoadIdentity();
//	OGLViewMatrix(Viewer->GetDirection(), Viewer->GetUp(), Viewer->GetLocation());
	
	TerrainMesh::Render(s);

	// Draw the objects.
	Model::Render(s);

	//
	// Overlay effects.
	//
	
	// Turn off the fog for overlay stuff.
	glDisable(GL_FOG);
	
	if (Config::GetBoolValue("BoarderShadow")) {
		// Draw boarder shadow.
		Boarder::RenderShadow(s);
	}
	
	// Draw a trail in the snow.
//	Trail::Render(s);

	// Draw ballistic particles.
	Particle::Render(s);

	// Draw weather overlays (falling snow, etc).
	if (player_index == 0)
	  Weather::RenderOverlay(s, true);
	else
	  Weather::RenderOverlay(s, false);
	
	// End of 3D drawing.
	Render::EndFrame();

	// Draw any UI stuff.
	UI::Render(s, player_index);

	// Music captions.
	Music::Render(s);
	
	// Console.
	Console::Render(s);

	// Remember the frame time, for computing frame rate stats.
	FrameTimeQueue[NextFTSample].Timestamp = CurrentTicks;
	FrameTimeQueue[NextFTSample].FrameTime = DeltaTicks;
	NextFTSample += 1;
	if (NextFTSample >= FT_SAMPLES) NextFTSample = 0;
	
	// Show the frame rate.
	if (Config::GetBoolValue("ShowFrameRate")) {
		// Compute min, max, average frame times over the past one second.
		int	min = 1000, max = 1, sum = 0, SampleCount = 0;
		int	i;
		for (i = 0; i < FT_SAMPLES; i++) {
			FrameTimeSample&	s = FrameTimeQueue[i];
			if (CurrentTicks - s.Timestamp < 1000) {
				// Sample is within the last second.
				if (s.FrameTime < min) min = s.FrameTime;
				if (s.FrameTime > max) max = s.FrameTime;
				sum += s.FrameTime;
				SampleCount++;
			}
		}

		// Compute corresponding frame rates.
		float	MinFR, MaxFR, AvgFR;
		MinFR = 1000.0f / max;
		MaxFR = 1000.0f / min;
		if (SampleCount) {
			AvgFR = (SampleCount * 1000.0f) / sum;
		}
		
		// Show the stats.
		char	buf[80];
		strcpy(buf, "fps: ");
		Text::FormatNumber(buf + strlen(buf), 1000.0f / DeltaTicks, 2, 1);	// last
		strcat(buf, "/");
		Text::FormatNumber(buf + strlen(buf), MinFR, 2, 1);	// min
		strcat(buf, "/");
		Text::FormatNumber(buf + strlen(buf), MaxFR, 2, 1);	// max
		strcat(buf, "/");
		Text::FormatNumber(buf + strlen(buf), AvgFR, 2, 1);	// avg
		
		Text::DrawString(5, 12, Text::FIXEDSYS, Text::ALIGN_LEFT, buf);

		// Show a scrolling bar graph of frame rate.
		GUIBegin();//xxxx
		for (i = 0; i < FT_SAMPLES; i++) {
			FrameTimeSample&	s = FrameTimeQueue[(NextFTSample + i) % FT_SAMPLES];
			float	height = 0;
			if (s.FrameTime) height = (1000.0f / s.FrameTime) / 240.0f;
			glColor3f(1, 0.25f, 0.25f);
			glBegin(GL_QUADS);
			glVertex2f((i-320)/320.0f, 180/240.0f + 0);
			glVertex2f((i-320+1)/320.0f, 180/240.0f + 0);
			glVertex2f((i-320+1)/320.0f, 180/240.0f + height);
			glVertex2f((i-320)/320.0f, 180/240.0f + height);
			glEnd();
		}
		GUIEnd();//xxxx
		
	}

	// Show some other miscellaneous info, if desired.
	if (Config::GetBoolValue("ShowRenderStats")) {
		char	buf[1000];
		sprintf(buf, "Model:\n texels: %dK\n tris: %d\n"
			"Terrain:\n tris: %d\n active nodes: %d\n total nodes: %d\n nudge: %g\n"
			" cache:\n  texels: %dK\n  active nodes = %d\n  nodes built = %d\n  thrash ct = %d"
			,
			Model::GetTexelCount() / 1024,
			Model::GetRenderedTriangleCount(),
			TerrainMesh::GetRenderedTriangleCount(),
			TerrainMesh::GetNodesActiveCount(),
			TerrainMesh::GetNodesTotalCount(),
			TerrainMesh::GetDetailNudge(),
			Surface::GetTexelCount() / 1024,
			Surface::GetActiveNodeCount(),
			Surface::GetNodesBuilt(),
			Surface::GetThrashCount()
		       );
		Text::DrawMultiLineString(5, 24, Text::FIXEDSYS, Text::ALIGN_LEFT, 640, buf);
	}

	// Show viewer location.
	if (Config::GetBoolValue("ShowViewerLocation") && Viewer) {
		char	buf[80];
		Text::FontID	f = Text::FIXEDSYS;

		vec3	v = ViewerLoc;
		
		int	y = 400;
		int	dy = Text::GetFontHeight(f);
		Text::FormatNumber(buf, v.X() + 32768, 4, 1);
		Text::DrawString(20, y, f, Text::ALIGN_LEFT, buf, 0xFF000000);
		y += dy;
		Text::FormatNumber(buf, v.Y(), 4, 1);
		Text::DrawString(20, y, f, Text::ALIGN_LEFT, buf, 0xFF000000);
		y += dy;
		Text::FormatNumber(buf, v.Z() + 32768, 4, 1);
		Text::DrawString(20, y, f, Text::ALIGN_LEFT, buf, 0xFF000000);
		y += dy;
	}
		
	
//	// Log user speed xxxxxx
//	{
//		char	buf[80];
//		float	speed = 0;
//		MDynamic*	d = Game::GetUser();
//		if (d) speed = d->GetVelocity().magnitude();
//		Text::FormatNumber(buf, speed * 2.2369, 3, 1);
//		Text::DrawString(40, 400, Text::DEFAULT, Text::ALIGN_LEFT, buf);
//	}
//	// xxxxxxxx

	Overlay::Render();
	
	if (Config::GetValue("RecordMoviePath")) SaveMovieFrame();

	const char*	fn = Config::GetValue("SaveFramePPM");
	if (fn) {
		Render::WriteScreenshotFilePPM(fn);
		Config::SetValue("SaveFramePPM", NULL);
	}
	
	} // end of two player display
	
	Render::ShowFrame();

	//xxxxxxx
	Config::SetBoolValue("F4Pressed", false);
}
ENTRYPOINT void init_blocktube (ModeInfo *mi)
{
    int loop;
    GLfloat fogColor[4] = {0,0,0,1};
    blocktube_configuration *lp;
    int wire = MI_IS_WIREFRAME(mi);

    if (!lps) {
        lps = (blocktube_configuration *)
              calloc (MI_NUM_SCREENS(mi), sizeof (blocktube_configuration));
        if (!lps) {
            fprintf(stderr, "%s: out of memory\n", progname);
            exit(1);
        }
        lp = &lps[MI_SCREEN(mi)];
    }

    lp = &lps[MI_SCREEN(mi)];
    lp->glx_context = init_GL(mi);

    lp->zoom = 30;
    lp->tilt = 4.5;
    lp->tunnelLength = 200;
    lp->tunnelWidth = 5;

    if (wire) {
        do_fog = False;
        do_texture = False;
        glLineWidth(2);
    }

    lp->block_dlist = glGenLists (1);
    glNewList (lp->block_dlist, GL_COMPILE);
    lp->polys = cube_vertices(0.15, 1.2, 5.25, wire);
    glEndList ();

#if defined( I_HAVE_XPM )
    if (do_texture) {
        if (!LoadGLTextures(mi)) {
            fprintf(stderr, "%s: can't load textures!\n", progname);
            exit(1);
        }
        glEnable(GL_TEXTURE_2D);
    }
#endif

    /* kick on the fog machine */
    if (do_fog) {
        glEnable(GL_FOG);
        glFogi(GL_FOG_MODE, GL_LINEAR);
        glHint(GL_FOG_HINT, GL_NICEST);
        glFogf(GL_FOG_START, 0);
        glFogf(GL_FOG_END, lp->tunnelLength/1.8);
        glFogfv(GL_FOG_COLOR, fogColor);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    }
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);

    if (!do_texture && !wire) {
        /* If there is no texture, the boxes don't show up without a light.
           Though I don't understand why all the blocks come out gray.
         */
        GLfloat pos[4] = {0.0, 1.0, 1.0, 0.0};
        GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
        GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
        GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
        glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
        glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
    }

    lp->counter = holdtime;
    lp->currentR = random() % 256;
    lp->currentG = random() % 256;
    lp->currentB = random() % 256;
    newTargetColor(lp);
    for (loop = 0; loop < MAX_ENTITIES; loop++)
    {
        randomize_entity(lp, &lp->entities[loop]);
    }
    reshape_blocktube(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    glFlush();
}
Exemple #6
0
/*=================== Main Initialization ==================================*/
static void Init(ModeInfo * mi)
{
  	atunnelstruct *sa = &Atunnel[MI_SCREEN(mi)];
	GLfloat light_ambient[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat light_position[] = {0.0, 0.0, 1.0, 0.0};
	GLfloat fogColor[4] = {0.8, 0.8, 0.8, 1.0};

  	glClearColor(0, 0, 0, 0);
	if (do_texture)
	{
		glGenTextures(MAX_TEXTURE, sa->texture);
		LoadTexture(mi, texture0,0);
		LoadTexture(mi, texture1,1);
		LoadTexture(mi, texture2,2);
		LoadTexture(mi, texture3,3);
		LoadTexture(mi, texture4,4);
		LoadTexture(mi, texture5,5);
		glEnable(GL_TEXTURE_2D);
	}
	sa->ts = InitTunnel();
	
	/* Set lighting parameters */
	if (do_light)
	{
		glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
		glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
		glLightfv(GL_LIGHT0, GL_POSITION, light_position);

		/* Enable light 0 */
		glEnable(GL_LIGHT0);
		glDepthFunc(GL_LESS);
	
		glEnable(GL_LIGHTING);
	}
  	if (do_wire) {
		glDisable(GL_NORMALIZE);
		glDisable(GL_CULL_FACE);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_TEXTURE_2D);
		glPolygonMode(GL_FRONT,GL_LINE);
  		glPolygonMode(GL_BACK,GL_LINE);
  	}
	else
	{
		glEnable(GL_DEPTH_TEST);
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

		/* Enable fog */
		glFogi(GL_FOG_MODE, GL_EXP);
		glFogfv(GL_FOG_COLOR, fogColor);
		glFogf(GL_FOG_DENSITY, 0.3);
		glEnable(GL_FOG);
	
		/* Cull face */
		glCullFace(GL_FRONT);
		glEnable(GL_CULL_FACE);
	}
	
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
Exemple #7
0
void OGLRender::Initialize(void)
{
    glMatrixMode(GL_MODELVIEW);
    OPENGL_CHECK_ERRORS;
    glLoadIdentity();
    OPENGL_CHECK_ERRORS;

    glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight);
    OPENGL_CHECK_ERRORS;

    COGLGraphicsContext *pcontext = (COGLGraphicsContext *)(CGraphicsContext::g_pGraphicsContext);
    if( pcontext->IsExtensionSupported("GL_IBM_texture_mirrored_repeat") )
    {
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_IBM;
    }
    else if( pcontext->IsExtensionSupported("ARB_texture_mirrored_repeat") )
    {
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_MIRRORED_REPEAT_ARB;
    }
    else
    {
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_MIRROR].realFlag = GL_REPEAT;
    }

    if( pcontext->IsExtensionSupported("GL_ARB_texture_border_clamp") || pcontext->IsExtensionSupported("GL_EXT_texture_edge_clamp") )
    {
        m_bSupportClampToEdge = true;
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP_TO_EDGE;
    }
    else
    {
        m_bSupportClampToEdge = false;
        OGLXUVFlagMaps[TEXTURE_UV_FLAG_CLAMP].realFlag = GL_CLAMP;
    }

    glVertexPointer( 4, GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][0]) );
    OPENGL_CHECK_ERRORS;
    glEnableClientState( GL_VERTEX_ARRAY );
    OPENGL_CHECK_ERRORS;

    if( m_bMultiTexture )
    {
        pglClientActiveTextureARB( GL_TEXTURE0_ARB );
        OPENGL_CHECK_ERRORS;
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        OPENGL_CHECK_ERRORS;

        pglClientActiveTextureARB( GL_TEXTURE1_ARB );
        OPENGL_CHECK_ERRORS;
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[1].u) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        OPENGL_CHECK_ERRORS;
    }
    else
    {
        glTexCoordPointer( 2, GL_FLOAT, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        OPENGL_CHECK_ERRORS;
    }

    if (m_bSupportFogCoordExt)
    {
        pglFogCoordPointerEXT( GL_FLOAT, sizeof(float)*5, &(g_vtxProjected5[0][4]) );
        OPENGL_CHECK_ERRORS;
        glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
        OPENGL_CHECK_ERRORS;
        glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
        OPENGL_CHECK_ERRORS;
        glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode
        OPENGL_CHECK_ERRORS;
        glFogf(GL_FOG_DENSITY, 1.0f); // How Dense Will The Fog Be
        OPENGL_CHECK_ERRORS;
        glHint(GL_FOG_HINT, GL_FASTEST); // Fog Hint Value
        OPENGL_CHECK_ERRORS;
        glFogi( GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT );
        OPENGL_CHECK_ERRORS;
        glFogf( GL_FOG_START, 0.0f );
        OPENGL_CHECK_ERRORS;
        glFogf( GL_FOG_END, 1.0f );
        OPENGL_CHECK_ERRORS;
    }

    //glColorPointer( 1, GL_UNSIGNED_BYTE, sizeof(TLITVERTEX), &g_vtxBuffer[0].r);
    glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
    OPENGL_CHECK_ERRORS;
    glEnableClientState( GL_COLOR_ARRAY );
    OPENGL_CHECK_ERRORS;

    if( pcontext->IsExtensionSupported("GL_NV_depth_clamp") )
    {
        glEnable(GL_DEPTH_CLAMP_NV);
        OPENGL_CHECK_ERRORS;
    }

}
Exemple #8
0
/*
=================
R_Fog (void)
=================
*/
void RB_Fog( glfog_t *curfog )
{
//	static glfog_t  setfog;

	GLimp_LogComment( "--- RB_Fog() ---\n" );

#if 0

	if ( !r_wolfFog->integer )
	{
		RB_FogOff();
		return;
	}

	if ( !curfog->registered )
	{
		//----(SA)
		RB_FogOff();
		return;
	}

	//----(SA) assume values of '0' for these parameters means 'use default'
	if ( !curfog->density )
	{
		curfog->density = 1;
	}

	if ( !curfog->hint )
	{
		curfog->hint = GL_DONT_CARE;
	}

	if ( !curfog->mode )
	{
		curfog->mode = GL_LINEAR;
	}

	//----(SA)  end

	RB_FogOn();

	// only send changes if necessary

//  if(curfog->mode != setfog.mode || !setfog.registered) {
	glFogi( GL_FOG_MODE, curfog->mode );
//      setfog.mode = curfog->mode;
//  }
//  if(curfog->color[0] != setfog.color[0] || curfog->color[1] != setfog.color[1] || curfog->color[2] != setfog.color[2] || !setfog.registered) {
	glFogfv( GL_FOG_COLOR, curfog->color );
//      VectorCopy(setfog.color, curfog->color);
//  }
//  if(curfog->density != setfog.density || !setfog.registered) {
	glFogf( GL_FOG_DENSITY, curfog->density );
//      setfog.density = curfog->density;
//  }
//  if(curfog->hint != setfog.hint || !setfog.registered) {
	glHint( GL_FOG_HINT, curfog->hint );
//      setfog.hint = curfog->hint;
//  }
//  if(curfog->start != setfog.start || !setfog.registered) {
	glFogf( GL_FOG_START, curfog->start );
//      setfog.start = curfog->start;
//  }

	if ( r_zfar->value )
	{
		// (SA) allow override for helping level designers test fog distances
//      if(setfog.end != r_zfar->value || !setfog.registered) {
		glFogf( GL_FOG_END, r_zfar->value );
//          setfog.end = r_zfar->value;
//      }
	}
	else
	{
//      if(curfog->end != setfog.end || !setfog.registered) {
		glFogf( GL_FOG_END, curfog->end );
//          setfog.end = curfog->end;
//      }
	}

// TTimo - from SP NV fog code
	// NV fog mode
	if ( glConfig.NVFogAvailable )
	{
		glFogi( GL_FOG_DISTANCE_MODE_NV, glConfig.NVFogMode );
	}

// end

	setfog.registered = qtrue;

	GL_ClearColor( curfog->color[ 0 ], curfog->color[ 1 ], curfog->color[ 2 ], curfog->color[ 3 ] );
#endif
}
Exemple #9
0
GLvoid CFog::SetDensity( GLfloat density )
{
	glFogf( GL_FOG_DENSITY, density );
}
Exemple #10
0
int
grInitScene(void)
{
    void		*hndl = grTrackHandle;
    ssgLight *          light = ssgGetLight(0);

    GLfloat mat_specular[]   = {0.3, 0.3, 0.3, 1.0};
    GLfloat mat_shininess[]  = {50.0};
    GLfloat light_position[] = {0, 0, 200, 0.0};
    GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0};
    GLfloat lmodel_diffuse[] = {0.8, 0.8, 0.8, 1.0};
    GLfloat fog_clr[]        = {1.0, 1.0, 1.0, 0.5};

    if (grHandle==NULL) {
	sprintf(buf, "%s%s", GetLocalDir(), GR_PARAM_FILE);
	grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
    }

    mat_specular[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SPEC_R, NULL, mat_specular[0]);
    mat_specular[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SPEC_G, NULL, mat_specular[1]);
    mat_specular[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SPEC_B, NULL, mat_specular[2]);

    lmodel_ambient[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_AMBIENT_R, NULL, lmodel_ambient[0]);
    lmodel_ambient[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_AMBIENT_G, NULL, lmodel_ambient[1]);
    lmodel_ambient[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_AMBIENT_B, NULL, lmodel_ambient[2]);

    lmodel_diffuse[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_DIFFUSE_R, NULL, lmodel_diffuse[0]);
    lmodel_diffuse[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_DIFFUSE_G, NULL, lmodel_diffuse[1]);
    lmodel_diffuse[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_DIFFUSE_B, NULL, lmodel_diffuse[2]);

    mat_shininess[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_SHIN, NULL, mat_shininess[0]);

    light_position[0] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_LIPOS_X, NULL, light_position[0]);
    light_position[1] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_LIPOS_Y, NULL, light_position[1]);
    light_position[2] = GfParmGetNum(hndl, TRK_SECT_GRAPH, TRK_ATT_LIPOS_Z, NULL, light_position[2]);

    glShadeModel(GL_SMOOTH);

    light->setPosition(light_position[0],light_position[1],light_position[2]);
    light->setColour(GL_AMBIENT,lmodel_ambient);
    light->setColour(GL_DIFFUSE,lmodel_diffuse);
    light->setColour(GL_SPECULAR,mat_specular);
    light->setSpotAttenuation(0.0, 0.0, 0.0);

    sgCopyVec3 (fog_clr,  grTrack->graphic.bgColor);
    sgScaleVec3 (fog_clr, 0.8);
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glFogfv(GL_FOG_COLOR, fog_clr);
    glFogf(GL_FOG_DENSITY, 0.05);
    glHint(GL_FOG_HINT, GL_DONT_CARE);
    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    if (!sun) {
	ssgaLensFlare      *sun_obj      = NULL ;
	sun_obj  = new ssgaLensFlare () ;
	sun      = new ssgTransform ;
	sun      -> setTransform    ( light_position ) ;
	sun      -> addKid          ( sun_obj  ) ;
	SunAnchor-> addKid(sun) ;
    }

    /* GUIONS GL_TRUE */
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);

#ifdef GL_SEPARATE_SPECULAR_COLOR 
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
#else
#ifdef GL_SEPARATE_SPECULAR_COLOR_EXT
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT,GL_SEPARATE_SPECULAR_COLOR_EXT);
#endif
#endif

    return 0;
}
Exemple #11
0
bool r_init(uint *vcounter, uint *tcounter,
					uint *dpcounter, uint *cpcounter) {
	float fogcolour[] = {0, 0, 0, 1};

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);

	if (!(r_screen = SDL_SetVideoMode(m_screen_width, m_screen_height,
		24, SDL_OPENGL | (m_full_screen ? SDL_FULLSCREEN : 0)))) {
		fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
		return false;
	}

	if (!vcounter || !tcounter || !dpcounter || !cpcounter)
		return false;

	r_vert_counter = vcounter;
	r_tri_counter = tcounter;
	r_visible_patch_counter = dpcounter;
	r_culled_patch_counter = cpcounter;

	SDL_WM_SetCaption("AC-130", "AC-130");

	// initialize the extension wrangler
	glewInit();
	// check for required features
	if (!GLEW_EXT_framebuffer_object) {
		fprintf(stderr, "Hardware does not support frame buffer objects\n");
		return false;
	}
	if (!GLEW_ARB_vertex_buffer_object) {
		fprintf(stderr, "Hardware does not support vertex buffer objects\n");
		return false;
	}
	if (!GLEW_ARB_multitexture) {
		fprintf(stderr, "Hardware does not support multitexturing\n");
		return false;
	}
	if (!GLEW_ARB_vertex_shader) {
		fprintf(stderr, "Hardware does not support vertex shaders\n");
		return false;
	}
	if (!GLEW_ARB_fragment_shader) {
		fprintf(stderr, "Hardware does not support fragment shaders\n");
		return false;
	}

	// all geometry uses vertex and index arrays
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	// initialize matrices
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	// set face culling
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f(1, 1, 1, 1);

	// set up fog
	glFogi(GL_FOG_MODE, GL_EXP2);
	glFogfv(GL_FOG_COLOR, fogcolour);
	glFogf(GL_FOG_DENSITY, 0.002);

	// set line smoothing
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

	// initialize FBO
	if (!r_init_FBO())
		return false;

	// initialize shaders
	if (!r_create_shaders())
		return false;

	// generate resources
	r_create_terrain();
	r_create_props();
	r_create_fx();
	r_create_font();
	r_create_footmobile();

	return true;
}
Exemple #12
0
/* general OpenGL initialization function */
int SDLScreen::InitGL( GLvoid )
{
	if ( !m_kScreen )
	{
		return false;
	}

	glClearColor( 0.0, 0.0, 0.0, 1.0 );
	glEnable( GL_CULL_FACE );

	glClearDepth( 1.0 );           // Enables Clearing Of The Depth Buffer
	glDepthFunc( GL_LESS );        // The Type Of Depth Test To Do
	glEnable( GL_DEPTH_TEST );     // Enables Depth Testing
	glShadeModel( GL_SMOOTH );     // Enables Smooth Color Shading
  
	glMatrixMode( GL_PROJECTION );
	glEnable( GL_TEXTURE_2D );

/*
	glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
	glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );
	glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient );
	glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse );

	glLightfv( GL_LIGHT0, GL_AMBIENT, LightAmbient );

	glLightfv( GL_LIGHT1, GL_DIFFUSE, LightDiffuse );

	glLightfv( GL_LIGHT0, GL_POSITION, LightPosition );
	glLightfv( GL_LIGHT1, GL_SPOT_DIRECTION, LightPosition );
	glLightfv( GL_LIGHT0, GL_POSITION, LightPosition );
	glEnable( GL_LIGHTING );
	glEnable( GL_LIGHT0 );
	glEnable( GL_LIGHT1 );
*/

	GLuint fogMode[] = { GL_EXP, GL_EXP2, GL_LINEAR }; // Storage For Three Types Of Fog
	GLuint fogfilter = 2; // Which Fog To Use
//  GLfloat fogColor[4] = { 53.0f / 255.0f, 66.0f / 255.0f, 98.0f / 255.0f , 1.0f }; // skybox
//	GLfloat fogColor[4] = { 168.0f / 255.0f, 168.0f / 255.0f, 180.0f / 255.0f , 1.0f }; // skybox
//	glClearColor( 0.5f, 0.5f, 0.5f, 1.0f ); // We'll Clear To The Color Of The Fog
	glFogi( GL_FOG_MODE, fogMode[fogfilter] ); // Fog Mode
// glFogfv( GL_FOG_COLOR, fogColor ); // Set Fog Color
	glFogf( GL_FOG_DENSITY, 0.45f ); // 0.35f How Dense Will The Fog Be
	glHint( GL_FOG_HINT, GL_DONT_CARE ); // Fog Hint Value
	glEnable( GL_FOG );

	glMatrixMode( GL_MODELVIEW );
	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glEnable( GL_BLEND );

	// glEnableClientState( GL_VERTEX_ARRAY );
	// glEnableClientState( GL_TEXTURE_COORD_ARRAY );
	// glEnableClientState( GL_NORMAL_ARRAY );

	glAlphaFunc( GL_GREATER, 0.9 );
	glEnable( GL_ALPHA_TEST );

	return true;
}
Exemple #13
0
void myMenu(int id)
{
		if (id==1)
	{
		flag1=0;
		wheelflag=0;
	glutPostRedisplay();

	}
	if(id ==2)
	{
		flag1=1;
		flag2=0;
		wheelflag=0;
		xangle += 5.0;
		glutPostRedisplay();
	}
	if(id==3)
	{
		flag2=1;
		wheelflag=0;
		xangle += 5.0;
		glutPostRedisplay();
	}
	if (id==4)
	{
		 wheelflag=1;
		 glutPostRedisplay();
	}
	if (id==5)
	{
               if(day)
                {

		if(light)
		{
			count++;
			glDisable(GL_LIGHTING);
			glDisable(GL_LIGHT0);
			light=0;
		}
		else
		{
			count--;
			light=1;
			glEnable(GL_LIGHTING);
			glEnable(GL_LIGHT0);
		}
		glutPostRedisplay();
                }
               else
                {

                  if(nml==0 && flag2==2)
                     {
                       flag2=0;
                       nml=1;
                     }
                   else
                     {
                         flag2=2;
                 nml=0;

                 aflag=0;
                 day=0;

	         glClearColor(0.1,0.1,0.1,0);
	         GLfloat fogcolour[4]={0.0,0.0,0.0,1.0};

                 glFogfv(GL_FOG_COLOR,fogcolour);              /* Define the fog colour */
                 glFogf(GL_FOG_DENSITY,0.5);                   /* How dense */
                 glFogi(GL_FOG_MODE,GL_EXP);                   /* exponential decay */
                         /* end */
                glHint(GL_FOG_HINT, GL_FASTEST);              /* compute per vertex */
                glEnable(GL_FOG);


	        glutPostRedisplay();
                 }
             }

	}


       if(id==12)
	{
	aflag=1;
        day=1;
	glClearColor(1,1,1,1);
	glDisable(GL_FOG);
	glutPostRedisplay();
	}

	if(id==13)
	{
	aflag=0;
        day=0;
	flag2=2;
	glClearColor(0.1,0.1,0.1,0);
	GLfloat fogcolour[4]={0.0,0.0,0.0,1.0};

  glFogfv(GL_FOG_COLOR,fogcolour);              /* Define the fog colour */
  glFogf(GL_FOG_DENSITY,0.5);                   /* How dense */
  glFogi(GL_FOG_MODE,GL_EXP);                   /* exponential decay */
                         /* end */
  glHint(GL_FOG_HINT, GL_FASTEST);              /* compute per vertex */
  glEnable(GL_FOG);

  glutPostRedisplay();
       }
}
Exemple #14
0
GLvoid DrawGLScene()
{


  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	/* Clear The Screen And The Depth Buffer */
if(view==0)
{
init();
display1();
}
else
{
  if(count==1)
	InitGL(Xsize,Ysize);
  if(aflag==1)/* Initialize our window. */
  glClearColor(1,1,1,1);
  else
	  glClearColor(0.1,0.1,0.1,0);
  glPushMatrix();
  glLoadIdentity();
  glTranslatef(-1.0,0.0,-3.5);
  glRotatef(xangle,1.0,0.0,0.0);
  glRotatef(yangle,0.0,1.0,0.0);
  glRotatef(zangle,0.0,0.0,1.0);
  glTranslatef(xt,yt,zt);
  glScalef(xs,ys,zs);
  glEnable(GL_COLOR_MATERIAL);
  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

  if(flag2==1)
  {
  GLfloat fogcolour[4]={1.0,1.0,1.0,1.0};

  glFogfv(GL_FOG_COLOR,fogcolour);              /* Define the fog colour */
  glFogf(GL_FOG_DENSITY,0.1);                   /* How dense */
  glFogi(GL_FOG_MODE,GL_EXP);                   /* exponential decay */
  glFogf(GL_FOG_START,3.0);                   /* Where wwe start fogging */
  glFogf(GL_FOG_END,100.0);                       /* end */
  glHint(GL_FOG_HINT, GL_FASTEST);              /* compute per vertex */
  glEnable(GL_FOG);/* ENABLE */
  }
  if(flag2==0)
  {
	  glDisable(GL_FOG);
  }

if(!aflag){
  glBegin(GL_POINTS);
  glColor3f(1,1,1);
  glPointSize(200.0);
  int ccount=0;
  float x=10,y=10;
  while(ccount<20)
  {
	  glVertex2f(x,y);
	  x+=10;
	  y+=10;
	  if(y>Ysize) y-=10;
	  if(x>Xsize) x-=10;
	  ccount++;
  }
  glEnd();}

  glColor3f(1.0,.75,0.0);
  glPointSize(30.0);
  glBegin(GL_POINTS);
  glVertex3f(0.2,0.3,0.3);
  glVertex3f(0.2,0.3,0.5);
  glEnd();
  glPointSize(200.0);



  glBegin(GL_QUADS);                /* OBJECT MODULE*/

  /* top of cube*/
  //************************FRONT BODY****************************************
  glColor3f(r,g,b);
  glVertex3f( 0.2, 0.4,0.6);
  glVertex3f(0.6, 0.5,0.6);
  glVertex3f(0.6, 0.5,0.2);
  glVertex3f( 0.2,0.4,0.2);

  /* bottom of cube*/
  glVertex3f( 0.2,0.2,0.6);
  glVertex3f(0.6,0.2,0.6);
  glVertex3f(0.6,0.2,0.2);
  glVertex3f( 0.2,0.2,0.2);

  /* front of cube*/
  glVertex3f( 0.2,0.2,0.6);
  glVertex3f(0.2, 0.4,0.6);
  glVertex3f(0.2,0.4,0.2);
  glVertex3f( 0.2,0.2,0.2);

  /* back of cube.*/
  glVertex3f(0.6,0.2,0.6);
  glVertex3f(0.6,0.5,0.6);
  glVertex3f(0.6,0.5,0.2);
  glVertex3f( 0.6,0.2,0.2);

  /* left of cube*/
  glVertex3f(0.2,0.2,0.6);
  glVertex3f(0.6,0.2,0.6);
  glVertex3f(0.6,0.5,0.6);
  glVertex3f(0.2,0.4,0.6);

  /* Right of cube */
  glVertex3f(0.2,0.2,0.2);
  glVertex3f( 0.6,0.2,0.2);
  glVertex3f( 0.6,0.5,0.2);
  glVertex3f( 0.2,0.4,0.2);
//****************************************************************************
  glVertex3f(0.7,0.65,0.6);
  glVertex3f(0.7,0.65,0.2);
  glVertex3f(1.7,0.65,0.2);        //top cover
  glVertex3f(1.7,0.65,0.6);
//***************************back guard******************************
  glColor3f(r,g,b);            /* Set The Color To Blue*/
  glVertex3f( 1.8, 0.5,0.6);
  glVertex3f(1.8, 0.5,0.2);
  glVertex3f(2.1, 0.4, 0.2);
  glVertex3f(2.1,0.4,0.6);

  /* bottom of cube*/
  glVertex3f( 2.1,0.2,0.6);
  glVertex3f(2.1,0.2,0.2);
  glVertex3f(1.8,0.2,0.6);
  glVertex3f( 1.8,0.2,0.6);

  /* back of cube.*/
  glVertex3f(2.1,0.4,0.6);
  glVertex3f(2.1,0.4,0.2);
  glVertex3f(2.1,0.2,0.2);
  glVertex3f(2.1,0.2,0.6);

  /* left of cube*/
  glVertex3f(1.8,0.2,0.2);
  glVertex3f(1.8,0.5,0.2);
  glVertex3f(2.1,0.4,0.2);
  glVertex3f(2.1,0.2,0.2);

  /* Right of cube */
  glVertex3f(1.8,0.2,0.6);
  glVertex3f(1.8,0.5,0.6);
  glVertex3f(2.1,0.4,0.6);
  glVertex3f(2.1,0.2,0.6);
//******************MIDDLE BODY************************************
  glVertex3f( 0.6, 0.5,0.6);
  glVertex3f(0.6, 0.2,0.6);
  glVertex3f(1.8, 0.2, 0.6);
  glVertex3f(1.8,0.5,0.6);

  /* bottom of cube*/
  glVertex3f( 0.6,0.2,0.6);
  glVertex3f(0.6,0.2,0.2);
  glVertex3f(1.8,0.2,0.2);
  glVertex3f( 1.8,0.2,0.6);

  /* back of cube.*/
  glVertex3f(0.6,0.5,0.2);
  glVertex3f(0.6,0.2,0.2);
  glVertex3f(1.8,0.2,0.2);
  glVertex3f(1.8,0.5,0.2);
//*********************ENTER WINDOW**********************************
  glColor3f(0.3,0.3,0.3);
  glVertex3f( 0.77, 0.63,0.2);
  glVertex3f(0.75, 0.5,0.2);        //quad front window
  glVertex3f(1.2, 0.5, 0.2);
  glVertex3f( 1.22,0.63,0.2);

  glVertex3f(1.27,0.63,.2);
  glVertex3f(1.25,0.5,0.2);        //quad back window
  glVertex3f(1.65,0.5,0.2);
  glVertex3f(1.67,0.63,0.2);

  glColor3f(r,g,b);
  glVertex3f(0.7,0.65,0.2);
  glVertex3f(0.7,0.5,.2);       //first separation
  glVertex3f(0.75,0.5,0.2);
  glVertex3f(0.77,0.65,0.2);

  glVertex3f(1.2,0.65,0.2);
  glVertex3f(1.2,0.5,.2);       //second separation
  glVertex3f(1.25,0.5,0.2);
  glVertex3f(1.27,0.65,0.2);

  glVertex3f(1.65,0.65,0.2);
  glVertex3f(1.65,0.5,.2);     //3d separation
  glVertex3f(1.7,0.5,0.2);
  glVertex3f(1.7,0.65,0.2);

  glVertex3f( 0.75, 0.65,0.2);
  glVertex3f(0.75, 0.63,0.2);        //line strip
  glVertex3f(1.7, 0.63, 0.2);
  glVertex3f( 1.7,0.65,0.2);

  glVertex3f( 0.75, 0.65,0.6);
  glVertex3f(0.75, 0.63,0.6);        //line strip
  glVertex3f(1.7, 0.63, 0.6);
  glVertex3f( 1.7,0.65,0.6);

  glColor3f(0.3,0.3,0.3);
  glVertex3f( 0.77, 0.63,0.6);
  glVertex3f(0.75, 0.5,0.6);        //quad front window
  glVertex3f(1.2, 0.5, 0.6);
  glVertex3f( 1.22,0.63,0.6);

  glVertex3f(1.27,0.63,.6);
  glVertex3f(1.25,0.5,0.6);        //quad back window
  glVertex3f(1.65,0.5,0.6);
  glVertex3f(1.67,0.63,0.6);

  glColor3f(r,g,b);
  glVertex3f(0.7,0.65,0.6);
  glVertex3f(0.7,0.5,.6);       //first separation
  glVertex3f(0.75,0.5,0.6);
  glVertex3f(0.77,0.65,0.6);

  glVertex3f(1.2,0.65,0.6);
  glVertex3f(1.2,0.5,.6);       //second separation
  glVertex3f(1.25,0.5,0.6);
  glVertex3f(1.27,0.65,0.6);

  glVertex3f(1.65,0.65,0.6);
  glVertex3f(1.65,0.5,.6);
  glVertex3f(1.7,0.5,0.6);
  glVertex3f(1.7,0.65,0.6);
  glEnd();


 //**************************************************************
  glBegin(GL_QUADS);

  /* top of cube*/
  glColor3f(0.3,0.3,0.3);
  glVertex3f( 0.6, 0.5,0.6);
  glVertex3f(0.6, 0.5,0.2);        //quad front window
  glVertex3f(0.7, 0.65, 0.2);
  glVertex3f( 0.7,0.65,0.6);

  glVertex3f(1.7,0.65,.6);
  glVertex3f(1.7,0.65,0.2);        //quad back window
  glVertex3f(1.8,0.5,0.2);
  glVertex3f(1.8,0.5,0.6);


//*****************************road and surrounding development***********************************
  if(flag1)
  {
	glPushMatrix();
	glTranslatef(xw,0,0);
  glColor3f(0,1,0);
  glVertex3f(-100,0.1,-100);
  glVertex3f(-100,0.1,0);         //a green surroundings
  glVertex3f(100,0.1,0);
  glVertex3f(100,0.1,-100);

  glColor3f(0.7,0.7,0.7);
  glVertex3f(-100,0.1,0);
  glVertex3f(-100,0.1,0.45);         //a long road
  glVertex3f(100,0.1,0.45);
  glVertex3f(100,0.1,0);

  glColor3f(1.0,0.75,0.0);
  glVertex3f(-100,0.1,0.45);       //a median
  glVertex3f(-100,0.1,0.55);
  glVertex3f(100,0.1,0.55);
  glVertex3f(100,0.1,0.45);

  glColor3f(0.7,0.7,0.7);
  glVertex3f(-100,0.1,0.55);
  glVertex3f(-100,0.1,1);         //a long road
  glVertex3f(100,0.1,1);
  glVertex3f(100,0.1,0.55);

  glColor3f(0,1,0);
  glVertex3f(-100,0.1,1);
  glVertex3f(-100,0.1,100);         //a green surroundings
  glVertex3f(100,0.1,100);
  glVertex3f(100,0.1,1);
    glPopMatrix();
  }
  glEnd();

  if(wheelflag)
  {
	  glPushMatrix();
	  glTranslatef(xw,0,0);
	  glColor3f(0.5,.2,0.3);
	  glBegin(GL_QUADS);
	  for(i=0;i<200;i+=0.2)
	  {
		  glVertex3f(-100+i,0,1);
		  glVertex3f(-99.9+i,0,1);
		  glVertex3f(-99.9+i,0.2,1);
		  glVertex3f(-100+i,0.2,1);
		  i+=0.5;
	  }
	  for(i=0;i<200;i+=0.2)
	  {
		  glVertex3f(-100+i,0,0);
		  glVertex3f(-99.9+i,0,0);
		  glVertex3f(-99.9+i,0.2,0);
		  glVertex3f(-100+i,0.2,0);
		  i+=0.5;
	  }
	  glEnd();
	  glPopMatrix();
  }
//*************************************************************************************************
glBegin(GL_TRIANGLES);                /* start drawing the cube.*/

  /* top of cube*/
  glColor3f(0.3,0.3,0.3);
  glVertex3f( 0.6, 0.5,0.6);
  glVertex3f( 0.7,0.65,0.6);       //tri front window
  glVertex3f(0.7,0.5,0.6);

  glVertex3f( 0.6, 0.5,0.2);
  glVertex3f( 0.7,0.65,0.2);       //tri front window
  glVertex3f(0.7,0.5,0.2);

  glVertex3f( 1.7, 0.65,0.2);
  glVertex3f( 1.8,0.5,0.2);       //tri back window
  glVertex3f( 1.7,0.5,0.2);

  glVertex3f( 1.7, 0.65,0.6);
  glVertex3f( 1.8,0.5,0.6);       //tri back window
  glVertex3f(1.7,0.5,0.6);

glEnd();
//************IGNITION SYSTEM**********************************
glPushMatrix();
   glColor3f(0.7,0.7,0.7);
   glTranslatef(1.65,0.2,0.3);
   glRotatef(90.0,0,1,0);
   gluCylinder(t,0.02,0.03,.5,10,10);
glPopMatrix();
//********************WHEEL*********************************************

glColor3f(0.7,0.7,0.7);
glPushMatrix();
  glBegin(GL_LINE_STRIP);
	  for(theta=0;theta<360;theta=theta+20)
	  {
  glVertex3f(0.6,0.2,0.62);
  glVertex3f(0.6+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)/180))),0.62);
	  }
glEnd();

glBegin(GL_LINE_STRIP);
	  for(theta=0;theta<360;theta=theta+20)
	  {
  glVertex3f(0.6,0.2,0.18);
  glVertex3f(0.6+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)/180))),0.18);
	  }
glEnd();

glBegin(GL_LINE_STRIP);
for(theta=0;theta<360;theta=theta+20)
	  {
  glVertex3f(1.7,0.2,0.18);
  glVertex3f(1.7+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)/180))),0.18);
	  }
glEnd();

glBegin(GL_LINE_STRIP);
for(theta=0;theta<360;theta=theta+20)
	  {
  glVertex3f(1.7,0.2,0.62);
 glVertex3f(1.7+(0.08*(cos(((theta+angle)*3.14)/180))),0.2+(0.08*(sin(((theta+angle)*3.14)/180))),0.62);
	  }
glEnd();
  glTranslatef(0.6,0.2,0.6);
  glColor3f(0,0,0);
  glutSolidTorus(0.025,0.07,10,25);

  glTranslatef(0,0,-0.4);
  glutSolidTorus(0.025,0.07,10,25);

  glTranslatef(1.1,0,0);
  glutSolidTorus(0.025,0.07,10,25);

  glTranslatef(0,0,0.4);
  glutSolidTorus(0.025,0.07,10,25);
  glPopMatrix();
//*************************************************************
  glPopMatrix();
  glEnable(GL_DEPTH_TEST);
  glutPostRedisplay();
  glutSwapBuffers();
 }
}
Exemple #15
0
void Fog::setMinDistance(float parMin)
{
	if (!m_useVolumetricFog) glFogf(GL_FOG_START, parMin);
}
Exemple #16
0
GLvoid CFog::SetStart( GLfloat start )
{
	glFogf( GL_FOG_START, start );
}
Exemple #17
0
void Fog::setMaxDistance(float parMax)
{
	if (!m_useVolumetricFog) glFogf(GL_FOG_END, parMax);
}
Exemple #18
0
GLvoid CFog::SetEnd( GLfloat end )
{
	glFogf( GL_FOG_END, end );
}
void SetupDefaultLights()
{
  GlLight *light;
  GlLight *light2;
  float fogcolor[4] = {0.75,.5,.4,1};
  ShaderProg = LoadShaderProgram("shaders/lighting1.vert","shaders/lighting1.frag");
  

   light=NewLight();
      light->ambientLight[0] =0.50f;
      light->ambientLight[1] =0.50f;
      light->ambientLight[2] =0.50f;
      light->ambientLight[3] =1.0f;
  
      light->diffuseLight[0] =1.0f;
      light->diffuseLight[1] =1.0f;
      light->diffuseLight[2] =1.0f;
      light->diffuseLight[3] =1.0f;
  
      light->specLight[0] =0.50f;
      light->specLight[1] =0.50f;
      light->specLight[2] =0.50f;
      light->specLight[3] =1.0f;
  
      light->direction[0] =1.0f;
      light->direction[1] =0.0f;
      light->direction[2] =0.0f;
      
      light->pos[0] =32.0f;
      light->pos[1] =15.0f;
      light->pos[2] =-32.0f;
      light->pos[3] =1.0f;
      light->spotEdge = 90.0f;
      light->spotAngle = 180.0f;
      light->useRot = 1;
      light->rot.x = 0;
      light->rot.y = 0;
      light->rot.z = 0;
      
      light2=NewLight();
      light2->ambientLight[0] =0.4f;
      light2->ambientLight[1] =0.4f;
      light2->ambientLight[2] =0.4f;
      light2->ambientLight[3] =1.0f;
  
      light2->diffuseLight[0] =1.0f;
      light2->diffuseLight[1] =1.0f;
      light2->diffuseLight[2] =1.0f;
      light2->diffuseLight[3] =1.0f;
  
      light2->specLight[0] =1.0f;
      light2->specLight[1] =1.0f;
      light2->specLight[2] =1.0f;
      light2->specLight[3] =1.0f;
  
      light2->direction[0] =1.0f;
      light2->direction[1] =0.0f;
      light2->direction[2] =0.0f;
      
      light2->pos[0] =32.0f;
      light2->pos[1] =590.0f;
      light2->pos[2] =-32.0f;
      light2->pos[3] =1.0f;
      light2->spotAngle =90.0f;
      light2->spotEdge = 180.0f;
      light2->useRot = 1;
      light2->rot.x = 0;
      light2->rot.y = 0;
      light2->rot.z = 180;


      
      glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION, 0.0f);
      glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION, 0.02f);
      glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION, 0.000002f);
      glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 0.001f);
      glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION, 0.02f);
      glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.000002f);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
      glEnable(GL_FOG);
      glFogfv(GL_FOG_COLOR,fogcolor);
      glFogi(GL_FOG_MODE, GL_EXP);
      glFogf(GL_FOG_DENSITY, 0.001f);
      glFogf(GL_FOG_START, 1.0f);
      glFogf(GL_FOG_END, 2000.0f);
      /*
  light=NewLight();
  light->ambientLight[0] =0.7f;
  light->ambientLight[1] =0.7f;
  light->ambientLight[2] =0.7f;
  light->ambientLight[3] =1.0f;
  
  light->diffuseLight[0] =1.0f;
  light->diffuseLight[1] =1.0f;
  light->diffuseLight[2] =1.0f;
  light->diffuseLight[3] =1.0f;
  
  light->specLight[0] =1.0f;
  light->specLight[1] =1.0f;
  light->specLight[2] =1.0f;
  light->specLight[3] =1.0f;
  
  light->direction[0] =0.0f;
  light->direction[1] =0.0f;
  light->direction[2] =1.0f;
  
  light->pos[0] =32.0f;
  light->pos[1] =15.0f;
  light->pos[2] =32.0f;
  light->pos[3] =1.0f;
  light->spotEdge = 0.0f;
  light->spotAngle = 180.0f;
  light->useRot = 1;
  light->rot.x = 0;
  light->rot.y = 0;
  light->rot.z = 180;
  
  light2=NewLight();
  light2->ambientLight[0] =0.9f;
  light2->ambientLight[1] =0.9f;
  light2->ambientLight[2] =0.9f;
  light2->ambientLight[3] =1.0f;
  
  light2->diffuseLight[0] =1.0f;
  light2->diffuseLight[1] =1.0f;
  light2->diffuseLight[2] =1.0f;
  light2->diffuseLight[3] =1.0f;
  
  light2->specLight[0] =1.0f;
  light2->specLight[1] =1.0f;
  light2->specLight[2] =1.0f;
  light2->specLight[3] =1.0f;
  
  light2->direction[0] =0.0f;
  light2->direction[1] =0.0f;
  light2->direction[2] =1.0f;
  
  light2->pos[0] =0.0f;
  light2->pos[1] =0.0f;
  light2->pos[2] =-32.0f;
  light2->pos[3] =1.0f;
  light2->spotAngle =0.0f;
  light2->spotEdge = 90.0f;
  light2->useRot = 1;
  light2->rot.x = 0;
  light2->rot.y = 0;
  light2->rot.z = 0;*/
  /*
  light=NewLight();
  light->ambientLight[0] =1.0f;
  light->ambientLight[1] =1.0f;
  light->ambientLight[2] =1.0f;
  light->ambientLight[3] =1.0f;
  
  light->diffuseLight[0] =1.0f;
  light->diffuseLight[1] =1.0f;
  light->diffuseLight[2] =1.0f;
  light->diffuseLight[3] =1.0f;
  
  light->specLight[0] =1.0f;
  light->specLight[1] =1.0f;
  light->specLight[2] =1.0f;
  light->specLight[3] =1.0f;
  
  light->direction[0] =0.0f;
  light->direction[1] =0.0f;
  light->direction[2] =1.0f;
  
  light->pos[0] =0.0f;
  light->pos[1] =0.0f;
  light->pos[2] =-32.0f;
  light->pos[3] =0.0f;
  light->spotEdge = 1.0f;
  light->spotAngle = 45.0f;
  light->useRot = 1;
  light->rot.x = 0;
  light->rot.y = 0;
  light->rot.z = 0;
  
  */
/*  glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION, 0.0f);
  glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION, 0.02f);
  glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION, 0.000002f);
  glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 0.001f);
  glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION, 0.02f);
  glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.000002f);
  glLightf(GL_LIGHT2,GL_CONSTANT_ATTENUATION, 0.001f);
  glLightf(GL_LIGHT2,GL_LINEAR_ATTENUATION, 0.02f);
  glLightf(GL_LIGHT2,GL_QUADRATIC_ATTENUATION, 0.000002f);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
//  glEnable(GL_LIGHT2);
  glEnable(GL_FOG);
  glFogfv(GL_FOG_COLOR,fogcolor);
  glFogi(GL_FOG_MODE, GL_EXP);
  glFogf(GL_FOG_DENSITY, 0.001f);
  glFogf(GL_FOG_START, 0.8f);
  glFogf(GL_FOG_END, 2000.0f);*/

}
bool RoverRenderable::render()
{
	bool ret1 = true, ret2 = true, ret3 = true, 
	  ret4 = true, ret5 = true, ret6 = true, ret7 = true;

	// set up the fog function for depth cueing
	if (m_EnableDepthCue) { 
		glFogfv(GL_FOG_COLOR,m_DepthCueColor);
		glFogf(GL_FOG_DENSITY,0.0001f);
		glFogi(GL_FOG_MODE,GL_LINEAR);
		glFogf(GL_FOG_START,-3.); // 6.0 ~ the center of the bounding cube
		glFogf(GL_FOG_END,6.);
		glHint(GL_FOG_HINT, GL_FASTEST);
		glEnable(GL_FOG);
	}
	else {
		glDisable(GL_FOG);
	}
	
	// render the items
	glPushAttrib(GL_DEPTH_BUFFER_BIT);
	if (m_OpaqueRenderable) {
		glEnable(GL_DEPTH_TEST);
		ret1 = m_OpaqueRenderable->render();
	}
	if (m_EnableGeometryRendering) {
		glEnable(GL_DEPTH_TEST);
		ret2 = m_GeometryRenderer.render();
	}
	if (m_EnableIsocontourRendering) {
		glEnable(GL_DEPTH_TEST);
		ret3 = m_MultiContour.render();
	}
	
#ifdef VOLUMEGRIDROVER
	if(m_EnableSliceRendering) {
	  glEnable(GL_DEPTH_TEST);
		ret4 = m_SliceRenderable.render();
	}
#endif

#ifdef USING_SKELETONIZATION
	if(m_EnableSkeletonRendering) {
	  glEnable(GL_DEPTH_TEST);
	  ret5 = m_SkeletonRenderable.render();
	}
#endif

	if (m_EnableVolumeRendering && m_VolumeRenderer) {
	//	Need to Check - CHA
/*
  		GLdouble modelview[16], inverse[16];
  		// get the modelview matrix
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
		// invert it
		m4_inverse(inverse, modelview);
		// multiply and set the light and view vectors
		mv_mult(inverse, lightvec, scratch);
		normalize(scratch);
		m_VolumeRenderer->setLight(scratch);
		mv_mult(inverse, viewvec, scratch);
		normalize(scratch);
		m_VolumeRenderer->setView(scratch);
*/		
		ret6 = m_VolumeRenderer->renderVolume();
	}
	if (m_SuperOpaqueRenderable) {
		glDisable(GL_DEPTH_TEST);
		ret7 = m_SuperOpaqueRenderable->render();
	}
	glPopAttrib();

	// FPS computation
	{
	  static unsigned int fpsCounter_ = 0;
	  static float f_p_s_ = 0.0;
	  static double newtime=0.0,oldtime=0.0;

	  const unsigned int maxCounter = 50;
	  if (++fpsCounter_ == maxCounter)
	    {
	      newtime = getTime();
	      f_p_s_ = maxCounter / (newtime-oldtime);
	      //fpsString_ = QString("%1Hz").arg(f_p_s_, 0, 'f', ((f_p_s_ < 10.0)?1:0));
	      printf("%fHz\n",f_p_s_);
	      fpsCounter_ = 0;
	      oldtime = newtime;
	    }
	}
	  
	return ret1 && ret2 && ret3 && ret4 && ret5 && ret6 && ret7;
}
Exemple #21
0
void TScene::SetDefaultOpenGL(void)
{
	LogText("Set Default OpenGL");

	float mat_ambient[4] = { 0.4f, 0.2f, 0.2f, 1.0f };
	float mat_diffuse[4] = { 0.5f, 0.2f, 0.2f, 1.0f };
//	float mat_specular[4]= { 1.0f, 1.0f, 1.0f, 1.0f };
	float mat_specular[4]= { 0.0f, 0.0f, 0.0f, 0.0f };

	//Параметры источника света
	float light_position[4]={2.0f,0.0f,2.0f,0.0f};
	float light_intensity[4]={1.0f,1.0f,1.0f,1.0f};
	
	glMaterialf(GL_FRONT,GL_SHININESS,25.0);

	glLightfv(GL_LIGHT0,GL_AMBIENT, light_intensity);
	glLightfv(GL_LIGHT0,GL_SPECULAR,light_intensity);
	glLightfv(GL_LIGHT0,GL_DIFFUSE, light_intensity);
	glLightfv(GL_LIGHT0,GL_POSITION,light_position);

	glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
	glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);

	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	//Начальные установки
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glClearDepth(1.0);
	glewInit();
	
	int VSync = GetPrivateProfileInt("Options", "VSync", 0, "Data/graph.ini");
	if(wglSwapIntervalEXT) wglSwapIntervalEXT(VSync);	// отключаем вертикальную синхронизацию, 1 - включить

	glEnable(GL_BLEND);

	//Туман
	//glEnable(GL_FOG);                       // Включает туман (GL_FOG)

	//GL_EXP 	- Обычный туман, заполняющий весь экран. Во многом он напоминает туман отдаленно, но легко справляется со своей работой даже на старых PC.
	//GL_EXP2 	- Это следующий шаг после GL_EXP. Затуманит весь экран, за то придает больше глубины всей сцене.
	//GL_LINEAR - Это лучший режим прорисовки тумана. Объекты выходят из тумана и исчезают в нем гораздо лучше.	glFogi(GL_FOG_MODE, fogMode[fogfilter]);// Выбираем тип тумана
	glFogi(GL_FOG_MODE, GL_LINEAR);// Выбираем тип тумана
	float fogColor[4]= {0.0f, 0.0f, 0.0f, 0.0f}; // Цвет тумана
	glFogfv(GL_FOG_COLOR, fogColor);        // Устанавливаем цвет тумана
	// устанавливает, насколько густым будет туман. Увеличьте число, и туман станет более густым, уменьшите - менее густым
	glFogf(GL_FOG_DENSITY, 0.0f);          // Насколько густым будет туман
	//GL_DONT_CARE - позволяет OpenGL выбрать формулу для расчета тумана (по вершинам или по пикселям).
	//GL_NICEST - Создает туман по пикселям (хорошо смотрится).
	//GL_FASTEST - Вычисляет туман по вершинам (быстрее, но не так красиво)) .	glHint(GL_FOG_HINT, GL_DONT_CARE);      // Вспомогательная установка тумана
	glHint(GL_FOG_HINT, GL_FASTEST );      
	glFogf(GL_FOG_START, 0.0f);             // Глубина, с которой начинается туман
	glFogf(GL_FOG_END, 40.0f);              // Глубина, где туман заканчивается.

	LogText("End sucsesful Set Default OpenGL");

	BuildFont();
	InitStarField();

	Scaner = new TScaner();
	Camera = new TCamera();

	std::string SectionName="";
	int NumMesh = GetPrivateProfileInt("Mesh", "NumMesh", 0, "Data/graph.ini");
	Mesh   = new TMesh[NumMesh+1];

		char buf[30];
		char FileName[100];
	for (int i=1; i<=NumMesh; i++)
	{
		sprintf(buf, "%d", i);
		SectionName = "FileMesh";
		SectionName += buf;
		GetPrivateProfileStringA("Mesh", SectionName.c_str(), "", FileName, 100, "Data/graph.ini");
		Mesh[i].LoadModel(FileName);
	}

	//InitParticle();	// тестовя функция
}
void GFXFogDensity (const float fogdensity) {
  if (fogdensity!=GFXFogState.density) {
    glFogf (GL_FOG_DENSITY,fogdensity); 
    GFXFogState.density=fogdensity;
  }
}
Exemple #23
0
void GLApp::display()
{
	//otherScene->Activate();
	//displayWorld();
	//checkError("DrawTestOther");
	//otherScene->Deactivate();

	float backgroundColour[] = {0.5f,0.65f,0.9f, 1};
	glClearColor(backgroundColour[0], backgroundColour[1], backgroundColour[2], backgroundColour[3]);
	glFogfv(GL_FOG_COLOR, backgroundColour);
	glFogf(GL_FOG_DENSITY, 1.f);
	glHint(GL_FOG_HINT, GL_DONT_CARE);
	glFogf(GL_FOG_START, 64);
	glFogf(GL_FOG_END, 130.0f);
	glFogi(GL_FOG_MODE, GL_LINEAR);

	glEnable(GL_FOG);

	displayWorld();
	glDisable(GL_FOG);

	{
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();

		glOrtho(0, width, 0, height, -10000, 10000);

		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();

		overlay.Display();
		overlay.Update();
		con->Render();
		xhair.Display();

		glPushMatrix();
		glTranslatef(10,10,0);
		glScalef(20, 20, 20);
		float fps = 1.0f/timer.Delta();
		arial->printf("FPS: %.2f", fps);
		glPopMatrix();   

	/*	//glEnable(GL_TEXTURE_2D);
		//glDisable(GL_TEXTURE_2D);
		glEnable(GL_TEXTURE_RECTANGLE_NV);
		glColor4f(1,1,1, 0.5f);
		glEnable(GL_BLEND);
		otherScene->Bind();
		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glBegin(GL_QUADS);

		glTexCoord2f(0, 0);
		glVertex2i(0, 0);
		glTexCoord2f(0, height);
		glVertex2i(0, height);
		glTexCoord2f(width, height);
		glVertex2i(width, height);
		glTexCoord2f(width, 0);
		glVertex2i(width, 0);

		glEnd();
		otherScene->Release();*/
		glDisable(GL_TEXTURE_RECTANGLE_NV);
		glDisable(GL_BLEND);

		glMatrixMode(GL_PROJECTION);
		glPopMatrix();   
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();


	}
	checkError("display");

}
Exemple #24
0
void draw_grid( program_state_t* PS )
{
	int w = PS->window_width;
	int h = PS->window_height;
	microtime_t T = PS->current_time_us;

	GLfloat x, y, z;
	GLfloat a, r;

	GLfloat camera_distance = CAMERA_DISTANCE;
	GLfloat camera_rotation
		= (T % ROTATION_DURATION)
		/ (GLfloat)ROTATION_DURATION
		* 360.0
	;

	GLfloat aspect = (GLfloat)w / (GLfloat)h;

	glViewport( 0, 0, w, h );
	glClearColor( 0.0f, 0.0f, 0.1f, 1.0f );	// Background dark blue, opaque
	glClearDepth( 1.0f );                   // Background depth to farthest
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	// Draw the 3D scene
	glMatrixMode( GL_PROJECTION );		// Setup perspective mode
	glLoadIdentity();
	gluPerspective(
		75.0f,				// fovy   Field of View, y-Axis
		aspect,				// Aspect ratio of the screen
		0.1f,				// zNear
		3000.0				// zFar
	);

	glMatrixMode( GL_MODELVIEW );
	glEnable( GL_DEPTH_TEST );
	glDepthFunc( GL_LESS );

#ifdef INTRO_USES_FOG
	GLfloat fog_color[4] = { 0,0,0, 0 };	// Fog of depth
	glEnable( GL_FOG );
	glFogi( GL_FOG_MODE, GL_EXP2 );
	glFogfv( GL_FOG_COLOR, fog_color );
	glFogf( GL_FOG_DENSITY, FOG_DENSITY );
	glHint( GL_FOG_HINT, GL_NICEST );
#endif

	glLoadIdentity();			// Reset
	glTranslatef( 0, CAMERA_OFFSET, -camera_distance );
	glRotatef( CAMERA_ANGLE, 1,0,0 );
	glRotatef( camera_rotation, 0,0,1 );

	GLfloat start_radius = (T % 100000) / -100000.0 + 0.01;

	glBegin( GL_POINTS );
	glPointSize( 1 );
	glColor3f( 1.0, 1.0, 1.0 );
	for( a = 0.0 ; a < 360.0*DEG_TO_RAD ; a += 5.0*DEG_TO_RAD ) {
		for( r = start_radius ; r < RADIUS ; r += RADIUS/100.0) {
			x = cos(a) * r;
			y = sin(a) * r;
			z = -RADIUS / sqrt(r + RADIUS_OFFSET);

			glVertex3f( x, y, z );
		}
	}
	glEnd();
	glPointSize( 1 );

#ifdef INTRO_USES_FOG
	glDisable( GL_FOG );
#endif
}
//Función para actualizar el juego.
void cGame::Update( float lfTimestep )
{ 			
	//Se actualiza la ventana:
	cWindow::Get().Update();

	// Updates application duration time
	mfAcTime += lfTimestep;

	//Se actualiza el InputManager.
	cInputManager::Get().Update(lfTimestep);

	// Checks if the effect has to be reloaded
	bool lbreloadEffect = IsPressed(eIA_ReloadEffectManager);
	if (lbreloadEffect) {
		cEffectManager::Get().Reload();
	}

	// Se actualiza niebla
	miFogStep ++;

	if (miFogStep == 1000) {
		if (mbFogIncreasing) {
			if (mfFogDensity >= 0.0005f)
				mbFogIncreasing = false;
			else
				mfFogDensity += 0.00001f;
		} else {
			if (mfFogDensity <= 0.0002f)
				mbFogIncreasing = true;
			else
				mfFogDensity -= 0.00001f;
		}

		miFogStep %= 1000;
	}
	glFogf (GL_FOG_DENSITY, mfFogDensity);

	// Recoge input teclado
	bool lbmoveFront = IsPressed( eIA_MoveFront );
	bool lbmoveBack = IsPressed( eIA_MoveBack );
	bool lbmoveLeft = IsPressed( eIA_MoveLeft );
	bool lbmoveRight = IsPressed( eIA_MoveRight );	
	bool lbswitchCamera = BecomePressed( eIA_SwitchCamera );
	bool lbswitchRasterizationMode = BecomePressed( eIA_SwitchFillLineMode );

	// Switch entre camara de juego/godmode
	if (lbswitchCamera)
		mbInGame = !mbInGame;
	// Switch entre el modo de rasterizacion solido/wireframe
	if (lbswitchRasterizationMode)
		mbRasterizationMode = !mbRasterizationMode;

	// Actualiza el flag de movimiento del personaje
	CharacterPos::Get().ResetChanged();
	// Calcula velocidad * tiempo transcurrido
	CharacterPos::Get().Update(lfTimestep);

	// Rotaciones del ratón
	float lfYaw = GetValue( eIA_MouseYaw );
	float lfPitch = GetValue( eIA_MousePitch );

	bool lbAuxCamera = IsPressed( eIA_SwitchCameraAux );

	// En modo juego, actualiza jugador
	if (mbInGame){
		mGodCamera.ResetYawPitch();
		if ( lbmoveFront && mMustang.IsAlive() ) {
			//CharacterPos::Get().MoveFront();
			//mVehicle.MoveForward(lfTimestep);
			mMustang.MoveForward(lfTimestep);
		}
		else if ( lbmoveBack && mMustang.IsAlive() ){
			//CharacterPos::Get().MoveBack();
			//mVehicle.Break(lfTimestep);
			mMustang.Break(lfTimestep);	
		}
		if ( lbmoveLeft && mMustang.IsAlive() ){
			//CharacterPos::Get().TurnLeft();
			//mVehicle.SteeringLeft(lfTimestep);
			mMustang.SteeringLeft(lfTimestep);
		}
		else if ( lbmoveRight && mMustang.IsAlive() ){
			//CharacterPos::Get().TurnRight();
			//mVehicle.SteeringRight(lfTimestep);
			mMustang.SteeringRight(lfTimestep);
		}

		// Actualizacion de cámara de juego
		// Si se pulsa la tecla de camara auxiliar se cambia la orientacion de la camara
		float lfDistance, lfYOffset;
		cVec3 lvYViewOffset;
		if (lbAuxCamera) {
			lfDistance = -4.f;	
			lfYOffset = 2.8f;
			lvYViewOffset = cVec3(0.f, 3.f, 0.f);
		} else {
			lfDistance = 8.f;
			lfYOffset = 3.3f;
			lvYViewOffset = cVec3(0.f, 0.0f, 0.f);
		}

		//cVec3 vVector = CharacterPos::Get().GetCharacterPosition() - CharacterPos::Get().GetFront() * lfDistance;

		/*m3DCamera.SetLookAt( cVec3(vVector.x,
								   vVector.y + 1.5f,
								   vVector.z),
								   CharacterPos::Get().GetCharacterPosition(), 
								   cVec3(0.0f, 1.f, 0.f) );*/
		//cVec3 vVector = mVehicle.GetChasisPos() - mVehicle.GetChasisRot() * lfDistance;
		cVec3 vVector = mMustang.GetVehicleBullet()->GetChasisPos() - mMustang.GetVehicleBullet()->GetChasisRot()  * lfDistance;

		m3DCamera.SetLookAt( cVec3(vVector.x,
								   vVector.y + lfYOffset,
								   vVector.z),
								   mMustang.GetVehicleBullet()->GetChasisPos() + lvYViewOffset, 
								   cVec3(0.0f, 1.f, 0.f) );

		bool lbFireMainWeapon = IsPressed( eIA_Fire );

		// Si no esta vivo el jugador entonces no puede disparar
		(!mMustang.IsAlive())?lbFireMainWeapon = false : lbFireMainWeapon = lbFireMainWeapon; 

		// Resetea estados de daño
		InitDamageStates();

		mMustang.Update(lfTimestep, lfYaw, lfPitch, lbAuxCamera, lbFireMainWeapon);
		mTruck.Update(lfTimestep);

	// Modo Godmode	
	} else {
		// Actualizacion camara godmode
		if ( lbmoveFront ) {
			mGodCamera.MoveFront(lfTimestep);				
		}
		else if ( lbmoveBack ){
			mGodCamera.MoveBack(lfTimestep);
		}
		if ( lbmoveLeft ){
			mGodCamera.MoveLeft(lfTimestep);
		}
		else if ( lbmoveRight ){
			mGodCamera.MoveRight(lfTimestep);
		}
		if (lfYaw || lfPitch){
			mGodCamera.MoveYawPitch(lfYaw, lfPitch, lfTimestep);
		}

		// Resetea estados de daño
		InitDamageStates();

		mMustang.Update(lfTimestep, lfYaw, lfPitch);
		mTruck.Update(lfTimestep);
	}

	//mObject.SetPosition(CharacterPos::Get().GetCharacterPosition(), CharacterPos::Get().GetYaw());

	// Actualiza personaje
	//mObject.Update(lfTimestep);

	// Update bullet physics object
	cPhysics::Get().Update(lfTimestep);

	//Se actualizan los personajes:
	cCharacterManager::Get().Update(lfTimestep);

//	((cScene *)mScene.GetResource())->Update(lfTimestep);

	// Update physic objects
	for ( unsigned int luiIndex = 0; luiIndex < 10; ++luiIndex) {
		maSphereObjects[luiIndex].Update(lfTimestep);
	}

	// Ruinas
	for ( unsigned int luiIndex = 0; luiIndex < RUINS_NUMBER; ++luiIndex) {
		maRuins[luiIndex].Update(lfTimestep);
	}

	//((cScene *)mMusExt.GetResource())->Update(lfTimestep);
	((cScene *)mMusNeu.GetResource())->Update(lfTimestep);

	// Check if the animation keys (stop/start) are pressed
	cSkeletalMesh* lpSkeletonMesh =(cSkeletalMesh*)mSkeletalMesh.GetResource();

	/*static bool mbJogging = false;

	bool lbPlayJogPressed = BecomePressed(eIA_PlayJog);
	bool lbStopJogPressed = BecomePressed(eIA_StopJog);
	bool lbPlayWavePressed = BecomePressed(eIA_PlayWave);
	bool lbStopWavePressed = BecomePressed(eIA_StopWave);

	// Jog animation
	if (lbPlayJogPressed && !mbJogging){
		mbJogging = true;
		lpSkeletonMesh->PlayAnim("Jog", 1.0f, 0.1f);
		lpSkeletonMesh->StopAnim("Idle", 0.1f);
	}else if (lbStopJogPressed && mbJogging){
		mbJogging = false;
		lpSkeletonMesh->PlayAnim("Idle", 1.0f, 0.1f);
		lpSkeletonMesh->StopAnim("Jog", 0.1f);
	}

	// Wave animation
	if (lbPlayWavePressed){
		lpSkeletonMesh->PlayAnim("Wave", 1.0f, 0.1f, 0.1f);
	}else if (lbStopWavePressed){
		lpSkeletonMesh->StopAnim("Wave", 0.1f);
	}*/
	
	//Se comprueba si hay que cerrar la aplicación, por ejemplo a causa de 
	// que el usuario haya cerrado la ventana. 
	mbFinish = mbFinish || cWindow::Get().GetCloseApplication()
		         //También se verifica si se ha producido la acción de entrada que cierra la aplicación:
				 // Pulsar la tecla ESC del teclado, el botón 1 del JoyStick o el botón central del ratón.
	             || IsPressed(eIA_CloseApplication);
	//Si es así, se cambia el booleano
	// que controla el cierre de la aplicación.

	if ( mbFinish )
	{
		return;
	}	
}
Exemple #26
0
/// Set the OpenGL fog start and end
void pie_UpdateFogDistance(float begin, float end)
{
	glFogf(GL_FOG_START, begin);
	glFogf(GL_FOG_END, end);
}
Exemple #27
0
void GLGSRender::ExecCMD()
{
	if(!LoadProgram())
	{
		ConLog.Error("LoadProgram failed.");
		Emu.Pause();
		return;
	}

	if(!m_fbo.IsCreated() || m_width != last_width || m_height != last_height || last_depth_format != m_surface_depth_format)
	{
		ConLog.Warning("New FBO (%dx%d)", m_width, m_height);
		last_width = m_width;
		last_height = m_height;
		last_depth_format = m_surface_depth_format;

		m_fbo.Create();
		checkForGlError("m_fbo.Create");
		m_fbo.Bind();

		m_rbo.Create(4 + 1);
		checkForGlError("m_rbo.Create");

		for(int i=0; i<4; ++i)
		{
			m_rbo.Bind(i);
			m_rbo.Storage(GL_RGBA, m_width, m_height);
			checkForGlError("m_rbo.Storage(GL_RGBA)");
		}

		m_rbo.Bind(4);

		switch(m_surface_depth_format)
		{
		case 1:
			m_rbo.Storage(GL_DEPTH_COMPONENT16, m_width, m_height);
			checkForGlError("m_rbo.Storage(GL_DEPTH_COMPONENT16)");
		break;

		case 2:
			m_rbo.Storage(GL_DEPTH24_STENCIL8, m_width, m_height);
			checkForGlError("m_rbo.Storage(GL_DEPTH24_STENCIL8)");
		break;

		default:
			ConLog.Error("Bad depth format! (%d)", m_surface_depth_format);
			assert(0);
		break;
		}

		for(int i=0; i<4; ++i)
		{
			m_fbo.Renderbuffer(GL_COLOR_ATTACHMENT0 + i, m_rbo.GetId(i));
			checkForGlError(wxString::Format("m_fbo.Renderbuffer(GL_COLOR_ATTACHMENT%d)", i));
		}

		m_fbo.Renderbuffer(GL_DEPTH_ATTACHMENT, m_rbo.GetId(4));
		checkForGlError("m_fbo.Renderbuffer(GL_DEPTH_ATTACHMENT)");

		if(m_surface_depth_format == 2)
		{
			m_fbo.Renderbuffer(GL_STENCIL_ATTACHMENT, m_rbo.GetId(4));
			checkForGlError("m_fbo.Renderbuffer(GL_STENCIL_ATTACHMENT)");
		}
	}

	if(!m_set_surface_clip_horizontal)
	{
		m_surface_clip_x = 0;
		m_surface_clip_w = m_width;
	}

	if(!m_set_surface_clip_vertical)
	{
		m_surface_clip_y = 0;
		m_surface_clip_h = m_height;
	}
		
	m_fbo.Bind();
	if(Ini.GSDumpDepthBuffer.GetValue())
		WriteDepthBuffer();
	static const GLenum draw_buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };

	switch(m_surface_colour_target)
	{
	case 0x0:
		break;

	case 0x1:
		glDrawBuffer(draw_buffers[0]);
	break;

	case 0x2:
		glDrawBuffer(draw_buffers[1]);
	break;

	case 0x13:
		glDrawBuffers(2, draw_buffers);
	break;

	case 0x17:
		glDrawBuffers(3, draw_buffers);
	break;

	case 0x1f:
		glDrawBuffers(4, draw_buffers);
	break;

	default:
		ConLog.Error("Bad surface colour target: %d", m_surface_colour_target);
	break;
	}

	if(m_set_color_mask)
	{
		glColorMask(m_color_mask_r, m_color_mask_g, m_color_mask_b, m_color_mask_a);
		checkForGlError("glColorMask");
	}

	if(m_set_viewport_horizontal && m_set_viewport_vertical)
	{
		glViewport(m_viewport_x, m_height-m_viewport_y-m_viewport_h, m_viewport_w, m_viewport_h);
		checkForGlError("glViewport");
	}

	if(m_set_scissor_horizontal && m_set_scissor_vertical)
	{
		glScissor(m_scissor_x, m_height-m_scissor_y-m_scissor_h, m_scissor_w, m_scissor_h);
		checkForGlError("glScissor");
	}

	if(m_clear_surface_mask)
	{
		GLbitfield f = 0;

		if (m_clear_surface_mask & 0x1)
		{
			glClearDepth(m_clear_surface_z / (float)0xffffff);

			f |= GL_DEPTH_BUFFER_BIT;
		}

		if (m_clear_surface_mask & 0x2)
		{
			glClearStencil(m_clear_surface_s);

			f |= GL_STENCIL_BUFFER_BIT;
		}

		if (m_clear_surface_mask & 0xF0)
		{
			glClearColor(
				m_clear_surface_color_r / 255.0f,
				m_clear_surface_color_g / 255.0f,
				m_clear_surface_color_b / 255.0f,
				m_clear_surface_color_a / 255.0f);

			f |= GL_COLOR_BUFFER_BIT;
		}

		glClear(f);
	}

	if(m_set_front_polygon_mode)
	{
		glPolygonMode(GL_FRONT, m_front_polygon_mode);
		checkForGlError("glPolygonMode");
	}

	Enable(m_depth_test_enable, GL_DEPTH_TEST);
	Enable(m_set_alpha_test, GL_ALPHA_TEST);
	Enable(m_set_depth_bounds_test, GL_DEPTH_CLAMP);
	Enable(m_set_blend, GL_BLEND);
	Enable(m_set_logic_op, GL_LOGIC_OP);
	Enable(m_set_cull_face_enable, GL_CULL_FACE);
	Enable(m_set_dither, GL_DITHER);
	Enable(m_set_stencil_test, GL_STENCIL_TEST);
	Enable(m_set_line_smooth, GL_LINE_SMOOTH);
	Enable(m_set_poly_smooth, GL_POLYGON_SMOOTH);

	if(m_set_clip_plane)
	{
		Enable(m_clip_plane_0, GL_CLIP_PLANE0);
		Enable(m_clip_plane_1, GL_CLIP_PLANE1);
		Enable(m_clip_plane_2, GL_CLIP_PLANE2);
		Enable(m_clip_plane_3, GL_CLIP_PLANE3);
		Enable(m_clip_plane_4, GL_CLIP_PLANE4);
		Enable(m_clip_plane_5, GL_CLIP_PLANE5);

		checkForGlError("m_set_clip_plane");
	}

	checkForGlError("glEnable");

	if(m_set_two_sided_stencil_test_enable)
	{
		if(m_set_stencil_fail && m_set_stencil_zfail && m_set_stencil_zpass)
		{
			glStencilOpSeparate(GL_FRONT, m_stencil_fail, m_stencil_zfail, m_stencil_zpass);
			checkForGlError("glStencilOpSeparate");
		}

		if(m_set_stencil_mask)
		{
			glStencilMaskSeparate(GL_FRONT, m_stencil_mask);
			checkForGlError("glStencilMaskSeparate");
		}

		if(m_set_stencil_func && m_set_stencil_func_ref && m_set_stencil_func_mask)
		{
			glStencilFuncSeparate(GL_FRONT, m_stencil_func, m_stencil_func_ref, m_stencil_func_mask);
			checkForGlError("glStencilFuncSeparate");
		}

		if(m_set_back_stencil_fail && m_set_back_stencil_zfail && m_set_back_stencil_zpass)
		{
			glStencilOpSeparate(GL_BACK, m_back_stencil_fail, m_back_stencil_zfail, m_back_stencil_zpass);
			checkForGlError("glStencilOpSeparate(GL_BACK)");
		}

		if(m_set_back_stencil_mask)
		{
			glStencilMaskSeparate(GL_BACK, m_back_stencil_mask);
			checkForGlError("glStencilMaskSeparate(GL_BACK)");
		}

		if(m_set_back_stencil_func && m_set_back_stencil_func_ref && m_set_back_stencil_func_mask)
		{
			glStencilFuncSeparate(GL_BACK, m_back_stencil_func, m_back_stencil_func_ref, m_back_stencil_func_mask);
			checkForGlError("glStencilFuncSeparate(GL_BACK)");
		}
	}
	else
	{
		if(m_set_stencil_fail && m_set_stencil_zfail && m_set_stencil_zpass)
		{
			glStencilOp(m_stencil_fail, m_stencil_zfail, m_stencil_zpass);
			checkForGlError("glStencilOp");
		}

		if(m_set_stencil_mask)
		{
			glStencilMask(m_stencil_mask);
			checkForGlError("glStencilMask");
		}

		if(m_set_stencil_func && m_set_stencil_func_ref && m_set_stencil_func_mask)
		{
			glStencilFunc(m_stencil_func, m_stencil_func_ref, m_stencil_func_mask);
			checkForGlError("glStencilFunc");
		}
	}

	if(m_set_shade_mode)
	{
		glShadeModel(m_shade_mode);
		checkForGlError("glShadeModel");
	}

	if(m_set_depth_mask)
	{
		glDepthMask(m_depth_mask);
		checkForGlError("glDepthMask");
	}

	if(m_set_depth_func)
	{
		glDepthFunc(m_depth_func);
		checkForGlError("glDepthFunc");
	}

	if(m_set_clip)
	{
		glDepthRangef(m_clip_min, m_clip_max);
		checkForGlError("glDepthRangef");
	}

	if(m_set_line_width)
	{
		glLineWidth(m_line_width / 255.f);
		checkForGlError("glLineWidth");
	}

	if(m_set_blend_equation)
	{
		glBlendEquationSeparate(m_blend_equation_rgb, m_blend_equation_alpha);
		checkForGlError("glBlendEquationSeparate");
	}

	if(m_set_blend_sfactor && m_set_blend_dfactor)
	{
		glBlendFuncSeparate(m_blend_sfactor_rgb, m_blend_dfactor_rgb, m_blend_sfactor_alpha, m_blend_dfactor_alpha);
		checkForGlError("glBlendFuncSeparate");
	}

	if(m_set_blend_color)
	{
		glBlendColor(m_blend_color_r, m_blend_color_g, m_blend_color_b, m_blend_color_a);
		checkForGlError("glBlendColor");
	}

	if(m_set_cull_face)
	{
		glCullFace(m_cull_face);
		checkForGlError("glCullFace");
	}

	if(m_set_alpha_func && m_set_alpha_ref)
	{
		glAlphaFunc(m_alpha_func, m_alpha_ref);
		checkForGlError("glAlphaFunc");
	}

	if(m_set_fog_mode)
	{
		glFogi(GL_FOG_MODE, m_fog_mode);
		checkForGlError("glFogi(GL_FOG_MODE)");
	}

	if(m_set_fog_params)
	{
		glFogf(GL_FOG_START, m_fog_param0);
		checkForGlError("glFogf(GL_FOG_START)");
		glFogf(GL_FOG_END, m_fog_param1);
		checkForGlError("glFogf(GL_FOG_END)");
	}

	if(m_indexed_array.m_count && m_draw_array_count)
	{
		ConLog.Warning("m_indexed_array.m_count && draw_array_count");
	}

	for(u32 i=0; i<m_textures_count; ++i)
	{
		if(!m_textures[i].IsEnabled()) continue;

		glActiveTexture(GL_TEXTURE0 + i);
		checkForGlError("glActiveTexture");
		m_gl_textures[i].Create();
		m_gl_textures[i].Bind();
		checkForGlError(wxString::Format("m_gl_textures[%d].Bind", i));
		m_program.SetTex(i);
		m_gl_textures[i].Init(m_textures[i]);
		checkForGlError(wxString::Format("m_gl_textures[%d].Init", i));
	}

	m_vao.Bind();
	if(m_indexed_array.m_count)
	{
		LoadVertexData(m_indexed_array.index_min, m_indexed_array.index_max - m_indexed_array.index_min + 1);
	}

	EnableVertexData(m_indexed_array.m_count ? true : false);

	InitVertexData();
	InitFragmentData();

	if(m_indexed_array.m_count)
	{
		switch(m_indexed_array.m_type)
		{
		case 0:
			glDrawElements(m_draw_mode - 1, m_indexed_array.m_count, GL_UNSIGNED_INT, nullptr);
			checkForGlError("glDrawElements #4");
		break;

		case 1:
			glDrawElements(m_draw_mode - 1, m_indexed_array.m_count, GL_UNSIGNED_SHORT, nullptr);
			checkForGlError("glDrawElements #2");
		break;

		default:
			ConLog.Error("Bad indexed array type (%d)", m_indexed_array.m_type);
		break;
		}

		DisableVertexData();
		m_indexed_array.Reset();
	}

	if(m_draw_array_count)
	{
		glDrawArrays(m_draw_mode - 1, 0, m_draw_array_count);
		checkForGlError("glDrawArrays");
		DisableVertexData();
		m_draw_array_count = 0;
	}

	if(Ini.GSDumpColorBuffers.GetValue())
		WriteBuffers();
}
// selfDraw draws in 3D using the default ofEasyCamera
// you can change the camera by returning getCameraRef()
void CloudsVisualSystemLaplacianTunnel::selfDraw(){
	if(vbos.size() > 0){
		
		glPushAttrib(GL_FOG_BIT);
		
		glEnable(GL_FOG);
		glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH);
		glFogi(GL_FOG_MODE, GL_EXP);
		
		//	float FogCol[3]={0.8f,0.8f,0.8f}; // Define a nice light grey
		//	glFogfv(GL_FOG_COLOR, FogCol);     // Set the fog color
		glFogf(GL_FOG_DENSITY, powf(fogDensity,2));
		
		ofFloatColor bgColor = ofFloatColor::fromHsb(bgHue, bgSat, bgBri);
		
		GLfloat fogColor[4] = {bgColor.r/255.,bgColor.g/255.,bgColor.b/255., 1.0 };
		glFogfv (GL_FOG_COLOR, fogColor);
		glEnable(GL_DEPTH_TEST);
		//glDisable(GL_DEPTH_TEST);
		
		ofEnableAlphaBlending();

		int vboIndex = int( (ofGetElapsedTimef() - startTime) * fps) % vbos.size() ;
		
		headlight.enable();
		float spread = (max.y - min.y);
		float startY = min.y + tunnelCam.getPosition().y - fmod(tunnelCam.getPosition().y, spread);
		
		mat->begin();
//		ofSphere(tunnelCam.getPosition(), 20);
//		numReplications = 1;
//		ofTranslate(0,translateAmount,0);

		for(int i = 0; i < numReplications; i++){
			ofPushMatrix();
			glPointSize(2);
			float translateAmount = (startY + i*spread);
			ofTranslate(0,translateAmount,0);
			ofTranslate(center);
			ofRotate(translateAmount*corkscrewFactor,0,1,0);
			ofTranslate(-center);
			
//			cout << "translating " << translateAmount << " camera is currently at " << tunnelCam.getPosition().y << endl;
			
			float cameraoffset = tunnelCam.getPosition().y - translateAmount - spread;
			int index = int(ofMap(cameraoffset, 0, -spread*numReplications, 1.0, 0.0, true) * (vbos.size()-1));

//			if(i == 0){
//				ofSetColor(0);
//				vbos[index].vbo->drawElements(GL_TRIANGLES, vbos[index].indexCount);
//			}
			ofSetColor(255);
			//vbos[index].vbo->drawElements(GL_TRIANGLES, vbos[index].indexCount);
			//vbos[index].vbo->draw(GL_TRIANGLES, 0, vbos[index].indexCount);
			vbos[index].vbo->draw(GL_POINTS, 0, vbos[index].indexCount);
			
			ofPopMatrix();
		}

		
		mat->end();
		headlight.disable();

		glPopAttrib();
	}
	
}
Exemple #29
0
void gl_init(void)
{
  ilInit();

  float fogColor[]={0.1,0.1,0.1,1};

  // setup perpective
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(FOV,(GLfloat)RESX/(GLfloat)RESY,1,16384);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  // setup shade model
  glShadeModel(GL_SMOOTH);

  // setup depth buffer
  glClearDepth(1.0);
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);

  // setup face culling
  glFrontFace(GL_CCW);
  glEnable(GL_CULL_FACE);

  
  // setup vertex arrays
  glEnableClientState(GL_VERTEX_ARRAY);
//  glVertexPointer(3,GL_FLOAT,sizeof(vertex_t),vertex[0].coordinate);
//  glClientActiveTextureARB(GL_TEXTURE0_ARB); 
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//  glTexCoordPointer(2,GL_FLOAT,sizeof(vertex_t),vertex[0].texCoordinate);
//  glClientActiveTextureARB(GL_TEXTURE1_ARB); 
//  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//  glTexCoordPointer(2 ,GL_FLOAT,sizeof(vertex_t),vertex[0].lmapCoordinate);
  glEnableClientState(GL_NORMAL_ARRAY);
 

  // set up texturing
  // glActiveTextureARB(GL_TEXTURE0_ARB);
  glEnable(GL_TEXTURE_2D);
  glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
  // glActiveTextureARB(GL_TEXTURE1_ARB);
  // glEnable(GL_TEXTURE_2D);
  // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

  // setup lights
  GLfloat lmodel_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  glEnable(GL_LIGHTING);
  glEnable(GL_NORMALIZE);
//  glEnable(GL_RESCALE_NORMAL);


  // set up fog
  glFogi(GL_FOG_MODE,GL_EXP2);
  glFogfv(GL_FOG_COLOR,fogColor);
  glFogf(GL_FOG_DENSITY,0.001);
  glHint(GL_FOG_HINT,GL_NICEST);
  if(FOG) glEnable(GL_FOG);

  // rotate textures to compensate for different origin per image type.
  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
  glRotatef(180, 1, 0, 0);

  // reset camera
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // clear and update frame buffer
  glClearColor(0,0,0,0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);	
  glFlush();
  SDL_GL_SwapWindow(main_window);
}
Exemple #30
0
static void Init(void)
{
    float ambient[] = {0.0, 0.0, 0.0, 1.0};
    float diffuse[] = {1.0, 1.0, 1.0, 1.0};
    float specular[] = {1.0, 1.0, 1.0, 1.0};
    float position[] = {0.0, 0.0,  4.0, 0.0};
    float fog_color[] = {0.0, 0.0, 0.0, 1.0};
    float mat_ambient[] = {0.0, 0.0, 0.0, 1.0};
    float mat_shininess[] = {90.0};
    float mat_specular[] = {1.0, 1.0, 1.0, 1.0};
    float mat_diffuse[] = {0.8, 0.8, 0.8, 1.0};
    float lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0};
    float lmodel_twoside[] = {GL_TRUE};
    int w, h;
    GLenum format;
    GLubyte *image;

    printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));

    SetDefaultSettings();

    image = LoadRGBImage(imageFileName, &w, &h, &format);
    if (!image) {
       printf("Error: couldn't load %s\n", imageFileName);
       exit(1);
    }
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    gluBuild2DMipmaps(GL_TEXTURE_2D, format, w, h,
                      GL_RGB, GL_UNSIGNED_BYTE, image);

    free(image);

    glFogf(GL_FOG_DENSITY, 0.125);
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glFogf(GL_FOG_START, 4.0);
    glFogf(GL_FOG_END, 8.5);
    glFogfv(GL_FOG_COLOR, fog_color);

    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glEnable(GL_LIGHT0);

    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);

    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
    glShadeModel(GL_SMOOTH);


    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);

    glFrontFace(GL_CW);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glTexGeniv(GL_S, GL_TEXTURE_GEN_MODE, sphereMap);
    glTexGeniv(GL_T, GL_TEXTURE_GEN_MODE, sphereMap);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);

    glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
    glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
    glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, sWrapMode);
    glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tWrapMode);

    glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureEnvironment);

    BuildLists();
}