Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7760 in orxonox.OLD for branches


Ignore:
Timestamp:
May 22, 2006, 2:08:44 PM (19 years ago)
Author:
amaechler
Message:

branches/atmospheric_engine: basic volfog (prob) working, weird values…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc

    r7759 r7760  
    1818#include "util/loading/factory.h"
    1919
     20#include "p_node.h"
     21#include "state.h"
     22
    2023#include "glincl.h"
    2124//#include "shell_command.h"
     
    2326#define GLX_GLXEXT_PROTOTYPES
    2427#include <GL/glx.h>
     28#include <GL/glut.h>
    2529
    2630//#include <GL/glext.h> //OpenGL Extensions
     
    7882
    7983        // set fog mode
    80         GLenum fogMode  = GL_EXP2;
     84        GLenum fogMode  = GL_EXP;
    8185
    8286        // set fog density
    83         float  fogDensity  = 0.03f;
     87        float  fogDensity  = 0.001f;
    8488
    8589        // set fog near & far distance
    86         float fogStart = 0.05f;
    87         float fogEnd   = 100.0f;
     90        float fogStart = 0.0f;
     91        float fogEnd   = 1000.0f;
    8892
    8993        // Set fog color
    90         float fogColor[4] = {0.0, 1.0, 0.0, 1.0};
     94        float fogColor[4] = {0.6f,0.58f,0.79f,0.0f};
    9195       
    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);
    9796
    9897        glFogCoordfEXT       = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT");
     
    105104        glFogf (GL_FOG_START,  fogStart);
    106105        glFogf (GL_FOG_END,    fogEnd);
    107         glFogfv(GL_FOG_COLOR,  fogColor);     
     106        glFogfv(GL_FOG_COLOR,  fogColor);
    108107        glFogi (GL_FOG_MODE,   fogMode);
    109108        glFogf (GL_FOG_DENSITY,fogDensity);
     
    139138{
    140139        PRINTF(0)("Deactivating VolFogEffect\n");
     140
     141        glDisable(GL_FOG);
    141142}
    142143
     
    147148void VolFogEffect::draw() const
    148149{
    149        
     150  glPushAttrib(GL_ENABLE_BIT);
     151  glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f);
     152        glShadeModel(GL_SMOOTH);
     153        glEnable(GL_DEPTH_TEST);
     154        glEnable(GL_CULL_FACE);
     155        glCullFace(GL_BACK);
     156
    150157        /* clear all pixels in colour buffer */
    151158        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    154161        //glEnable(GL_BLEND);
    155162        //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       
     164        int i;
     165        //glLoadIdentity();
     166
     167       
     168        glBegin( GL_LINES );
     169                glNormal3f(0,1,0);
     170                for(i=-20;i<=20;i+=2)
     171                {
     172                        float fog_c;
     173                        float diff[3];
     174
     175                        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     176                        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     177                        diff[1] = State::getCameraNode()->getAbsCoor().y;
     178                        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     179                        glFogCoordfEXT(fog_c*2);
     180                        glVertex3f(i,0,-20);
     181
     182                        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     183                        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     184                        diff[1] = State::getCameraNode()->getAbsCoor().y;
     185                        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     186                        glFogCoordfEXT(fog_c*2);
     187                        glVertex3f(i,0,20);
     188
     189                        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     190                        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     191                        diff[1] = State::getCameraNode()->getAbsCoor().y;
     192                        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     193                        glFogCoordfEXT(fog_c*2);
     194                        glVertex3f(-20,0,i);
     195
     196                        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     197                        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     198                        diff[1] = State::getCameraNode()->getAbsCoor().y;
     199                        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     200                        glFogCoordfEXT(fog_c*2);
     201                        glVertex3f(20,0,i);
     202                }
    163203        glEnd();
    164204
    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();
     205  glPopAttrib();
    202206
    203207}
Note: See TracChangeset for help on using the changeset viewer.