Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: glFog implemented in AtmosEngine

File size: 2.7 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"
23/*SHELL_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->fogMode = GL_LINEAR;
37  this->fogDensity = 0.001f;
38  this->fogStart = 10.0f;
39  this->fogEnd = 1000.0f;
40
41  if (root != NULL)
42    this->loadParams(root);
43
44  this->activate();
45}
46
47
48
49FogEffect::~FogEffect()
50{
51  this->deactivate();
52}
53
54
55void FogEffect::loadParams(const TiXmlElement* root)
56{
57  WeatherEffect::loadParams(root);
58
59  LoadParam(root, "fog-mode", this, FogEffect, setFogMode);
60
61  LoadParam(root, "fog-density", this, FogEffect, setFogDensity);
62
63  LoadParam(root, "fog-color", this, FogEffect, setFogColor);
64
65  // LoadParam(root, "test", this, FogEffect, setTest);
66
67
68}
69
70void FogEffect::setTest(int test)
71{
72  PRINTF(0)("\n\ntest: %i\n\n", test);
73}
74
75bool FogEffect::init()
76{}
77
78
79
80bool FogEffect::activate()
81{
82  PRINTF(0)( "Enabling Fog Effect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity,
83             this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
84
85  /*PRINTF(0)( "Enabling Fog Effect, mode: %i, density: %f, start: %f, end: %f\n", this->fogMode, this->fogDensity,
86             this->fogStart, this->fogEnd);*/
87
88  glEnable(GL_FOG);
89  {
90    //GLfloat fogColor[4] = {0.7, 0.6, 0.6, 1.0};
91    GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
92
93    glFogi(GL_FOG_MODE, this->fogMode);
94    glFogfv(GL_FOG_COLOR, fogColor);
95    glFogf(GL_FOG_DENSITY, this->fogDensity);
96    glHint(GL_FOG_HINT, GL_DONT_CARE);
97    glFogf(GL_FOG_START, this->fogStart);
98    glFogf(GL_FOG_END, this->fogEnd);
99
100    //glFogi(GL_FOG_COORDINATE_SOURCE, GL_FOG_COORDINATE);
101  }
102  glClearColor(0.5, 0.5, 0.5, 1.0);
103}
104
105
106
107bool FogEffect::deactivate()
108{
109        glDisable(GL_FOG);
110}
111
112
113
114GLint FogEffect::stringToFogMode(const std::string& mode)
115{
116  if(mode == "GL_LINEAR")
117    return GL_LINEAR;
118  else if(mode == "GL_EXP")
119    return GL_EXP;
120  else if(mode == "GL_EXP2" )
121    return GL_EXP2;
122  else
123    return -1;
124}
125
126
Note: See TracBrowser for help on using the repository browser.