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(); }
void CBaseShader::FogToFogColor( void ) { Assert( IsSnapshotting() ); SetFogMode( SHADER_FOGMODE_FOGCOLOR ); }
void CBaseShader::FogToGrey( void ) { Assert( IsSnapshotting() ); SetFogMode( SHADER_FOGMODE_GREY ); }
void CBaseShader::FogToBlack( void ) { Assert( IsSnapshotting() ); SetFogMode( SHADER_FOGMODE_BLACK ); }
void CBaseShader::FogToWhite( void ) { Assert( IsSnapshotting() ); SetFogMode( SHADER_FOGMODE_WHITE ); }
//----------------------------------------------------------------------------- // // Helper methods for fog // //----------------------------------------------------------------------------- void CBaseShader::FogToOOOverbright( void ) { Assert( IsSnapshotting() ); SetFogMode( SHADER_FOGMODE_OO_OVERBRIGHT ); }
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(); }
static void Display( void ) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); glTranslatef(0.0f, 0.0f, -camz); SetFogMode(fogMode); glColor3f(1, 1, 1); if (Texture) glEnable(GL_TEXTURE_2D); if (Arrays) { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawElements(GL_QUADS, sizeof(vertex_index) / sizeof(vertex_index[0]), GL_UNSIGNED_INT, vertex_index); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } else { /* Back */ glBegin(GL_QUADS); glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f,-DEPTH); glEnd(); /* Floor */ glBegin(GL_QUADS); glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f,-DEPTH); glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, DEPTH); glVertex3f( 1.0f,-1.0f,0.0); glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, DEPTH); glVertex3f(-1.0f,-1.0f,0.0); glEnd(); /* Roof */ glBegin(GL_QUADS); glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, 1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f,-DEPTH); glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, DEPTH); glVertex3f( 1.0f, 1.0f,0.0); glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, DEPTH); glVertex3f(-1.0f, 1.0f,0.0); glEnd(); /* Right */ glBegin(GL_QUADS); glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,-1.0f,0.0); glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f,0.0); glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 0.0f); glVertex3f( 1.0f, 1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 1.0f); glVertex3f( 1.0f,-1.0f,-DEPTH); glEnd(); /* Left */ glBegin(GL_QUADS); glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f,0.0); glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f,0.0); glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 1.0f); glVertex3f(-1.0f, 1.0f,-DEPTH); glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 0.0f); glVertex3f(-1.0f,-1.0f,-DEPTH); glEnd(); } glDisable(GL_TEXTURE_2D); PrintInfo(); glutSwapBuffers(); }