From e9212bf1b65c573a2de6d49679d03dae09cd6e42 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 9 Jul 2009 22:03:29 +0100 Subject: [PATCH] Automatically make fog same colour as clear --- include/IFog.hpp | 3 +++ src/Fog.cpp | 9 +++++++++ src/Map.cpp | 5 +---- src/OpenGLHelper.cpp | 3 +++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/IFog.hpp b/include/IFog.hpp index 0edfecd..ca73d35 100644 --- a/include/IFog.hpp +++ b/include/IFog.hpp @@ -33,4 +33,7 @@ typedef std::tr1::shared_ptr IFogPtr; IFogPtr makeFog(float r, float g, float b, float density, float start, float end); +// Construct a fog from the current clear colour +IFogPtr makeFog(float density, float start, float end); + #endif diff --git a/src/Fog.cpp b/src/Fog.cpp index acb12f1..c3ad9d0 100644 --- a/src/Fog.cpp +++ b/src/Fog.cpp @@ -55,4 +55,13 @@ IFogPtr makeFog(float r, float g, float b, return IFogPtr(new Fog(r, g, b, density, start, end)); } +IFogPtr makeFog(float density, float start, float end) +{ + float params[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE, params); + + return makeFog(params[0], params[1], params[2], + density, start, end); +} + #endif diff --git a/src/Map.cpp b/src/Map.cpp index 773e564..3f89239 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -204,8 +204,7 @@ Map::Map() myStartDirection(axis::X), shouldDrawGridLines(false), inPickMode(false) { - myFog = makeFog(0.6f, 0.7f, 0.8f, // Colour - 0.25f, // Density + myFog = makeFog(0.25f, // Density 60.0f, 70.0f); // Start and end distance } @@ -382,8 +381,6 @@ void Map::render(IGraphicsPtr aContext) const { resetMarks(); - glClearColor(0.6f, 0.7f, 0.8f, 1.0f); - myFog->apply(); glPushAttrib(GL_ALL_ATTRIB_BITS); diff --git a/src/OpenGLHelper.cpp b/src/OpenGLHelper.cpp index d8b9b46..c207ad9 100644 --- a/src/OpenGLHelper.cpp +++ b/src/OpenGLHelper.cpp @@ -101,6 +101,9 @@ void initGL() glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // Clear to the sky colour + glClearColor(0.6f, 0.7f, 0.8f, 1.0f); + // Check for OpenGL extensions GLenum err = glewInit(); if (err != GLEW_OK) -- 2.39.2