Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weather_effects/volfog_effect.cc @ 10556

Last change on this file since 10556 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

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