Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/fog_effect.cc @ 7689

Last change on this file since 7689 was 7689, checked in by amaechler, 18 years ago

branches/atmosphere_engine: fog weirdness…

File size: 2.3 KB
Line 
1/*
2        orxonox - the future of 3D-vertical-scrollers
3
4        Copyright (C) 2004 orx
5
6        This program is free software; you can redistribute it and/or modify
7        it under the terms of the GNU General Public License as published by
8        the Free Software Foundation; either version 2, or (at your option)
9        any later version.
10
11### File Specific:
12        main-programmer: hdavid, amaechler
13*/
14
15#include "fog_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "glincl.h"
21
22/*#include "shell_command.h"
23SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate)
24        ->setAlias("aFog");
25SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate)
26        ->setAlias("dFog");*/
27
28using namespace std;
29
30CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
31
32FogEffect::FogEffect(const TiXmlElement* root)
33{
34        this->setClassID(CL_FOG_EFFECT, "FogEffect");
35
36        this->init();
37
38        if (root != NULL)
39                this->loadParams(root);
40
41        this->activate();
42}
43
44
45FogEffect::~FogEffect()
46{
47        this->deactivate();
48}
49
50
51void FogEffect::loadParams(const TiXmlElement* root)
52{
53        WeatherEffect::loadParams(root);
54
55        LoadParam(root, "fog-mode", this, FogEffect, setFogMode);
56        LoadParam(root, "fog-density", this, FogEffect, setFogDensity);
57        LoadParam(root, "fog-color", this, FogEffect, setFogColor);
58}
59
60bool FogEffect::init()
61{
62        //default values
63        this->fogMode = GL_LINEAR;
64        this->fogDensity = 0.1;
65        this->fogStart = 0;
66        this->fogEnd = 5000;
67  this->colorVector = Vector(0.7, 0.7, 0.7);
68}
69
70
71
72bool FogEffect::activate()
73{
74        PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
75
76        glEnable(GL_FOG);
77        {
78                GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
79
80                glFogi(GL_FOG_MODE, this->fogMode);
81                glFogfv(GL_FOG_COLOR, fogColor);
82                glFogf(GL_FOG_DENSITY, this->fogDensity);
83                glHint(GL_FOG_HINT, GL_DONT_CARE);
84                glFogf(GL_FOG_START, this->fogStart);
85                glFogf(GL_FOG_END, this->fogEnd);
86        }
87        glClearColor(0.5, 0.5, 0.5, 1.0);
88}
89
90
91bool FogEffect::deactivate()
92{
93        PRINTF(0)("Deactivating FogEffect\n");
94        glDisable(GL_FOG);
95}
96
97
98GLint FogEffect::stringToFogMode(const std::string& mode)
99{
100        if(mode == "GL_LINEAR")
101                return GL_LINEAR;
102        else if(mode == "GL_EXP")
103                return GL_EXP;
104        else if(mode == "GL_EXP2" )
105                return GL_EXP2;
106        else
107                return -1;
108}
109
110
Note: See TracBrowser for help on using the repository browser.