Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc @ 7504

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

branches/atmospheric_engine: Added volumetric fogeffect files

File size: 2.6 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 "volfog_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(activateVolFog, VolFogEffect, VolFogEffect::activate)
24  ->setAlias("aVolFog");
25SHELL_COMMAND(deactivateVolFog, VolFogEffect, VolFogEffect::deactivate)
26  ->setAlias("dVolFog");*/
27
28using namespace std;
29
30CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT);
31
32VolFogEffect::VolFogEffect(const TiXmlElement* root)
33{
34  this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect");
35
36  this->volfogMode = GL_LINEAR;
37  this->volfogDensity = 0.001f;
38  this->volfogStart = 10.0f;
39  this->volfogEnd = 1000.0f;
40
41  if (root != NULL)
42    this->loadParams(root);
43
44  this->activate();
45}
46
47
48
49VolFogEffect::~VolFogEffect()
50{
51  this->deactivate();
52}
53
54
55void VolFogEffect::loadParams(const TiXmlElement* root)
56{
57  WeatherEffect::loadParams(root);
58
59  LoadParam(root, "volfog-mode", this, VolFogEffect, setVolFogMode);
60  LoadParam(root, "volfog-density", this, VolFogEffect, setVolFogDensity);
61  LoadParam(root, "volfog-color", this, VolFogEffect, setVolFogColor);
62
63
64}
65
66bool VolFogEffect::init()
67{}
68
69
70
71bool VolFogEffect::activate()
72{
73  PRINTF(0)( "Enabling VolFog Effect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->volfogMode, this->volfogDensity,
74             this->volfogStart, this->volfogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
75
76  glEnable(GL_FOG);
77  {
78    //GLfloat volfogColor[4] = {0.7, 0.6, 0.6, 1.0};
79    GLfloat volfogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
80
81    glFogi(GL_FOG_MODE, this->volfogMode);
82    glFogfv(GL_FOG_COLOR, volfogColor);
83    glFogf(GL_FOG_DENSITY, this->volfogDensity);
84    glHint(GL_FOG_HINT, GL_DONT_CARE);
85    glFogf(GL_FOG_START, this->volfogStart);
86    glFogf(GL_FOG_END, this->volfogEnd);
87
88    //glVolFogi(GL_VOLFOG_COORDINATE_SOURCE, GL_VOLFOG_COORDINATE);
89  }
90  glClearColor(0.5, 0.5, 0.5, 1.0);
91}
92
93
94
95bool VolFogEffect::deactivate()
96{
97  PRINTF(0)("Deactivating VolFog Effect");
98        glDisable(GL_FOG);
99}
100
101
102
103GLint VolFogEffect::stringToVolFogMode(const std::string& mode)
104{
105  if(mode == "GL_LINEAR")
106    return GL_LINEAR;
107  else if(mode == "GL_EXP")
108    return GL_EXP;
109  else if(mode == "GL_EXP2" )
110    return GL_EXP2;
111  else
112    return -1;
113}
114
115
Note: See TracBrowser for help on using the repository browser.