Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5266 in orxonox.OLD for trunk


Ignore:
Timestamp:
Sep 27, 2005, 4:10:26 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Shaders now work :)

Location:
trunk/src
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r5265 r5266  
    5555                  world_entities/player.cc \
    5656                  world_entities/npc.cc \
     57                  world_entities/npc2.cc \
    5758                  world_entities/environment.cc \
    5859                  world_entities/skysphere.cc \
     
    114115                 world_entities/player.h \
    115116                 world_entities/npc.h \
     117                 world_entities/npc2.h \
    116118                 world_entities/environment.h \
    117119                 world_entities/skysphere.h \
  • trunk/src/Makefile.in

    r5265 r5266  
    6666        orxonox-world_entity.$(OBJEXT) orxonox-camera.$(OBJEXT) \
    6767        orxonox-player.$(OBJEXT) orxonox-npc.$(OBJEXT) \
    68         orxonox-environment.$(OBJEXT) orxonox-skysphere.$(OBJEXT) \
    69         orxonox-skybox.$(OBJEXT) orxonox-terrain.$(OBJEXT) \
    70         orxonox-satellite.$(OBJEXT) \
     68        orxonox-npc2.$(OBJEXT) orxonox-environment.$(OBJEXT) \
     69        orxonox-skysphere.$(OBJEXT) orxonox-skybox.$(OBJEXT) \
     70        orxonox-terrain.$(OBJEXT) orxonox-satellite.$(OBJEXT) \
    7171        orxonox-character_attributes.$(OBJEXT) \
    7272        orxonox-test_entity.$(OBJEXT) orxonox-weapon_manager.$(OBJEXT) \
     
    114114@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-load_param.Po \
    115115@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-npc.Po \
     116@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-npc2.Po \
    116117@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-null_parent.Po \
    117118@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-orxonox.Po \
     
    316317                  world_entities/player.cc \
    317318                  world_entities/npc.cc \
     319                  world_entities/npc2.cc \
    318320                  world_entities/environment.cc \
    319321                  world_entities/skysphere.cc \
     
    375377                 world_entities/player.h \
    376378                 world_entities/npc.h \
     379                 world_entities/npc2.h \
    377380                 world_entities/environment.h \
    378381                 world_entities/skysphere.h \
     
    526529@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-load_param.Po@am__quote@
    527530@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-npc.Po@am__quote@
     531@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-npc2.Po@am__quote@
    528532@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-null_parent.Po@am__quote@
    529533@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-orxonox.Po@am__quote@
     
    923927@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    924928@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-npc.obj `if test -f 'world_entities/npc.cc'; then $(CYGPATH_W) 'world_entities/npc.cc'; else $(CYGPATH_W) '$(srcdir)/world_entities/npc.cc'; fi`
     929
     930orxonox-npc2.o: world_entities/npc2.cc
     931@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT orxonox-npc2.o -MD -MP -MF "$(DEPDIR)/orxonox-npc2.Tpo" -c -o orxonox-npc2.o `test -f 'world_entities/npc2.cc' || echo '$(srcdir)/'`world_entities/npc2.cc; \
     932@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/orxonox-npc2.Tpo" "$(DEPDIR)/orxonox-npc2.Po"; else rm -f "$(DEPDIR)/orxonox-npc2.Tpo"; exit 1; fi
     933@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='world_entities/npc2.cc' object='orxonox-npc2.o' libtool=no @AMDEPBACKSLASH@
     934@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/orxonox-npc2.Po' tmpdepfile='$(DEPDIR)/orxonox-npc2.TPo' @AMDEPBACKSLASH@
     935@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     936@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-npc2.o `test -f 'world_entities/npc2.cc' || echo '$(srcdir)/'`world_entities/npc2.cc
     937
     938orxonox-npc2.obj: world_entities/npc2.cc
     939@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT orxonox-npc2.obj -MD -MP -MF "$(DEPDIR)/orxonox-npc2.Tpo" -c -o orxonox-npc2.obj `if test -f 'world_entities/npc2.cc'; then $(CYGPATH_W) 'world_entities/npc2.cc'; else $(CYGPATH_W) '$(srcdir)/world_entities/npc2.cc'; fi`; \
     940@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/orxonox-npc2.Tpo" "$(DEPDIR)/orxonox-npc2.Po"; else rm -f "$(DEPDIR)/orxonox-npc2.Tpo"; exit 1; fi
     941@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='world_entities/npc2.cc' object='orxonox-npc2.obj' libtool=no @AMDEPBACKSLASH@
     942@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/orxonox-npc2.Po' tmpdepfile='$(DEPDIR)/orxonox-npc2.TPo' @AMDEPBACKSLASH@
     943@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     944@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-npc2.obj `if test -f 'world_entities/npc2.cc'; then $(CYGPATH_W) 'world_entities/npc2.cc'; else $(CYGPATH_W) '$(srcdir)/world_entities/npc2.cc'; fi`
    925945
    926946orxonox-environment.o: world_entities/environment.cc
  • trunk/src/lib/graphics/graphics_engine.cc

    r5265 r5266  
    2929
    3030using namespace std;
    31 
    32 
    33 #include "shader.h"
    3431
    3532/**
     
    274271  PRINTF(4)("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
    275272
    276   Shader* shader = new Shader("test.txt", "shader.cg");
    277 //  delete shader;
    278   shader->activateShader();
    279 //  exit(-1);
    280 
    281273}
    282274
     
    301293      //    return -1;
    302294    }
     295    glMatrixMode(GL_PROJECTION_MATRIX);
     296    glLoadIdentity();
    303297    glViewport(0,0,width,height);                                                   // Reset The Current Viewport
    304298}
  • trunk/src/lib/graphics/shader.cc

    r5264 r5266  
    1818#include "shader.h"
    1919
    20 
    21 #include "array.h"
    2220#include "stdlibincl.h"
    2321#include <stdio.h>
     
    4139   this->fragmentShaderFile = NULL;
    4240   this->vertexShaderFile = NULL;
    43    this->fragmentShaderSource = NULL;
    44    this->vertexShaderSource = NULL;
    45    this->fragmentShaderLengths = NULL;
    46    this->vertexShaderLenghts = NULL;
    4741   this->shaderProgram = 0;
    4842   this->vertexShader = 0;
     
    5044
    5145   if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
    52      this->shaderProgram = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
     46     this->shaderProgram = glCreateProgramObjectARB();
    5347
    5448   if (vertexShaderFile != NULL)
     
    8175  this->deleteProgram(type);
    8276
    83   FILE*    stream;           //< The stream we use to read the file.
    8477
    85   if( (stream = fopen (fileName, "r")) == NULL)
    86   {
    87     PRINTF(1)("Shader could not open %s\n", fileName);
    88     return false;
    89   }
    90   Array<char*>* program = new Array<char*>;
    91   Array<int>* lengths = new Array<int>;
    92   if (type == SHADER_VERTEX)
     78  const char* program = fileRead(fileName);
     79
     80  if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
    9381  {
    9482    this->vertexShaderFile = new char[strlen(fileName)+1];
    9583    strcpy(this->vertexShaderFile, fileName);
    96     this->vertexShaderSource = program;
    97     this->vertexShaderLenghts = lengths;
    98   }
    99   else
    100   {
    101     this->fragmentShaderFile = new char[strlen(fileName)+1];
    102     strcpy(this->fragmentShaderFile, fileName);
    103     this->fragmentShaderSource = program;
    104     this->fragmentShaderLengths = lengths;
    105   }
    10684
    107   char lineBuffer[PARSELINELENGHT];
    108   char* addString;
    109   while( !feof( stream))
    110   {
    111       // get next line
    112     fgets (lineBuffer, PARSELINELENGHT, stream);
    113 //     if (strchr(lineBuffer, '\n'))
    114 //     {
    115 //       addString = new char[strlen(lineBuffer)];
    116 //       strncpy(addString, lineBuffer, strlen (lineBuffer)-1);
    117 //       addString[strlen(lineBuffer)-1] ='\0';
    118 //     }
    119 //     else
    120     {
    121       addString = new char[strlen(lineBuffer)+1];
    122       strcpy(addString, lineBuffer);
    123     }
    124     program->addEntry(addString);
    125     lengths->addEntry(strlen(addString));
    126   }
    127   fclose(stream);
    128 
    129   program->finalizeArray();
    130   lengths->finalizeArray();
    131 
    132   if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
    133   {
    13485    this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    135     glShaderSourceARB(this->vertexShader, program->getCount(), (const GLcharARB**)program->getArray(), lengths->getArray());
     86    glShaderSourceARB(this->vertexShader, 1, (const GLcharARB**)&program, NULL);
    13687    glCompileShaderARB(this->vertexShader);
    13788    glAttachObjectARB(this->shaderProgram, this->vertexShader);
     
    14192  if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader)
    14293  {
     94    this->fragmentShaderFile = new char[strlen(fileName)+1];
     95    strcpy(this->fragmentShaderFile, fileName);
     96
    14397    this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    144     glShaderSourceARB(this->fragmentShader, program->getCount(), (const GLcharARB**)program->getArray(), lengths->getArray());
     98    glShaderSourceARB(this->fragmentShader, 1, (const GLcharARB**)&program, NULL);
    14599    glCompileShaderARB(this->fragmentShader);
    146100    glAttachObjectARB(this->shaderProgram, this->fragmentShader);
    147101    this->printError(this->fragmentShader);
    148102  }
     103
     104  delete[] program;
    149105}
    150106
    151 bool Shader::activateShader()
     107
     108char* Shader::fileRead(const char* fileName)
     109{
     110  FILE* fileHandle;
     111  char* content = NULL;
     112
     113  int count = 0;
     114
     115  if (fileName != NULL) {
     116    fileHandle = fopen(fileName, "rt");
     117
     118    if (fileHandle != NULL) {
     119
     120      fseek(fileHandle, 0, SEEK_END);
     121      count = ftell(fileHandle);
     122      rewind(fileHandle);
     123
     124      if (count > 0) {
     125        content = new char[count+1];
     126        count = fread(content, sizeof(char), count, fileHandle);
     127        content[count] = '\0';
     128      }
     129      fclose(fileHandle);
     130    }
     131  }
     132  return content;
     133}
     134
     135void Shader::activateShader()
    152136{
    153137  glUseProgramObjectARB(this->shaderProgram);
     138}
     139
     140void Shader::deactivateShader()
     141{
     142  glUseProgramObjectARB(0);
    154143}
    155144
     
    157146void Shader::deleteProgram(SHADER_TYPE type)
    158147{
    159   Array<char*>* deleteArray = NULL;
    160148  if (type == SHADER_VERTEX)
    161149  {
    162     deleteArray = this->vertexShaderSource;
    163     this->vertexShaderSource = NULL;
    164     delete this->vertexShaderLenghts;
    165     this->vertexShaderLenghts = NULL;
    166150    delete[] this->vertexShaderFile;
    167151    this->vertexShaderFile = NULL;
     
    171155  else if (type == SHADER_FRAGMENT)
    172156  {
    173     deleteArray = this->fragmentShaderSource;
    174     delete this->fragmentShaderLengths;
    175     this->fragmentShaderLengths = NULL;
    176     this->fragmentShaderSource = NULL;
    177157    delete[] this->fragmentShaderFile;
    178158    this->fragmentShaderFile = NULL;
     
    182162  else
    183163    return;
    184 
    185   if (deleteArray == NULL)
    186     return;
    187   else
    188   {
    189     deleteArray->finalizeArray();
    190     for (unsigned int i = 0; i < deleteArray->getCount(); i++)
    191     {
    192       delete[] deleteArray->getEntry(i);
    193     }
    194     delete deleteArray;
    195   }
    196164}
    197165
     
    214182  if (this->vertexShader != 0)
    215183  {
    216     PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);
     184/*    PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);
    217185    if (this->vertexShaderSource != NULL)
    218186      for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)
     
    224192    if (this->fragmentShaderSource != NULL)
    225193      for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)
    226         PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));
     194        PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/
    227195  }
    228196
  • trunk/src/lib/graphics/shader.h

    r5264 r5266  
    2020
    2121// FORWARD DECLARATION
    22 template<class T> class Array;
    2322
    2423
     
    3130
    3231  bool loadShaderProgramm(SHADER_TYPE type, const char* fileName);
    33   bool activateShader();
     32  void activateShader();
     33  static void deactivateShader();
    3434  void deleteProgram(SHADER_TYPE type);
     35
     36  char* fileRead(const char* fileName);
    3537
    3638  void printError(GLenum program);
     
    4244   char*                  fragmentShaderFile;
    4345   char*                  vertexShaderFile;
    44    Array<char*>*          fragmentShaderSource;
    45    Array<char*>*          vertexShaderSource;
    46    Array<int>*            fragmentShaderLengths;
    47    Array<int>*            vertexShaderLenghts;
    4846   GLenum                 shaderProgram;
    4947   GLenum                 vertexShader;
  • trunk/src/story_entities/world.cc

    r5260 r5266  
    7373#include "cd_engine.h"
    7474#include "npc.h"
     75#include "npc2.h"
    7576
    7677SHELL_COMMAND(speed, World, setSpeed);
     
    462463  for(int i = 0; i < 100; i++)
    463464  {
    464     WorldEntity* tmp = new NPC();
     465    WorldEntity* tmp = new NPC2();
    465466    char npcChar[10];
    466467    sprintf (npcChar, "NPC_%d", i);
  • trunk/src/world_entities/npc.cc

    r5259 r5266  
    3030  this->setClassID(CL_NPC, "NPC");
    3131
    32   this->loadModelWithScale("models/ships/bolido.obj", 5);
     32  this->loadModelWithScale("models/ships/bolido.obj", 2);
    3333
    3434  this->randomRotAxis = VECTOR_RAND(1);
  • trunk/src/world_entities/npc2.cc

    r5265 r5266  
    1717
    1818
    19 #include "npc.h"
     19#include "npc2.h"
    2020#include "obb_tree.h"
    2121
     22#include "shader.h"
    2223#include "state.h"
    2324#include "list.h"
     
    2627
    2728
    28 NPC::NPC()
     29NPC2::NPC2()
    2930{
    3031  this->setClassID(CL_NPC, "NPC");
    3132
    32   this->loadModelWithScale("models/ships/bolido.obj", 5);
     33  this->loadModelWithScale("models/ships/bolido.obj", 3);
     34  this->shader = new Shader("toon.vert", "toon.frag");
     35//  this->shader->activateShader();
     36  //exit(-1);
     37
     38  this->obj = gluNewQuadric();
    3339
    3440  this->randomRotAxis = VECTOR_RAND(1);
     
    3642
    3743
    38 NPC::~NPC () {}
     44NPC2::~NPC2 () {}
    3945
    4046
    41 void NPC::collidesWith(WorldEntity* entity, const Vector& location)
     47void NPC2::collidesWith(WorldEntity* entity, const Vector& location)
    4248{
    4349  if (entity->isA(CL_PROJECTILE))
     
    5662
    5763
    58 void NPC::tick(float dt)
     64/**
     65 *  the entity is drawn onto the screen with this function
     66 *
     67 * This is a central function of an entity: call it to let the entity painted to the screen.
     68 * Just override this function with whatever you want to be drawn.
     69 */
     70void NPC2::draw()
     71{
     72  glMatrixMode(GL_MODELVIEW);
     73  glPushMatrix();
     74  float matrix[4][4];
     75
     76  /* translate */
     77  glTranslatef (this->getAbsCoor ().x,
     78                this->getAbsCoor ().y,
     79                this->getAbsCoor ().z);
     80  /* rotate */
     81  this->getAbsDir ().matrix (matrix);
     82  glMultMatrixf((float*)matrix);
     83
     84  shader->activateShader();
     85  gluSphere(this->obj, 3, 20, 20);
     86  shader->deactivateShader();
     87
     88
     89/*  if (this->model)
     90    this->model->draw();*/
     91  glPopMatrix();
     92}
     93
     94
     95void NPC2::tick(float dt)
    5996{
    6097//  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
  • trunk/src/world_entities/npc2.h

    r5265 r5266  
    11
    2 #ifndef _NPC_H
    3 #define _NPC_H
     2#ifndef _NPC22_H
     3#define _NPC2_H
    44
    55#include "world_entity.h"
     
    77
    88class AI;
     9class Shader;
    910
    10 class NPC : public WorldEntity, public PhysicsInterface {
     11class NPC2 : public WorldEntity, public PhysicsInterface {
    1112
    1213 public:
    13   NPC ();
    14   ~NPC ();
     14  NPC2 ();
     15  ~NPC2 ();
    1516
    1617
     
    1819
    1920  virtual void tick(float dt);
     21  virtual void draw();
    2022
    2123  virtual void collidesWith (WorldEntity* entity, const Vector& location);
     
    2426 private:
    2527   Vector   randomRotAxis;
    26 
    27 ;
     28   Shader*  shader;
     29   GLUquadricObj* obj;
    2830
    2931};
    3032
    31 #endif /* _NPC_H */
     33#endif /* _NPC2_H */
Note: See TracChangeset for help on using the changeset viewer.