Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7568 was 7568, checked in by hdavid, 18 years ago

/branches/atmospheric_engine: extension available check with glew

File size: 4.4 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  if (glewInit() == GLEW_OK)
57    PRINTF(0)("glewInit OK\n");
58  else
59    PRINTF(0)("glewInit failed\n");
60
61  // Set fog color
62  float fogColor[4] = {0.2, 0.2, 0.2, 1.0};
63
64  /* set up fog params */       
65  glEnable(GL_FOG);                                             // Enable Fog
66  glFogi(GL_FOG_MODE, GL_LINEAR);                               // Fog Fade Is Linear
67  glFogfv(GL_FOG_COLOR, fogColor);                              // Set The Fog Color
68  glFogf(GL_FOG_START, 0.0f);                                   // Set The Fog Start
69  glFogf(GL_FOG_END, 10.0f);                                    // Set The Fog End
70  glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);  // Set The Fog based on vertice coordinates
71  // glHint(GL_FOG_HINT, GL_NICEST);                            // Per-Pixel Fog Calculation
72
73  // glClearColor(0.0, 0.0, 0.0, 1.0);  //sets bg color?!
74
75  /* enable texturing & set texturing function */
76  // glEnable(GL_TEXTURE_2D);
77  // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
78
79  if (glewGetExtension("GL_EXT_fog_coord"))
80  {
81    PRINTF(0)("GL_EXT_fog_coord extension found\n");
82    return true;
83  }
84  else
85  {
86    PRINTF(0)("GL_EXT_fog_coord extension NOT found\n");
87    return false;
88  }
89}
90
91
92bool VolFogEffect::activate()
93{
94  PRINTF(0)("Activating VolFogEffect\n");
95}
96
97bool VolFogEffect::deactivate()
98{
99  PRINTF(0)("Deactivating VolFogEffect\n");
100}
101
102
103/**
104 * draws the effect, if needed
105 */
106void VolFogEffect::draw() const
107{
108        //glPushAttrib(GL_ENABLE_BIT);
109       
110        /* clear all pixels in colour buffer */
111        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
112
113        //glEnable(GL_BLEND);
114        //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
115
116        //glLoadIdentity ();    // Reset The Modelview Matrix
117
118        // glBindTexture(GL_TEXTURE_2D, 0);
119        /* draw the panels */
120        glBegin(GL_QUADS); // Floor
121                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
122                glFogCoordfEXT(0.0f);   glVertex3f(100.0f,0.0f,0.0f);
123                glFogCoordfEXT(0.0f);   glVertex3f(100.0f,0.0f, 100.0f);
124                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f, 100.0f);
125        glEnd();
126
127        glBegin(GL_QUADS); // Roof
128                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
129                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
130                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
131                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f, 100.0f);
132        glEnd();
133
134        glBegin(GL_QUADS); // Back Wall
135                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
136                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
137                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
138                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
139        glEnd();
140
141        glBegin(GL_QUADS); // Front Wall
142                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,100.0f);
143                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,100.0f);
144                glFogCoordfEXT(50.0f);  glVertex3f( 100.0f, 100.0f,100.0f);
145                glFogCoordfEXT(50.0f);  glVertex3f(0.0f, 100.0f,100.0f);
146        glEnd();
147
148        glBegin(GL_QUADS); // Right Wall
149                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f, 100.0f);
150                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
151                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
152                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
153        glEnd();
154
155        glBegin(GL_QUADS); // Left Wall
156                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f, 100.0f);
157                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f, 100.0f);
158                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
159                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
160        glEnd();
161       
162        /* process all buffered OpenGL commands */
163        glFlush();
164
165        // glPopAttrib();
166}
167
168
169/**
170 * ticks the effect if there is any time dependancy
171 */
172void VolFogEffect::tick(float dt)       
173{
174}
Note: See TracBrowser for help on using the repository browser.