[6741] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS |
---|
| 18 | |
---|
| 19 | #include "fog_effect.h" |
---|
| 20 | |
---|
[7193] | 21 | #include "util/loading/load_param.h" |
---|
| 22 | #include "util/loading/factory.h" |
---|
[6741] | 23 | |
---|
[6772] | 24 | #include "glincl.h" |
---|
[6741] | 25 | |
---|
[6772] | 26 | |
---|
| 27 | |
---|
[6741] | 28 | using namespace std; |
---|
| 29 | |
---|
[6772] | 30 | CREATE_FACTORY(FogEffect, CL_FOG_EFFECT); |
---|
[6741] | 31 | |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * default constructor |
---|
| 35 | * @param root The XML-element to load the FogEffect from |
---|
| 36 | */ |
---|
| 37 | FogEffect::FogEffect(const TiXmlElement* root) |
---|
| 38 | { |
---|
[6977] | 39 | this->setClassID(CL_FOG_EFFECT, "FogEffect"); |
---|
[6741] | 40 | |
---|
[7107] | 41 | this->fogMode = GL_LINEAR; |
---|
[6772] | 42 | this->fogDensity = 0.001f; |
---|
| 43 | this->fogStart = 10.0f; |
---|
| 44 | this->fogEnd = 1000.0f; |
---|
| 45 | |
---|
[6741] | 46 | if (root != NULL) |
---|
| 47 | this->loadParams(root); |
---|
[7107] | 48 | |
---|
| 49 | this->activate(); |
---|
[6741] | 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * destroys a FogEffect |
---|
| 55 | */ |
---|
| 56 | FogEffect::~FogEffect() |
---|
[6980] | 57 | { |
---|
| 58 | this->deactivate(); |
---|
| 59 | } |
---|
[6741] | 60 | |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * @param root The XML-element to load the FogEffect from |
---|
| 64 | */ |
---|
| 65 | void FogEffect::loadParams(const TiXmlElement* root) |
---|
| 66 | { |
---|
| 67 | GraphicsEffect::loadParams(root); |
---|
| 68 | |
---|
[6772] | 69 | |
---|
[6980] | 70 | LoadParam(root, "fog-mode", this, FogEffect, setFogMode) |
---|
| 71 | .describe("sets the the fog mode {GL_LINEAR, GL_EXP, GL_EXP2}"); |
---|
[6772] | 72 | |
---|
[6980] | 73 | LoadParam(root, "fog-density", this, FogEffect, setFogDensity) |
---|
| 74 | .describe("sets the the fog density of the exponentionl functions"); |
---|
| 75 | |
---|
[7107] | 76 | LoadParam(root, "fog-color", this, FogEffect, setFogColor) |
---|
| 77 | .describe("sets the fog color"); |
---|
| 78 | |
---|
[6741] | 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * initializes the fog effect |
---|
| 84 | */ |
---|
| 85 | bool FogEffect::init() |
---|
| 86 | {} |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * activates the fog effect |
---|
| 91 | */ |
---|
| 92 | bool FogEffect::activate() |
---|
[6752] | 93 | { |
---|
[7107] | 94 | PRINTF(0)( "Enabling Fog Effect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, |
---|
| 95 | this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z); |
---|
[6772] | 96 | |
---|
| 97 | glEnable(GL_FOG); |
---|
[6752] | 98 | { |
---|
[7107] | 99 | // GLfloat fogColor[4] = {0.7, 0.6, 0.6, 1.0}; |
---|
| 100 | GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; |
---|
[6741] | 101 | |
---|
[6772] | 102 | glFogi(GL_FOG_MODE, this->fogMode); |
---|
[6752] | 103 | glFogfv(GL_FOG_COLOR, fogColor); |
---|
[6772] | 104 | glFogf(GL_FOG_DENSITY, this->fogDensity); |
---|
| 105 | glHint(GL_FOG_HINT, GL_DONT_CARE); |
---|
| 106 | glFogf(GL_FOG_START, this->fogStart); |
---|
| 107 | glFogf(GL_FOG_END, this->fogEnd); |
---|
[6741] | 108 | |
---|
[6772] | 109 | //glFogi(GL_FOG_COORDINATE_SOURCE, GL_FOG_COORDINATE); |
---|
| 110 | } |
---|
| 111 | glClearColor(0.5, 0.5, 0.5, 1.0); |
---|
[6752] | 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
[6741] | 115 | /** |
---|
| 116 | * deactivates the fog effect |
---|
| 117 | */ |
---|
| 118 | bool FogEffect::deactivate() |
---|
[6772] | 119 | { |
---|
| 120 | glDisable(GL_FOG); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * converts a gl mode char to a GLint |
---|
| 126 | * @param mode the mode character |
---|
| 127 | */ |
---|
| 128 | GLint FogEffect::charToFogMode(const char* mode) |
---|
| 129 | { |
---|
| 130 | if( !strcmp( "GL_LINEAR", mode)) |
---|
| 131 | return GL_LINEAR; |
---|
| 132 | else if( !strcmp("GL_EXP", mode)) |
---|
| 133 | return GL_EXP; |
---|
| 134 | else if(!strcmp("GL_EXP2", mode) ) |
---|
| 135 | return GL_EXP2; |
---|
| 136 | else |
---|
| 137 | return -1; |
---|
| 138 | } |
---|
| 139 | |
---|