Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: volfog cleanup, still not working

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