[6741] | 1 | /* |
---|
[7652] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[6741] | 3 | |
---|
[7652] | 4 | Copyright (C) 2004 orx |
---|
[6741] | 5 | |
---|
[7652] | 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. |
---|
[6741] | 10 | |
---|
| 11 | ### File Specific: |
---|
[7652] | 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 | |
---|
[7523] | 22 | /*#include "shell_command.h" |
---|
| 23 | SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate) |
---|
[7652] | 24 | ->setAlias("aFog"); |
---|
[7392] | 25 | SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate) |
---|
[7652] | 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 | { |
---|
[7652] | 34 | this->setClassID(CL_FOG_EFFECT, "FogEffect"); |
---|
| 35 | |
---|
| 36 | this->fogMode = GL_LINEAR; |
---|
[7683] | 37 | this->fogDensity = 0.1f; |
---|
| 38 | this->fogStart = 0.0f; |
---|
| 39 | this->fogEnd = 5000.0f; |
---|
| 40 | this->colorVector = Vector(0.7, 0.7, 0.7); |
---|
[7392] | 41 | |
---|
[7652] | 42 | if (root != NULL) |
---|
| 43 | this->loadParams(root); |
---|
[7107] | 44 | |
---|
[7652] | 45 | this->activate(); |
---|
[6741] | 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
[7379] | 49 | |
---|
[6741] | 50 | FogEffect::~FogEffect() |
---|
[6980] | 51 | { |
---|
[7652] | 52 | this->deactivate(); |
---|
[6980] | 53 | } |
---|
[6741] | 54 | |
---|
| 55 | |
---|
| 56 | void FogEffect::loadParams(const TiXmlElement* root) |
---|
| 57 | { |
---|
[7652] | 58 | WeatherEffect::loadParams(root); |
---|
[6741] | 59 | |
---|
[7652] | 60 | LoadParam(root, "fog-mode", this, FogEffect, setFogMode); |
---|
| 61 | LoadParam(root, "fog-density", this, FogEffect, setFogDensity); |
---|
| 62 | LoadParam(root, "fog-color", this, FogEffect, setFogColor); |
---|
[6980] | 63 | |
---|
[7107] | 64 | |
---|
[6741] | 65 | } |
---|
| 66 | |
---|
| 67 | bool FogEffect::init() |
---|
| 68 | {} |
---|
| 69 | |
---|
| 70 | |
---|
[7379] | 71 | |
---|
[6741] | 72 | bool FogEffect::activate() |
---|
[7392] | 73 | { |
---|
[7652] | 74 | PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z); |
---|
[6772] | 75 | |
---|
[7652] | 76 | glEnable(GL_FOG); |
---|
| 77 | { |
---|
| 78 | //GLfloat fogColor[4] = {0.7, 0.6, 0.6, 1.0}; |
---|
| 79 | GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; |
---|
[6741] | 80 | |
---|
[7652] | 81 | glFogi(GL_FOG_MODE, this->fogMode); |
---|
| 82 | glFogfv(GL_FOG_COLOR, fogColor); |
---|
| 83 | glFogf(GL_FOG_DENSITY, this->fogDensity); |
---|
| 84 | glHint(GL_FOG_HINT, GL_DONT_CARE); |
---|
| 85 | glFogf(GL_FOG_START, this->fogStart); |
---|
| 86 | glFogf(GL_FOG_END, this->fogEnd); |
---|
[6741] | 87 | |
---|
[7652] | 88 | //glFogi(GL_FOG_COORDINATE_SOURCE, GL_FOG_COORDINATE); |
---|
| 89 | } |
---|
| 90 | glClearColor(0.5, 0.5, 0.5, 1.0); |
---|
[6752] | 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
[6741] | 94 | bool FogEffect::deactivate() |
---|
[6772] | 95 | { |
---|
[7652] | 96 | PRINTF(0)("Deactivating FogEffect\n"); |
---|
[7392] | 97 | glDisable(GL_FOG); |
---|
[6772] | 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
[7392] | 101 | |
---|
[7221] | 102 | GLint FogEffect::stringToFogMode(const std::string& mode) |
---|
[6772] | 103 | { |
---|
[7652] | 104 | if(mode == "GL_LINEAR") |
---|
| 105 | return GL_LINEAR; |
---|
| 106 | else if(mode == "GL_EXP") |
---|
| 107 | return GL_EXP; |
---|
| 108 | else if(mode == "GL_EXP2" ) |
---|
| 109 | return GL_EXP2; |
---|
| 110 | else |
---|
| 111 | return -1; |
---|
[6772] | 112 | } |
---|
| 113 | |
---|
[7392] | 114 | |
---|