[6741] | 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: |
---|
[7379] | 12 | main-programmer: hdavid, amaechler |
---|
[6741] | 13 | */ |
---|
| 14 | |
---|
| 15 | #include "fog_effect.h" |
---|
| 16 | |
---|
[7193] | 17 | #include "util/loading/load_param.h" |
---|
| 18 | #include "util/loading/factory.h" |
---|
[6741] | 19 | |
---|
[6772] | 20 | #include "glincl.h" |
---|
[6741] | 21 | |
---|
[7392] | 22 | #include "shell_command.h" |
---|
| 23 | /*SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate) |
---|
| 24 | ->setAlias("aFog"); |
---|
| 25 | SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate) |
---|
| 26 | ->setAlias("dFog");*/ |
---|
[6772] | 27 | |
---|
[6741] | 28 | using namespace std; |
---|
| 29 | |
---|
[6772] | 30 | CREATE_FACTORY(FogEffect, CL_FOG_EFFECT); |
---|
[6741] | 31 | |
---|
[7379] | 32 | FogEffect::FogEffect(const TiXmlElement* root) |
---|
[6741] | 33 | { |
---|
[7379] | 34 | //this->setClassID(CL_FOG_EFFECT, "FogEffect"); |
---|
[7392] | 35 | |
---|
[7107] | 36 | this->fogMode = GL_LINEAR; |
---|
[6772] | 37 | this->fogDensity = 0.001f; |
---|
| 38 | this->fogStart = 10.0f; |
---|
| 39 | this->fogEnd = 1000.0f; |
---|
[7392] | 40 | |
---|
[6741] | 41 | if (root != NULL) |
---|
| 42 | this->loadParams(root); |
---|
[7107] | 43 | |
---|
| 44 | this->activate(); |
---|
[6741] | 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
[7379] | 48 | |
---|
[6741] | 49 | FogEffect::~FogEffect() |
---|
[6980] | 50 | { |
---|
| 51 | this->deactivate(); |
---|
| 52 | } |
---|
[6741] | 53 | |
---|
| 54 | |
---|
| 55 | void FogEffect::loadParams(const TiXmlElement* root) |
---|
| 56 | { |
---|
[7381] | 57 | WeatherEffect::loadParams(root); |
---|
[6741] | 58 | |
---|
[7379] | 59 | LoadParam(root, "fog-mode", this, FogEffect, setFogMode); |
---|
[6772] | 60 | |
---|
[7379] | 61 | LoadParam(root, "fog-density", this, FogEffect, setFogDensity); |
---|
[6772] | 62 | |
---|
[7392] | 63 | LoadParam(root, "fog-color", this, FogEffect, setFogColor); |
---|
[6980] | 64 | |
---|
[7392] | 65 | // LoadParam(root, "test", this, FogEffect, setTest); |
---|
[7107] | 66 | |
---|
[7379] | 67 | |
---|
[6741] | 68 | } |
---|
| 69 | |
---|
[7379] | 70 | void FogEffect::setTest(int test) |
---|
| 71 | { |
---|
| 72 | PRINTF(0)("\n\ntest: %i\n\n", test); |
---|
| 73 | } |
---|
[6741] | 74 | |
---|
| 75 | bool FogEffect::init() |
---|
| 76 | {} |
---|
| 77 | |
---|
| 78 | |
---|
[7379] | 79 | |
---|
[6741] | 80 | bool FogEffect::activate() |
---|
[7392] | 81 | { |
---|
[7107] | 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); |
---|
[6772] | 84 | |
---|
[7392] | 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 | |
---|
[6772] | 88 | glEnable(GL_FOG); |
---|
[6752] | 89 | { |
---|
[7392] | 90 | //GLfloat fogColor[4] = {0.7, 0.6, 0.6, 1.0}; |
---|
[7107] | 91 | GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; |
---|
[6741] | 92 | |
---|
[6772] | 93 | glFogi(GL_FOG_MODE, this->fogMode); |
---|
[6752] | 94 | glFogfv(GL_FOG_COLOR, fogColor); |
---|
[6772] | 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); |
---|
[6741] | 99 | |
---|
[6772] | 100 | //glFogi(GL_FOG_COORDINATE_SOURCE, GL_FOG_COORDINATE); |
---|
| 101 | } |
---|
[7392] | 102 | glClearColor(0.5, 0.5, 0.5, 1.0); |
---|
[6752] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
[7379] | 106 | |
---|
[6741] | 107 | bool FogEffect::deactivate() |
---|
[6772] | 108 | { |
---|
[7392] | 109 | glDisable(GL_FOG); |
---|
[6772] | 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
[7392] | 113 | |
---|
[7221] | 114 | GLint FogEffect::stringToFogMode(const std::string& mode) |
---|
[6772] | 115 | { |
---|
[7221] | 116 | if(mode == "GL_LINEAR") |
---|
[6772] | 117 | return GL_LINEAR; |
---|
[7221] | 118 | else if(mode == "GL_EXP") |
---|
[6772] | 119 | return GL_EXP; |
---|
[7221] | 120 | else if(mode == "GL_EXP2" ) |
---|
[6772] | 121 | return GL_EXP2; |
---|
| 122 | else |
---|
| 123 | return -1; |
---|
| 124 | } |
---|
| 125 | |
---|
[7392] | 126 | |
---|