Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: volfog hacking

File size: 5.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//#include "shell_command.h"
22
23#define GLX_GLXEXT_PROTOTYPES
24#include <GL/glx.h>
25
26//#include <GL/glext.h> //OpenGL Extensions
27//#include <GL/glxext.h> // GLX Extensions
28
29#ifndef GL_EXT_fog_coord
30#define GL_EXT_fog_coord 1
31
32typedef void (APIENTRY * PFNGLFOGCOORDFEXTPROC) (GLfloat coord);
33typedef void (APIENTRY * PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord);
34typedef void (APIENTRY * PFNGLFOGCOORDDEXTPROC) (GLdouble coord);
35typedef void (APIENTRY * PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord);
36typedef void (APIENTRY * PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer);
37#endif
38
39PFNGLFOGCOORDFEXTPROC glFogCoordfEXT = 0;
40PFNGLFOGCOORDFVEXTPROC glFogCoordfvEXT = 0;
41PFNGLFOGCOORDDEXTPROC glFogCoorddEXT = 0;
42PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT = 0;
43PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT = 0;
44
45
46using namespace std;
47
48CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT);
49
50VolFogEffect::VolFogEffect(const TiXmlElement* root)
51{
52        this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect");
53
54        if (root != NULL)
55                this->loadParams(root);
56
57        // Initialize Effect
58        this->init();
59
60        // Activate Effect
61        this->activate();
62}
63
64
65VolFogEffect::~VolFogEffect()
66{
67        this->deactivate();
68}
69
70void VolFogEffect::loadParams(const TiXmlElement* root)
71{
72        WeatherEffect::loadParams(root);
73}
74
75bool VolFogEffect::init()
76{
77        PRINTF(0)("Initalize VolFogEffect\n");
78
79        // set fog mode
80        GLenum fogMode  = GL_EXP2;
81
82        // set fog density
83        float  fogDensity  = 0.03f;
84
85        // set fog near & far distance
86        float fogStart = 0.05f;
87        float fogEnd   = 100.0f;
88
89        // Set fog color
90        float fogColor[4] = {0.0, 1.0, 0.0, 1.0};
91       
92        glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f);
93        glShadeModel(GL_SMOOTH);
94        glEnable(GL_DEPTH_TEST);
95        glEnable(GL_CULL_FACE);
96        glCullFace(GL_BACK);
97
98        glFogCoordfEXT       = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT");
99        glFogCoordfvEXT      = (PFNGLFOGCOORDFVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfvEXT");
100        glFogCoorddEXT       = (PFNGLFOGCOORDDEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddEXT");
101        glFogCoorddvEXT      = (PFNGLFOGCOORDDVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddvEXT");
102        glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordPointerEXT");
103
104        // set the fog attributes
105        glFogf (GL_FOG_START,  fogStart);
106        glFogf (GL_FOG_END,    fogEnd);
107        glFogfv(GL_FOG_COLOR,  fogColor);     
108        glFogi (GL_FOG_MODE,   fogMode);
109        glFogf (GL_FOG_DENSITY,fogDensity);
110        glFogi (GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT);
111
112        // enable the fog
113        glEnable(GL_FOG);
114
115        if (glewInit() == GLEW_OK)
116                PRINTF(0)("glewInit OK\n");
117        else
118                PRINTF(0)("glewInit failed\n");
119
120        if (glewGetExtension("GL_EXT_fog_coord"))
121        {
122                PRINTF(0)("GL_EXT_fog_coord extension found\n");
123                return true;
124        }
125        else
126        {
127                PRINTF(0)("GL_EXT_fog_coord extension NOT found\n");
128                return false;
129        }
130}
131
132
133bool VolFogEffect::activate()
134{
135        PRINTF(0)("Activating VolFogEffect\n");
136}
137
138bool VolFogEffect::deactivate()
139{
140        PRINTF(0)("Deactivating VolFogEffect\n");
141}
142
143
144/**
145* draws the effect, if needed
146*/
147void VolFogEffect::draw() const
148{
149       
150        /* clear all pixels in colour buffer */
151        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
152
153        /* Enable blending */
154        //glEnable(GL_BLEND);
155        //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
156
157        /* draw the panels */
158        glBegin(GL_QUADS); // Floor
159                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
160                glFogCoordfEXT(0.0f);   glVertex3f(100.0f,0.0f,0.0f);
161                glFogCoordfEXT(0.0f);   glVertex3f(100.0f,0.0f, 100.0f);
162                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f, 100.0f);
163        glEnd();
164
165        glBegin(GL_QUADS); // Roof
166                glFogCoordfEXT(1.0f);   glVertex3f(0.0f, 100.0f,0.0f);
167                glFogCoordfEXT(1.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
168                glFogCoordfEXT(1.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
169                glFogCoordfEXT(1.0f);   glVertex3f(0.0f, 100.0f, 100.0f);
170        glEnd();
171
172        glBegin(GL_QUADS); // Back Wall
173                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
174                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
175                glFogCoordfEXT(1.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
176                glFogCoordfEXT(1.0f);   glVertex3f(0.0f, 100.0f,0.0f);
177        glEnd();
178
179        glBegin(GL_QUADS); // Front Wall
180                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,100.0f);
181                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,100.0f);
182                glFogCoordfEXT(1.0f);   glVertex3f( 100.0f, 100.0f,100.0f);
183                glFogCoordfEXT(1.0f);   glVertex3f(0.0f, 100.0f,100.0f);
184        glEnd();
185
186        glBegin(GL_QUADS); // Right Wall
187                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f, 100.0f);
188                glFogCoordfEXT(1.0f);   glVertex3f( 100.0f, 100.0f, 100.0f);
189                glFogCoordfEXT(1.0f);   glVertex3f( 100.0f, 100.0f,0.0f);
190                glFogCoordfEXT(0.0f);   glVertex3f( 100.0f,0.0f,0.0f);
191        glEnd();
192
193        glBegin(GL_QUADS); // Left Wall
194                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f, 100.0f);
195                glFogCoordfEXT(1.0f);   glVertex3f(0.0f, 100.0f, 100.0f);
196                glFogCoordfEXT(1.0f);   glVertex3f(0.0f, 100.0f,0.0f);
197                glFogCoordfEXT(0.0f);   glVertex3f(0.0f,0.0f,0.0f);
198        glEnd();
199       
200        /* process all buffered OpenGL commands */
201        glFlush();
202
203}
204
205
206/**
207* ticks the effect if there is any time dependancy
208*/
209void VolFogEffect::tick(float dt)       
210{
211}
Note: See TracBrowser for help on using the repository browser.