Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/volfog_effect.cc @ 8697

Last change on this file since 8697 was 8523, checked in by bensch, 19 years ago

trunk: compiles on Windows: DANGER: THE LINUX PORT MAY BE COMPROMISED

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