/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: hdavid, amaechler */ #include "volfog_effect.h" #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "glincl.h" #include "shell_command.h" using namespace std; CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); VolFogEffect::VolFogEffect(const TiXmlElement* root) { this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); if (root != NULL) this->loadParams(root); // Initialize Effect this->init(); // Activate Effect this->activate(); } VolFogEffect::~VolFogEffect() { this->deactivate(); } void VolFogEffect::loadParams(const TiXmlElement* root) { WeatherEffect::loadParams(root); } bool VolFogEffect::init() { PRINTF(0)("Initalize VolFogEffect\n"); if (glewInit() == GLEW_OK) PRINTF(0)("glewInit OK\n"); else PRINTF(0)("glewInit failed\n"); // Set fog color float fogColor[4] = {0.2, 0.2, 0.2, 1.0}; /* set up fog params */ glEnable(GL_FOG); // Enable Fog glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Fade Is Linear glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color glFogf(GL_FOG_START, 0.0f); // Set The Fog Start glFogf(GL_FOG_END, 10.0f); // Set The Fog End glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); // Set The Fog based on vertice coordinates // glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation // glClearColor(0.0, 0.0, 0.0, 1.0); //sets bg color?! /* enable texturing & set texturing function */ // glEnable(GL_TEXTURE_2D); // glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); if (glewGetExtension("GL_EXT_fog_coord")) { PRINTF(0)("GL_EXT_fog_coord extension found\n"); return true; } else { PRINTF(0)("GL_EXT_fog_coord extension NOT found\n"); return false; } } bool VolFogEffect::activate() { PRINTF(0)("Activating VolFogEffect\n"); } bool VolFogEffect::deactivate() { PRINTF(0)("Deactivating VolFogEffect\n"); } /** * draws the effect, if needed */ void VolFogEffect::draw() const { //glPushAttrib(GL_ENABLE_BIT); /* clear all pixels in colour buffer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); //glLoadIdentity (); // Reset The Modelview Matrix // glBindTexture(GL_TEXTURE_2D, 0); /* draw the panels */ glBegin(GL_QUADS); // Floor glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f,0.0f); glFogCoordfEXT(0.0f); glVertex3f(100.0f,0.0f, 100.0f); glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); glEnd(); glBegin(GL_QUADS); // Roof glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f,0.0f); glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f,0.0f); glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f, 100.0f); glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f, 100.0f); glEnd(); glBegin(GL_QUADS); // Back Wall glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f,0.0f); glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f,0.0f); glEnd(); glBegin(GL_QUADS); // Front Wall glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,100.0f); glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,100.0f); glFogCoordfEXT(50.0f); glVertex3f( 100.0f, 100.0f,100.0f); glFogCoordfEXT(50.0f); glVertex3f(0.0f, 100.0f,100.0f); glEnd(); glBegin(GL_QUADS); // Right Wall glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f, 100.0f); glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f, 100.0f); glFogCoordfEXT(5.0f); glVertex3f( 100.0f, 100.0f,0.0f); glFogCoordfEXT(0.0f); glVertex3f( 100.0f,0.0f,0.0f); glEnd(); glBegin(GL_QUADS); // Left Wall glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f, 100.0f); glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f, 100.0f); glFogCoordfEXT(5.0f); glVertex3f(0.0f, 100.0f,0.0f); glFogCoordfEXT(0.0f); glVertex3f(0.0f,0.0f,0.0f); glEnd(); /* process all buffered OpenGL commands */ glFlush(); // glPopAttrib(); } /** * ticks the effect if there is any time dependancy */ void VolFogEffect::tick(float dt) { }