Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc @ 7558

Last change on this file since 7558 was 7558, checked in by amaechler, 18 years ago

branches/atmospheric_engine: blenging?! and U2 sound:)

File size: 4.6 KB
Line 
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:
12   main-programmer: hdavid, amaechler
13*/
14
15#include "volfog_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "glincl.h"
21#include "shell_command.h"
22
23using namespace std;
24
25CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT);
26
27VolFogEffect::VolFogEffect(const TiXmlElement* root)
28{
29  this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect");
30
31  if (root != NULL)
32    this->loadParams(root);
33
34  // Initialize Effect
35  this->init();
36
37  // Activate Effect
38  this->activate();
39}
40
41
42VolFogEffect::~VolFogEffect()
43{
44  this->deactivate();
45}
46
47void VolFogEffect::loadParams(const TiXmlElement* root)
48{
49  WeatherEffect::loadParams(root);
50}
51
52bool VolFogEffect::init()
53{
54  PRINTF(0)("Initalize VolFogEffect\n");
55
56  // Set fog color
57  float fogColor[4] = {0.2, 0.2, 0.2, 1.0};
58
59  // glClearColor(0.0, 0.0, 0.0, 1.0);  //sets bg color?!
60
61  /* set up fog params */       
62  glEnable(GL_FOG);                                             // Enable Fog
63  glFogi(GL_FOG_MODE, GL_LINEAR);                               // Fog Fade Is Linear
64  glFogfv(GL_FOG_COLOR, fogColor);                              // Set The Fog Color
65  glFogf(GL_FOG_START, 0.0f);                                   // Set The Fog Start
66  glFogf(GL_FOG_END, 1.0f);                                     // Set The Fog End
67  glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
68  // glHint(GL_FOG_HINT, GL_NICEST);                            // Per-Pixel Fog Calculation
69
70  /* enable texturing & set texturing function */
71  // glEnable(GL_TEXTURE_2D);
72  // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
73
74  // *********************************************
75
76  char extensions[ 16384 ];
77  char Extension_Name[] = "GL_EXT_fog_coord";
78  char *buf;
79
80  sprintf( extensions, "%s", (char *)glGetString( GL_EXTENSIONS ) );
81  buf = strtok( extensions, " " );
82  while( buf != NULL )
83  {
84    if( !strcmp( Extension_Name, buf ) )
85    {
86      PRINTF(0)( "%s found, great.\n", Extension_Name );
87      return true;
88    }
89    buf = strtok( NULL, " " );
90  }
91
92  PRINTF(0)( "%s\n", (char *)glGetString( GL_EXTENSIONS ) );
93  PRINTF(0)( "%s not found.\n", Extension_Name );
94  return false;
95}
96
97
98bool VolFogEffect::activate()
99{
100  PRINTF(0)("Activating VolFogEffect\n");
101}
102
103bool VolFogEffect::deactivate()
104{
105  PRINTF(0)("Deactivating VolFogEffect\n");
106}
107
108
109/**
110 * draws the effect, if needed
111 */
112void VolFogEffect::draw() const
113{
114        //glPushAttrib(GL_ENABLE_BIT);
115       
116        /* clear all pixels in colour buffer */
117        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
118
119        // glPushAttrib(GL_ENABLE_BIT);
120
121        glEnable(GL_BLEND);
122        glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
123
124        //glLoadIdentity ();    // Reset The Modelview Matrix
125
126        // glBindTexture(GL_TEXTURE_2D, 0);
127        /* draw the panels */
128        glBegin(GL_QUADS); // Floor
129                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
130                glFogCoordfEXT(0.0f);   glVertex3f(100.0f,0.0f,0.0f);
131                glFogCoordfEXT(0.0f);   glVertex3f(100.0f,0.0f, 100.0f);
132                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f, 100.0f);
133        glEnd();
134
135        glBegin(GL_QUADS); // Roof
136                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
137                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
138                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
139                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f, 100.0f);
140        glEnd();
141
142        glBegin(GL_QUADS); // Back Wall
143                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
144                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
145                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
146                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
147        glEnd();
148
149        glBegin(GL_QUADS); // Front Wall
150                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,100.0f);
151                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,100.0f);
152                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,100.0f);
153                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,100.0f);
154        glEnd();
155
156        glBegin(GL_QUADS); // Right Wall
157                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f, 100.0f);
158                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
159                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
160                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
161        glEnd();
162
163        glBegin(GL_QUADS); // Left Wall
164                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f, 100.0f);
165                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f, 100.0f);
166                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
167                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
168        glEnd();
169       
170        /* process all buffered OpenGL commands */
171        glFlush();
172
173        // glPopAttrib();
174        // glPopAttrib();
175}
176
177
178/**
179 * ticks the effect if there is any time dependancy
180 */
181void VolFogEffect::tick(float dt)       
182{
183}
Note: See TracBrowser for help on using the repository browser.