Changeset 7822 in orxonox.OLD for branches/water
- Timestamp:
- May 24, 2006, 6:04:19 PM (19 years ago)
- Location:
- branches/water/src/lib/graphics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/lib/graphics/shader.cc
r7818 r7822 20 20 #include "stdlibincl.h" 21 21 #include "compiler.h" 22 #include <stdio.h> 22 //#include <stdio.h> 23 #include <fstream> 24 23 25 #include "debug.h" 24 26 … … 26 28 27 29 28 #ifndef PARSELINELENG HT29 #define PARSELINELENG HT512 //!< how many chars to read at once30 #ifndef PARSELINELENGTH 31 #define PARSELINELENGTH 512 //!< how many chars to read at once 30 32 #endif 31 33 … … 119 121 120 122 121 std::vector<char*>* program = fileReadArray(fileName); 123 std::string program; 124 if (!readShader(fileName, program)) 125 return false; 122 126 123 127 if (type == Shader::Vertex && GLEW_ARB_vertex_shader) … … 139 143 GLint status = 0; 140 144 /// FIXME do it back 141 // glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL); 145 const char* prog = &program[0]; 146 glShaderSourceARB(shader, 1, &prog, NULL); 142 147 glCompileShaderARB(shader); 143 148 // checking on error. … … 148 153 glAttachObjectARB(this->shaderProgram, shader); 149 154 } 150 for (unsigned int i=0; i< program->size(); i++)151 delete[] (*program)[i];152 delete program;153 155 } 154 156 … … 166 168 167 169 168 char* Shader::fileRead(const std::string& fileName) 169 { 170 FILE* fileHandle; 171 char* content = NULL; 172 173 int count = 0; 174 175 if (fileName.empty()) 176 return NULL; 177 178 fileHandle = fopen(fileName.c_str(), "rt"); 179 180 if (fileHandle == NULL) 181 return NULL; 182 fseek(fileHandle, 0, SEEK_END); 183 count = ftell(fileHandle); 184 rewind(fileHandle); 185 if (count > 0) { 186 content = new char[count+1]; 187 count = fread(content, sizeof(char), count, fileHandle); 188 content[count] = '\0'; 189 } 190 fclose(fileHandle); 191 return content; 192 } 193 194 195 std::vector<char*>* Shader::fileReadArray(const std::string& fileName) 196 { 197 FILE* stream; //< The stream we use to read the file. 198 199 if( (stream = fopen (fileName.c_str(), "rt")) == NULL) 200 { 201 PRINTF(1)("Shader could not open %s\n", fileName.c_str()); 202 return NULL; 203 } 204 std::vector<char*>* file = new std::vector<char*>; 205 206 char lineBuffer[PARSELINELENGHT]; 207 char* addString; 208 while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL) 209 { 210 addString = new char[strlen(lineBuffer)+1]; 211 strcpy(addString, lineBuffer); 212 file->push_back(addString); 213 } 214 fclose(stream); 215 return file; 170 bool Shader::readShader(const std::string& fileName, std::string& output) 171 { 172 char lineBuffer[PARSELINELENGTH]; 173 174 std::ifstream shader; 175 shader.open(fileName.c_str()); 176 if (!shader.is_open()) 177 return false; 178 179 180 while (!shader.eof()) 181 { 182 shader.getline(lineBuffer, PARSELINELENGTH); 183 output += lineBuffer; 184 printf("line:: %s\n"); 185 } 186 187 188 shader.close(); 216 189 } 217 190 -
branches/water/src/lib/graphics/shader.h
r7818 r7822 46 46 47 47 48 char* fileRead(const std::string& fileName); 49 std::vector<char*>* fileReadArray(const std::string& fileName); 48 bool readShader(const std::string& fileName, std::string& output); 50 49 51 50
Note: See TracChangeset
for help on using the changeset viewer.