- Timestamp:
- Sep 27, 2005, 4:10:26 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r5265 r5266 55 55 world_entities/player.cc \ 56 56 world_entities/npc.cc \ 57 world_entities/npc2.cc \ 57 58 world_entities/environment.cc \ 58 59 world_entities/skysphere.cc \ … … 114 115 world_entities/player.h \ 115 116 world_entities/npc.h \ 117 world_entities/npc2.h \ 116 118 world_entities/environment.h \ 117 119 world_entities/skysphere.h \ -
trunk/src/Makefile.in
r5265 r5266 66 66 orxonox-world_entity.$(OBJEXT) orxonox-camera.$(OBJEXT) \ 67 67 orxonox-player.$(OBJEXT) orxonox-npc.$(OBJEXT) \ 68 orxonox- environment.$(OBJEXT) orxonox-skysphere.$(OBJEXT) \69 orxonox-sky box.$(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) \ 71 71 orxonox-character_attributes.$(OBJEXT) \ 72 72 orxonox-test_entity.$(OBJEXT) orxonox-weapon_manager.$(OBJEXT) \ … … 114 114 @AMDEP_TRUE@ ./$(DEPDIR)/orxonox-load_param.Po \ 115 115 @AMDEP_TRUE@ ./$(DEPDIR)/orxonox-npc.Po \ 116 @AMDEP_TRUE@ ./$(DEPDIR)/orxonox-npc2.Po \ 116 117 @AMDEP_TRUE@ ./$(DEPDIR)/orxonox-null_parent.Po \ 117 118 @AMDEP_TRUE@ ./$(DEPDIR)/orxonox-orxonox.Po \ … … 316 317 world_entities/player.cc \ 317 318 world_entities/npc.cc \ 319 world_entities/npc2.cc \ 318 320 world_entities/environment.cc \ 319 321 world_entities/skysphere.cc \ … … 375 377 world_entities/player.h \ 376 378 world_entities/npc.h \ 379 world_entities/npc2.h \ 377 380 world_entities/environment.h \ 378 381 world_entities/skysphere.h \ … … 526 529 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-load_param.Po@am__quote@ 527 530 @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@ 528 532 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-null_parent.Po@am__quote@ 529 533 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-orxonox.Po@am__quote@ … … 923 927 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 924 928 @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 930 orxonox-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 938 orxonox-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` 925 945 926 946 orxonox-environment.o: world_entities/environment.cc -
trunk/src/lib/graphics/graphics_engine.cc
r5265 r5266 29 29 30 30 using namespace std; 31 32 33 #include "shader.h"34 31 35 32 /** … … 274 271 PRINTF(4)("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); 275 272 276 Shader* shader = new Shader("test.txt", "shader.cg");277 // delete shader;278 shader->activateShader();279 // exit(-1);280 281 273 } 282 274 … … 301 293 // return -1; 302 294 } 295 glMatrixMode(GL_PROJECTION_MATRIX); 296 glLoadIdentity(); 303 297 glViewport(0,0,width,height); // Reset The Current Viewport 304 298 } -
trunk/src/lib/graphics/shader.cc
r5264 r5266 18 18 #include "shader.h" 19 19 20 21 #include "array.h"22 20 #include "stdlibincl.h" 23 21 #include <stdio.h> … … 41 39 this->fragmentShaderFile = NULL; 42 40 this->vertexShaderFile = NULL; 43 this->fragmentShaderSource = NULL;44 this->vertexShaderSource = NULL;45 this->fragmentShaderLengths = NULL;46 this->vertexShaderLenghts = NULL;47 41 this->shaderProgram = 0; 48 42 this->vertexShader = 0; … … 50 44 51 45 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100) 52 this->shaderProgram = glCreate ShaderObjectARB(GL_VERTEX_SHADER_ARB);46 this->shaderProgram = glCreateProgramObjectARB(); 53 47 54 48 if (vertexShaderFile != NULL) … … 81 75 this->deleteProgram(type); 82 76 83 FILE* stream; //< The stream we use to read the file.84 77 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) 93 81 { 94 82 this->vertexShaderFile = new char[strlen(fileName)+1]; 95 83 strcpy(this->vertexShaderFile, fileName); 96 this->vertexShaderSource = program;97 this->vertexShaderLenghts = lengths;98 }99 else100 {101 this->fragmentShaderFile = new char[strlen(fileName)+1];102 strcpy(this->fragmentShaderFile, fileName);103 this->fragmentShaderSource = program;104 this->fragmentShaderLengths = lengths;105 }106 84 107 char lineBuffer[PARSELINELENGHT];108 char* addString;109 while( !feof( stream))110 {111 // get next line112 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 // else120 {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 {134 85 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); 136 87 glCompileShaderARB(this->vertexShader); 137 88 glAttachObjectARB(this->shaderProgram, this->vertexShader); … … 141 92 if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader) 142 93 { 94 this->fragmentShaderFile = new char[strlen(fileName)+1]; 95 strcpy(this->fragmentShaderFile, fileName); 96 143 97 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); 145 99 glCompileShaderARB(this->fragmentShader); 146 100 glAttachObjectARB(this->shaderProgram, this->fragmentShader); 147 101 this->printError(this->fragmentShader); 148 102 } 103 104 delete[] program; 149 105 } 150 106 151 bool Shader::activateShader() 107 108 char* 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 135 void Shader::activateShader() 152 136 { 153 137 glUseProgramObjectARB(this->shaderProgram); 138 } 139 140 void Shader::deactivateShader() 141 { 142 glUseProgramObjectARB(0); 154 143 } 155 144 … … 157 146 void Shader::deleteProgram(SHADER_TYPE type) 158 147 { 159 Array<char*>* deleteArray = NULL;160 148 if (type == SHADER_VERTEX) 161 149 { 162 deleteArray = this->vertexShaderSource;163 this->vertexShaderSource = NULL;164 delete this->vertexShaderLenghts;165 this->vertexShaderLenghts = NULL;166 150 delete[] this->vertexShaderFile; 167 151 this->vertexShaderFile = NULL; … … 171 155 else if (type == SHADER_FRAGMENT) 172 156 { 173 deleteArray = this->fragmentShaderSource;174 delete this->fragmentShaderLengths;175 this->fragmentShaderLengths = NULL;176 this->fragmentShaderSource = NULL;177 157 delete[] this->fragmentShaderFile; 178 158 this->fragmentShaderFile = NULL; … … 182 162 else 183 163 return; 184 185 if (deleteArray == NULL)186 return;187 else188 {189 deleteArray->finalizeArray();190 for (unsigned int i = 0; i < deleteArray->getCount(); i++)191 {192 delete[] deleteArray->getEntry(i);193 }194 delete deleteArray;195 }196 164 } 197 165 … … 214 182 if (this->vertexShader != 0) 215 183 { 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); 217 185 if (this->vertexShaderSource != NULL) 218 186 for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++) … … 224 192 if (this->fragmentShaderSource != NULL) 225 193 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));*/ 227 195 } 228 196 -
trunk/src/lib/graphics/shader.h
r5264 r5266 20 20 21 21 // FORWARD DECLARATION 22 template<class T> class Array;23 22 24 23 … … 31 30 32 31 bool loadShaderProgramm(SHADER_TYPE type, const char* fileName); 33 bool activateShader(); 32 void activateShader(); 33 static void deactivateShader(); 34 34 void deleteProgram(SHADER_TYPE type); 35 36 char* fileRead(const char* fileName); 35 37 36 38 void printError(GLenum program); … … 42 44 char* fragmentShaderFile; 43 45 char* vertexShaderFile; 44 Array<char*>* fragmentShaderSource;45 Array<char*>* vertexShaderSource;46 Array<int>* fragmentShaderLengths;47 Array<int>* vertexShaderLenghts;48 46 GLenum shaderProgram; 49 47 GLenum vertexShader; -
trunk/src/story_entities/world.cc
r5260 r5266 73 73 #include "cd_engine.h" 74 74 #include "npc.h" 75 #include "npc2.h" 75 76 76 77 SHELL_COMMAND(speed, World, setSpeed); … … 462 463 for(int i = 0; i < 100; i++) 463 464 { 464 WorldEntity* tmp = new NPC ();465 WorldEntity* tmp = new NPC2(); 465 466 char npcChar[10]; 466 467 sprintf (npcChar, "NPC_%d", i); -
trunk/src/world_entities/npc.cc
r5259 r5266 30 30 this->setClassID(CL_NPC, "NPC"); 31 31 32 this->loadModelWithScale("models/ships/bolido.obj", 5);32 this->loadModelWithScale("models/ships/bolido.obj", 2); 33 33 34 34 this->randomRotAxis = VECTOR_RAND(1); -
trunk/src/world_entities/npc2.cc
r5265 r5266 17 17 18 18 19 #include "npc .h"19 #include "npc2.h" 20 20 #include "obb_tree.h" 21 21 22 #include "shader.h" 22 23 #include "state.h" 23 24 #include "list.h" … … 26 27 27 28 28 NPC ::NPC()29 NPC2::NPC2() 29 30 { 30 31 this->setClassID(CL_NPC, "NPC"); 31 32 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(); 33 39 34 40 this->randomRotAxis = VECTOR_RAND(1); … … 36 42 37 43 38 NPC ::~NPC() {}44 NPC2::~NPC2 () {} 39 45 40 46 41 void NPC ::collidesWith(WorldEntity* entity, const Vector& location)47 void NPC2::collidesWith(WorldEntity* entity, const Vector& location) 42 48 { 43 49 if (entity->isA(CL_PROJECTILE)) … … 56 62 57 63 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 */ 70 void 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 95 void NPC2::tick(float dt) 59 96 { 60 97 // Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor()); -
trunk/src/world_entities/npc2.h
r5265 r5266 1 1 2 #ifndef _NPC _H3 #define _NPC _H2 #ifndef _NPC22_H 3 #define _NPC2_H 4 4 5 5 #include "world_entity.h" … … 7 7 8 8 class AI; 9 class Shader; 9 10 10 class NPC : public WorldEntity, public PhysicsInterface {11 class NPC2 : public WorldEntity, public PhysicsInterface { 11 12 12 13 public: 13 NPC ();14 ~NPC ();14 NPC2 (); 15 ~NPC2 (); 15 16 16 17 … … 18 19 19 20 virtual void tick(float dt); 21 virtual void draw(); 20 22 21 23 virtual void collidesWith (WorldEntity* entity, const Vector& location); … … 24 26 private: 25 27 Vector randomRotAxis; 26 27 ;28 Shader* shader; 29 GLUquadricObj* obj; 28 30 29 31 }; 30 32 31 #endif /* _NPC _H */33 #endif /* _NPC2_H */
Note: See TracChangeset
for help on using the changeset viewer.