Exemplo n.º 1
0
static void
Init(void)
{
   static const GLubyte teximage[2][2][4] = {
      { { 255, 255, 255, 255}, { 128, 128, 128, 255} },
      { { 128, 128, 128, 255}, { 255, 255, 255, 255} }
   };

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

   if (!GLEW_EXT_fog_coord) {
      printf("GL_EXT_fog_coord not supported!\n");
   }

   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0,
                GL_RGBA, GL_UNSIGNED_BYTE, teximage);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

   glClearColor(0.1f, 0.1f, 0.1f, 0.0f);

   glDepthFunc(GL_LEQUAL);
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_SMOOTH);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

   glFogfv(GL_FOG_COLOR, fogColor);
   glHint(GL_FOG_HINT, GL_NICEST);
   fogCoord = SetFogCoord(GL_TRUE); /* try to enable fog_coord */
   fogMode = SetFogMode(1);

   glEnableClientState(GL_VERTEX_ARRAY);
   glVertexPointer(3, GL_FLOAT, 0, vertex_pointer);

   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   glTexCoordPointer(2, GL_FLOAT, 0, texcoord_pointer);

   if (GLEW_EXT_fog_coord) {
      glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
      glFogCoordPointerEXT(GL_FLOAT, 0, fogcoord_pointer);
   }

   Reset();
}
Exemplo n.º 2
0
static void
Key( unsigned char key, int x, int y )
{
   (void) x;
   (void) y;
   switch (key) {
      case 'a':
         Arrays = !Arrays;
         break;
      case 'f':
      case 'm':
         fogMode = SetFogMode(fogMode + 1);
         break;
      case 'D':
         fogDensity += 0.05;
         SetFogMode(fogMode);
         break;
      case 'd':
         if (fogDensity > 0.0) {
            fogDensity -= 0.05;
         }
         SetFogMode(fogMode);
         break;
      case 's':
         if (fogStart > 0.0) {
            fogStart -= 0.25;
         }
         SetFogMode(fogMode);
         break;
      case 'S':
         if (fogStart < 100.0) {
            fogStart += 0.25;
         }
         SetFogMode(fogMode);
         break;
      case 'e':
         if (fogEnd > 0.0) {
            fogEnd -= 0.25;
         }
         SetFogMode(fogMode);
         break;
      case 'E':
         if (fogEnd < 100.0) {
            fogEnd += 0.25;
         }
         SetFogMode(fogMode);
         break;
      case 'c':
	 fogCoord = SetFogCoord(fogCoord ^ GL_TRUE);
         break;
      case 't':
         Texture = !Texture;
         break;
      case 'z':
         camz -= 0.1;
         break;
      case 'Z':
         camz += 0.1;
         break;
      case 'r':
         Reset();
         break;
      case 27:
         exit(0);
         break;
   }
   glutPostRedisplay();
}
Exemplo n.º 3
0
void RenderHeightMap(BYTE pHeightMap[])
{
	int X = 0, Y = 0;						// Create some variables to walk the array with.
	int x, y, z;							// Create some variables for readability
	bool bSwitchSides = false;

	// Make sure our height data is valid
	if(!pHeightMap) return;		
	
	// Activate the first texture ID and bind the tree background to it
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, g_Texture[0]);

	// If we want detail texturing on, let's render the second texture
	if(g_bDetail)
	{
		// Activate the second texture ID and bind the fog texture to it
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glEnable(GL_TEXTURE_2D);
		
		// Here we turn on the COMBINE properties and increase our RGB
		// gamma for the detail texture.  2 seems to work just right.
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
		glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
		
		// Bind the detail texture
		glBindTexture(GL_TEXTURE_2D, g_Texture[1]);
	
		// Now we want to enter the texture matrix.  This will allow us
		// to change the tiling of the detail texture.
		glMatrixMode(GL_TEXTURE);

			// Reset the current matrix and apply our chosen scale value
			glLoadIdentity();
			glScalef((float)g_DetailScale, (float)g_DetailScale, 1);

		// Leave the texture matrix and set us back in the model view matrix
		glMatrixMode(GL_MODELVIEW);
	}

	// We want to render triangle strips
	glBegin( GL_TRIANGLE_STRIP );			

	// Go through all of the rows of the height map
	for ( X = 0; X <= MAP_SIZE; X += STEP_SIZE )
	{
		// Check if we need to render the opposite way for this column
		if(bSwitchSides)
		{	
			// Render a column of the terrain, for this current X.
			// We start at MAP_SIZE and render down to 0.
			for ( Y = MAP_SIZE; Y >= 0; Y -= STEP_SIZE )
			{
				// Get the (X, Y, Z) value for the bottom left vertex		
				x = X;							
				y = Height(pHeightMap, X, Y );	
				z = Y;							


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

				// Set the fog coordinate for this vertex, depending on it's height
				// and the current depth of the fog.
				SetFogCoord(g_FogDepth, (float)y);

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


				// Set the current texture coordinate and render the vertex
				SetTextureCoord( (float)x, (float)z );
				glVertex3i(x, y, z);		

				// Get the (X, Y, Z) value for the bottom right vertex		
				x = X + STEP_SIZE; 
				y = Height(pHeightMap, X + STEP_SIZE, Y ); 
				z = Y;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

				// Set the fog coordinate for this vertex
				SetFogCoord(g_FogDepth, (float)y);

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


				// Set the current texture coordinate and render the vertex
				SetTextureCoord( (float)x, (float)z );
				glVertex3i(x, y, z);			
			}
		}
		else
		{	
			// Render a column of the terrain, for this current X.
			// We start at 0 and render down up to MAP_SIZE.
			for ( Y = 0; Y <= MAP_SIZE; Y += STEP_SIZE )
			{
				// Get the (X, Y, Z) value for the bottom right vertex		
				x = X + STEP_SIZE; 
				y = Height(pHeightMap, X + STEP_SIZE, Y ); 
				z = Y;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

				// Set the fog coordinate for this vertex
				SetFogCoord(g_FogDepth, (float)y);

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


				// Set the current texture coordinate and render the vertex
				SetTextureCoord( (float)x, (float)z );
				glVertex3i(x, y, z);

				// Get the (X, Y, Z) value for the bottom left vertex		
				x = X;							
				y = Height(pHeightMap, X, Y );	
				z = Y;							


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

				// Set the fog coordinate for this vertex
				SetFogCoord(g_FogDepth, (float)y);

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


				// Set the current texture coordinate and render the vertex
				SetTextureCoord( (float)x, (float)z );
				glVertex3i(x, y, z);		
			}
		}

		// Switch the direction the column renders to allow the fluid tri strips
		bSwitchSides = !bSwitchSides;
	}

	// Stop rendering triangle strips
	glEnd();

	// Turn the second multitexture pass off
	glActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_2D);

	// Turn the first multitexture pass off
	glActiveTextureARB(GL_TEXTURE0_ARB);		
    glDisable(GL_TEXTURE_2D);
}