[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 | |
---|
| 21 | #include "load_param.h" |
---|
| 22 | #include "factory.h" |
---|
| 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 | /** |
---|
| 35 | * default constructor |
---|
| 36 | * @param root The XML-element to load the FogEffect from |
---|
| 37 | */ |
---|
| 38 | FogEffect::FogEffect(const TiXmlElement* root) |
---|
| 39 | { |
---|
| 40 | |
---|
[6772] | 41 | this->fogMode = GL_EXP2; |
---|
| 42 | this->fogDensity = 0.001f; |
---|
| 43 | this->fogStart = 10.0f; |
---|
| 44 | this->fogEnd = 1000.0f; |
---|
| 45 | |
---|
| 46 | |
---|
[6741] | 47 | if (root != NULL) |
---|
| 48 | this->loadParams(root); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * destroys a FogEffect |
---|
| 54 | */ |
---|
| 55 | FogEffect::~FogEffect() |
---|
| 56 | {} |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * @param root The XML-element to load the FogEffect from |
---|
| 61 | */ |
---|
| 62 | void FogEffect::loadParams(const TiXmlElement* root) |
---|
| 63 | { |
---|
| 64 | GraphicsEffect::loadParams(root); |
---|
| 65 | |
---|
[6772] | 66 | LoadParam(root, "fog-effect", this, FogEffect, setFogMode) |
---|
| 67 | .describe("sets the the fog mode {GL_LINEAR, GL_EXP, GL_EXP2}"); |
---|
| 68 | |
---|
| 69 | LoadParam(root, "fog-density", this, FogEffect, setFogDensity) |
---|
| 70 | .describe("sets the the fog density of the exponentionl functions"); |
---|
| 71 | |
---|
| 72 | LoadParam(root, "fog-range", this, FogEffect, setFogRange) |
---|
| 73 | .describe("sets the the range of the linear functions"); |
---|
[6741] | 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | * initializes the fog effect |
---|
| 79 | */ |
---|
| 80 | bool FogEffect::init() |
---|
| 81 | {} |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * activates the fog effect |
---|
| 86 | */ |
---|
| 87 | bool FogEffect::activate() |
---|
[6752] | 88 | { |
---|
[6772] | 89 | PRINTF(4)( "Enabling Fog Effect, mode: %i, density: %f, start: %f, end: %f\n", this->fogMode, this->fogDensity, |
---|
| 90 | this->fogStart, this->fogEnd); |
---|
| 91 | |
---|
| 92 | glEnable(GL_FOG); |
---|
[6752] | 93 | { |
---|
[6772] | 94 | GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0}; |
---|
[6741] | 95 | |
---|
[6772] | 96 | glFogi(GL_FOG_MODE, this->fogMode); |
---|
[6752] | 97 | glFogfv(GL_FOG_COLOR, fogColor); |
---|
[6772] | 98 | glFogf(GL_FOG_DENSITY, this->fogDensity); |
---|
| 99 | glHint(GL_FOG_HINT, GL_DONT_CARE); |
---|
| 100 | glFogf(GL_FOG_START, this->fogStart); |
---|
| 101 | glFogf(GL_FOG_END, this->fogEnd); |
---|
[6741] | 102 | |
---|
[6772] | 103 | //glFogi(GL_FOG_COORDINATE_SOURCE, GL_FOG_COORDINATE); |
---|
| 104 | } |
---|
| 105 | glClearColor(0.5, 0.5, 0.5, 1.0); |
---|
[6752] | 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
[6741] | 109 | /** |
---|
| 110 | * deactivates the fog effect |
---|
| 111 | */ |
---|
| 112 | bool FogEffect::deactivate() |
---|
[6772] | 113 | { |
---|
| 114 | glDisable(GL_FOG); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | * converts a gl mode char to a GLint |
---|
| 120 | * @param mode the mode character |
---|
| 121 | */ |
---|
| 122 | GLint FogEffect::charToFogMode(const char* mode) |
---|
| 123 | { |
---|
| 124 | if( !strcmp( "GL_LINEAR", mode)) |
---|
| 125 | return GL_LINEAR; |
---|
| 126 | else if( !strcmp("GL_EXP", mode)) |
---|
| 127 | return GL_EXP; |
---|
| 128 | else if(!strcmp("GL_EXP2", mode) ) |
---|
| 129 | return GL_EXP2; |
---|
| 130 | else |
---|
| 131 | return -1; |
---|
| 132 | } |
---|
| 133 | |
---|