Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/volumetric_fog/src/world_entities/weather_effects/volfog_effect.cc @ 9937

Last change on this file since 9937 was 9937, checked in by hdavid, 17 years ago

branches/volumetric_fog

File size: 4.7 KB
Line 
1/*
2  orxonox - the future of 3D-vertical-scrollers
3
4  Copyright (C) 2006 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
13*/
14
15#include "volfog_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "p_node.h"
21#include "state.h"
22#include "shell_command.h"
23
24#include "glincl.h"
25#include "debug.h"
26
27//#include <GL/glext.h>
28#include <SDL.h>
29
30/*
31//////////////////////////////////
32#ifndef APIENTRY
33#define APIENTRY
34#endif
35#ifndef APIENTRYP
36#define APIENTRYP APIENTRY *
37#endif
38///////////////////////////////////
39*/
40#define GLX_GLXEXT_PROTOTYPES
41
42#include "class_id_DEPRECATED.h"
43ObjectListDefinitionID(VolFogEffect, CL_VOLFOG_EFFECT);
44CREATE_FACTORY(VolFogEffect);
45
46SHELL_COMMAND(activate, VolFogEffect, activateFog);
47SHELL_COMMAND(deactivate, VolFogEffect, deactivateFog);
48
49
50//typedef void (APIENTRY * PFNGLFOGCOORDFEXTPROC) (GLfloat coord);    // Declare Function Prototype
51//PFNGLFOGCOORDFEXTPROC glFogCoordfEXT = NULL;                        // Our glFogCoordfEXT Function
52
53
54VolFogEffect::VolFogEffect(const TiXmlElement* root) {
55  this->registerObject(this, VolFogEffect::_objectList);
56
57  if (root != NULL)
58      this->loadParams(root);
59
60  // Initialize Effect
61  this->init();
62
63  // Activate Effect
64  if(fogActivate)
65    this->activate();
66}
67
68
69VolFogEffect::~VolFogEffect() {
70  if(fogActivate)
71    this->deactivate();
72}
73
74void VolFogEffect::loadParams(const TiXmlElement* root) {
75  WeatherEffect::loadParams(root);
76}
77
78void VolFogEffect::init() {
79  PRINTF(0)("Initalize VolFogEffect\n");
80 
81  fogColor[0] = 0.6f;
82  fogColor[1] = 0.3f;
83  fogColor[2] = 0.0f;
84  fogColor[3] = 1.0f;
85
86  //fogActivate = false;
87fogActivate = true;
88}
89
90
91void VolFogEffect::activate() {
92  PRINTF(0)("Activating VolFogEffect\n");
93 
94  // Test whether the extension exists
95  if (!glewIsSupported("GL_EXT_fog_coord"))
96  {
97    PRINTF(0)("Can't activate volumetric fog, GL_EXT_fog_coord extension is misssing\n");
98    return;
99  }
100
101  // Set Up Fog
102  //glEnable(GL_FOG);                         // Enable Fog
103  glFogi(GL_FOG_MODE, GL_LINEAR);           // Fog Fade Is Linear
104  glFogfv(GL_FOG_COLOR, fogColor);          // Set The Fog Color
105  glFogf(GL_FOG_START,  1.0f);              // Set The Fog Start
106  glFogf(GL_FOG_END,    0.0f);              // Set The Fog End
107  glHint(GL_FOG_HINT, GL_NICEST);           // Per-Pixel Fog Calculation
108
109
110  glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC) SDL_GL_GetProcAddress("glFogCoordfEXT");
111
112  glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);    // Set Fog Based On Vertice Coordinates
113 
114  fogActivate = true;
115}
116
117void VolFogEffect::deactivate() {
118  PRINTF(0)("Deactivating VolFogEffect\n");
119 
120  fogActivate = false;
121}
122
123
124/**
125* draws the effect
126*/
127void VolFogEffect::draw() const {
128
129  if(!fogActivate)
130    return;
131
132  glPushAttrib(GL_ENABLE_BIT);
133  glDisable(GL_LIGHTING);
134  glDisable(GL_BLEND);
135glEnable(GL_FOG);                         // Enable Fog
136 
137  glPushMatrix();
138 
139
140
141glBegin(GL_QUADS);                          // Back Wall
142    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f);
143    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f);
144    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f);
145    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f);
146  glEnd();
147
148  glBegin(GL_QUADS);                          // Floor
149    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f);
150    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f);
151    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f);
152    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f);
153  glEnd();
154
155  glBegin(GL_QUADS);                          // Roof
156    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f);
157    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f);
158    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f);
159    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f);
160  glEnd();
161
162  glBegin(GL_QUADS);                          // Right Wall
163    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f,-2.5f, 15.0f);
164    glFogCoordfEXT( 1.0f); glVertex3f( 2.5f, 2.5f, 15.0f);
165    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f, 2.5f,-15.0f);
166    glFogCoordfEXT( 0.0f); glVertex3f( 2.5f,-2.5f,-15.0f);
167  glEnd();
168
169  glBegin(GL_QUADS);                          // Left Wall
170    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f,-2.5f, 15.0f);
171    glFogCoordfEXT( 1.0f); glVertex3f(-2.5f, 2.5f, 15.0f);
172    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f, 2.5f,-15.0f);
173    glFogCoordfEXT( 0.0f); glVertex3f(-2.5f,-2.5f,-15.0f);
174  glEnd();
175
176  glPopMatrix();
177  glPopAttrib();
178}
179
180
181/**
182* ticks the effect if there is any time dependancy
183*/
184void VolFogEffect::tick(float dt) {}
Note: See TracBrowser for help on using the repository browser.