Changeset 5318 in orxonox.OLD for trunk/src/lib/graphics/shader.cc
- Timestamp:
- Oct 8, 2005, 1:08:09 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/shader.cc
r5317 r5318 22 22 #include <stdio.h> 23 23 #include "debug.h" 24 #include "array.h" 24 25 25 26 … … 66 67 /** 67 68 * standard deconstructor 68 */69 */ 69 70 Shader::~Shader () 70 71 { 72 if (storedShader == this) 73 Shader::deactivateShader(); 74 71 75 // delete what has to be deleted here 72 76 this->deleteProgram(SHADER_VERTEX); … … 79 83 if (this->shaderProgram != 0) 80 84 glDeleteObjectARB(this->shaderProgram); 85 81 86 } 82 87 … … 93 98 94 99 95 const char* program = fileRead(fileName);100 Array<char*>* program = fileReadArray(fileName); 96 101 if (program == NULL) 97 102 return false; 103 98 104 if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader) 99 105 { … … 114 120 if (shader != 0) 115 121 { 116 glShaderSourceARB(shader, 1, (const GLcharARB**)&program, NULL); 117 try { 122 glShaderSourceARB(shader, program->getCount(), (const GLcharARB**)program->getArray(), NULL); 118 123 glCompileShaderARB(shader); 119 }120 catch (...)121 {122 124 this->printError(shader); 123 }124 125 glAttachObjectARB(this->shaderProgram, shader); 125 delete[] program;126 126 } 127 delete program; 127 128 } 128 129 … … 153 154 } 154 155 156 157 Array<char*>* Shader::fileReadArray(const char* fileName) 158 { 159 FILE* stream; //< The stream we use to read the file. 160 161 if( (stream = fopen (fileName, "rt")) == NULL) 162 { 163 PRINTF(1)("Shader could not open %s\n", fileName); 164 return NULL; 165 } 166 Array<char*>* file = new Array<char*>; 167 168 char lineBuffer[PARSELINELENGHT]; 169 char* addString; 170 while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL) 171 { 172 addString = new char[strlen(lineBuffer)+1]; 173 strcpy(addString, lineBuffer); 174 file->addEntry(addString); 175 } 176 fclose(stream); 177 file->finalizeArray(); 178 return file; 179 } 180 181 182 155 183 void Shader::activateShader() 156 184 {
Note: See TracChangeset
for help on using the changeset viewer.