Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8175 in orxonox.OLD


Ignore:
Timestamp:
Jun 6, 2006, 6:34:02 PM (18 years ago)
Author:
amaechler
Message:

branches/atmospheric_engine: new cloud implementation using shaders, not yet working - wanna fix it? :) look at source and the demo mentioned there

Location:
branches/atmospheric_engine/src/lib/graphics/effects
Files:
1 added
2 edited

Legend:

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

    r8119 r8175  
    1111### File Specific:
    1212        main-programmer: hdavid, amaechler
    13         Taken from SkySphere
     13
     14        INSPIRED BY http://www.codesampler.com/usersrc/usersrc_6.htm#oglu_sky_dome_shader
    1415*/
    15 
    16 // TODO: Vektortextur erzeugen und Regionen auswaehlen, Sky...
    1716
    1817#include "cloud_effect.h"
     
    2019#include "util/loading/load_param.h"
    2120#include "util/loading/factory.h"
     21#include "util/loading/resource_manager.h"
    2222
    2323#include "glincl.h"
    2424#include "material.h"
    2525#include <math.h>
    26 #include "material.h"
    2726#include "state.h"
    2827#include "p_node.h"
     28#include "shader.h"
    2929
    3030#include "parser/tinyxml/tinyxml.h"
     31
     32#include "sglmodel.h"
    3133
    3234using namespace std;
     
    5052        this->deactivate();
    5153
    52         //delete this->skyMaterial;
    53         //gluDeleteQuadric(this->sphereObj);
     54        delete this->cloudMaterial;
     55
     56        g_sky_model.Delete();
     57        Shader::unload(this->skyShader);
     58
    5459}
    5560
     
    5964        PRINTF(1)("Initializing CloudEffect\n");
    6065
    61         this->sphereObj = gluNewQuadric();
    62         //this->setParentMode(PNODE_MOVEMENT);
    63 
    64         gluQuadricTexture(this->sphereObj, GL_TRUE);
    65         gluQuadricOrientation(this->sphereObj, GLU_INSIDE);
    66 
    67         this->setRadius(1900.0);
    68 
    69         mover = 0.0f;
    70 
    71         // Initializing default values
    72         this->cloudSpeed = 1.0f;
     66        // glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     67        glShadeModel(GL_SMOOTH);
     68        glEnable(GL_DEPTH_TEST);
     69        glEnable(GL_CULL_FACE);
     70        glCullFace(GL_BACK);
     71        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     72       
     73        glLineWidth(3.0f);
     74       
     75        float diffuse[]  = {1.0f, 1.0f, 1.0f, 1.0f};
     76        float position[] = {0.0f, 2.0f, 0.0f, 1.0f};
     77        float specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
     78       
     79        glEnable(GL_LIGHTING);
     80        glEnable( GL_LIGHT0);
     81        glLightfv(GL_LIGHT0, GL_DIFFUSE,  diffuse);
     82        glLightfv(GL_LIGHT0, GL_POSITION, position);
     83        glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
     84       
     85        float shininess = 5.0f;
     86        glEnable(GL_COLOR_MATERIAL);
     87        glMaterialf( GL_FRONT, GL_SHININESS, shininess);
     88        glMaterialfv(GL_FRONT, GL_SPECULAR,  specular);
     89
    7390        this->cloudTexture = "pictures/sky/cloud1.jpg";
     91
     92        g_sky_model.Load("sky.sgl");
     93        g_sky_model.Unitize();
     94
     95        /* Get the bounding box of the sky dome. */
     96        float bbox[3] = {0};
     97        g_sky_model.GetDimensions(bbox[0], bbox[1], bbox[2]);
     98       
     99        // this->skyShader = (Shader*)ResourceManager::getInstance()->load("shaders/sky.vert", SHADER, RP_GAME, "shaders/skyfrag");
     100        this->skyShader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/sky.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/sky.frag");
     101
     102        /* Tell the shader the bounding box of the sky dome. */
     103        this->skyShader->bindShader("bbox", bbox, 4);
     104
     105        //g_cloud_texture = 0;
     106
     107        g_tint[4] = ( 0.9f, 0.7f, 0.7f, 1.0f );
     108        g_scroll = 1.0f;
     109        time = 0.0f;
    74110}
    75111
     
    101137void CloudEffect::draw() const
    102138{
    103         /* TODO:
    104                 -Load a texture, for now from an existing image, a cloud texture
    105                 -Blend / Overlay this with a blue sky like in the tutorial
    106                 -Animate it (for now move it along the sky)
    107         */
     139
     140//      glMatrixMode(GL_MODELVIEW);
     141//      glPushMatrix();
     142//
     143//      // Move sphere along with the camera
     144//      Vector r = State::getCameraNode()->getAbsCoor();
     145//      glTranslatef(r.x, r.y, r.z);
     146//
     147//      // Sky movement
     148//      glRotatef(mover, 0, 0, 1);
     149//
     150//      cloudMaterial->select();
     151//      gluSphere(this->sphereObj, this->sphereRadius, 20, 20);
     152//      glPopMatrix();
     153
     154        // ******
    108155
    109156        glMatrixMode(GL_MODELVIEW);
    110157        glPushMatrix();
    111158
    112         // Move sphere along with the camera
    113         Vector r = State::getCameraNode()->getAbsCoor();
    114         glTranslatef(r.x, r.y, r.z);
    115 
    116         // Sky movement
    117         glRotatef(mover, 0, 0, 1);
    118 
    119         cloudMaterial->select();
    120         gluSphere(this->sphereObj, this->sphereRadius, 20, 20);
     159        static float time = 0.0f;
     160        // static vector3f eye = {0.0f, 0.0f, 0.0f}, look = {0.0f, 0.0f, 1.0f}, up = {0.0f, 1.0f, 0.0f};
     161
     162        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     163        // glLoadIdentity();
     164        // gluLookAt(eye[x], eye[y], eye[z], look[x], look[y], look[z], up[x], up[y], up[z]);
     165
     166        /* Turn off the depth buffer when rendering the background. */
     167        // glDisable(GL_DEPTH_TEST);
     168
     169        this->skyShader->activateShader();
     170
     171        /* Select the shader program and update parameters. */
     172        /* The "time" parameter controls the cloud scrolling. */
     173        this->skyShader->bindShader("time", &time, 1);
     174        /* The "horizon" parameter controls the sky tinting. */
     175        this->skyShader->bindShader("horizon", g_tint, 4);
     176       
     177        glActiveTexture(GL_TEXTURE0 + 0);
     178        glActiveTexture(GL_TEXTURE0 + 1);
     179        /* Load the cloud texture. */
     180        //glBindTexture(GL_TEXTURE_2D, g_cloud_texture);
     181        this->cloudMaterial->select();
     182       
     183        /* Render the sky dome. */
     184        g_sky_model.Render();
     185       
     186        /* Unselect the shader. */
     187        Shader::deactivateShader();
     188
     189        /* Turn on the depth buffer when rendering the foreground. */
     190        // glEnable(GL_DEPTH_TEST);
     191
     192        /* Render the forground, for example, a teapot or bunny. */
     193        //    glEnable(GL_LIGHTING);
     194        //    glColor3f(0.0f, 1.0f, 0.0f);
     195        //    glBegin(GL_QUADS);
     196        //    glNormal3f( 0.0f,  1.0f,  0.0f);
     197        //    glVertex3f( 20.0f, -1.0f,  20.0f);
     198        //    glVertex3f( 20.0f, -1.0f, -20.0f);
     199        //    glVertex3f(-20.0f, -1.0f, -20.0f);
     200        //    glVertex3f(-20.0f, -1.0f,  20.0f);
     201        //    glEnd();
     202        //    glDisable(GL_LIGHTING);
     203
    121204        glPopMatrix();
    122205}
     
    124207void CloudEffect::tick (float dt)
    125208{
    126         mover = mover + this->cloudSpeed * dt;
    127 }
    128 
    129 
    130 /**
    131 *  sets the Radius of the Sphere.
    132 * @param radius The Radius of The Sphere
    133 */
    134 void CloudEffect::setRadius(float radius)
    135 {
    136         this->sphereRadius = radius;
    137 }
    138 
    139 
     209        // mover = mover + this->cloudSpeed * dt;
     210
     211        /* Update the timer for scrolling the clouds. */
     212        time = time + ((1.0f / 2000.0f) * g_scroll);
     213}
     214
  • branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h

    r8119 r8175  
    1414#include "glincl.h"
    1515
     16#include "sglmodel.h"
     17
     18class Shader;
    1619class Material;
    1720class Vector;
     
    3336                virtual void tick(float dt);
    3437
    35                 void setRadius(float radius);
    36                 void setTexture(char* fileName);
     38                // void setRadius(float radius);
     39                // void setTexture(char* fileName);
    3740
    3841
     
    4043                void initialize(char* fileName);
    4144
    42                 GLUquadricObj*                  sphereObj;              // A Placeholder for the Sphere.
     45                // GLUquadricObj*               sphereObj;              // A Placeholder for the Sphere.
    4346                Material*                       cloudMaterial;          // A Material for the Sphere.
    4447                float                           sphereRadius;           // Radius of the Sphere.
     
    5154                inline void setCloudAnimation(float speed) { this->cloudSpeed = speed; }
    5255
     56                Sglmodel_sgl g_sky_model;
     57                Shader* skyShader;
     58
     59                float g_tint[4];
     60                float g_scroll;
     61
     62                float time;
     63
     64
    5365};
    5466
Note: See TracChangeset for help on using the changeset viewer.