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
RevLine 
[7504]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);
[7532]33
[7557]34  // Initialize Effect
[7546]35  this->init();
36
[7557]37  // Activate Effect
[7504]38  this->activate();
39}
40
41
[7516]42VolFogEffect::~VolFogEffect()
[7504]43{
44  this->deactivate();
45}
46
47void VolFogEffect::loadParams(const TiXmlElement* root)
48{
49  WeatherEffect::loadParams(root);
50}
51
52bool VolFogEffect::init()
[7520]53{
[7523]54  PRINTF(0)("Initalize VolFogEffect\n");
[7568]55 
56  if (glewInit() == GLEW_OK)
57    PRINTF(0)("glewInit OK\n");
58  else
59    PRINTF(0)("glewInit failed\n");
[7504]60
[7557]61  // Set fog color
[7558]62  float fogColor[4] = {0.2, 0.2, 0.2, 1.0};
[7504]63
[7557]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
[7561]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
[7557]71  // glHint(GL_FOG_HINT, GL_NICEST);                            // Per-Pixel Fog Calculation
72
[7561]73  // glClearColor(0.0, 0.0, 0.0, 1.0);  //sets bg color?!
74
[7557]75  /* enable texturing & set texturing function */
[7558]76  // glEnable(GL_TEXTURE_2D);
77  // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
[7557]78
[7568]79  if (glewGetExtension("GL_EXT_fog_coord"))
[7546]80  {
[7568]81    PRINTF(0)("GL_EXT_fog_coord extension found\n");
82    return true;
[7546]83  }
[7568]84  else
85  {
86    PRINTF(0)("GL_EXT_fog_coord extension NOT found\n");
87    return false;
88  }
[7546]89}
90
91
[7504]92bool VolFogEffect::activate()
93{
[7546]94  PRINTF(0)("Activating VolFogEffect\n");
[7504]95}
96
97bool VolFogEffect::deactivate()
98{
[7546]99  PRINTF(0)("Deactivating VolFogEffect\n");
[7504]100}
101
[7520]102
[7516]103/**
104 * draws the effect, if needed
105 */
106void VolFogEffect::draw() const
[7519]107{
[7557]108        //glPushAttrib(GL_ENABLE_BIT);
109       
110        /* clear all pixels in colour buffer */
111        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[7530]112
[7568]113        //glEnable(GL_BLEND);
114        //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
[7558]115
[7557]116        //glLoadIdentity ();    // Reset The Modelview Matrix
[7520]117
[7557]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();
[7520]126
[7557]127        glBegin(GL_QUADS); // Roof
[7558]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);
[7557]132        glEnd();
[7520]133
[7557]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);
[7558]137                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
138                glFogCoordfEXT(5.0f);   glVertex3f(0.0f, 100.0f,0.0f);
[7557]139        glEnd();
[7520]140
[7557]141        glBegin(GL_QUADS); // Front Wall
[7558]142                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,100.0f);
[7557]143                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,100.0f);
[7561]144                glFogCoordfEXT(50.0f);  glVertex3f( 100.0f, 100.0f,100.0f);
145                glFogCoordfEXT(50.0f);  glVertex3f(0.0f, 100.0f,100.0f);
[7557]146        glEnd();
[7546]147
[7557]148        glBegin(GL_QUADS); // Right Wall
149                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f, 100.0f);
[7558]150                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
151                glFogCoordfEXT(5.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
[7557]152                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
153        glEnd();
[7546]154
[7557]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();
[7546]164
[7557]165        // glPopAttrib();
166}
[7546]167
168
[7516]169/**
170 * ticks the effect if there is any time dependancy
171 */
[7519]172void VolFogEffect::tick(float dt)       
173{
174}
Note: See TracBrowser for help on using the repository browser.