Changeset 8037 in orxonox.OLD for trunk/src/lib
- Timestamp:
- May 31, 2006, 4:52:34 PM (19 years ago)
- Location:
- trunk/src/lib/graphics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/material.cc
r7922 r8037 108 108 return true; 109 109 110 /// !! HACK !!! FIX THIS IN MODEL /// 111 else if (likely(Material::selectedMaterial != NULL)) 112 { 113 Material::unselect(); 114 // for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i) 115 // { 116 // glActiveTexture(Material::glTextureArbs[i]); 117 // glBindTexture(GL_TEXTURE_2D, 0); 118 // glDisable(GL_TEXTURE_2D); 119 // } 120 } 121 110 122 if (likely(Material::selectedMaterial != NULL)) 111 123 { … … 146 158 glShadeModel(GL_SMOOTH); 147 159 148 149 160 for(unsigned int i = 0; i < this->textures.size(); ++i) 150 161 { … … 160 171 } 161 172 173 void Material::unselect() 174 { 175 Material::selectedMaterial = NULL; 176 for(unsigned int i = 0; i < 8; ++i) 177 { 178 glActiveTexture(Material::glTextureArbs[i]); 179 glBindTexture(GL_TEXTURE_2D, 0); 180 glDisable(GL_TEXTURE_2D); 181 } 182 } 183 162 184 /** 163 185 * Sets the Material Illumination Model. … … 366 388 } 367 389 390 /** 391 * @brief renders viewport buffer (?? or another buffer ;-)) to a texture 392 * @param textureNumber select the texture unit that will be overwritten 393 */ 394 void Material::renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) 395 { 396 assert(textureNumber < Material::getMaxTextureUnits()); 397 assert(textureNumber < this->textures.size()); 398 399 glActiveTexture(0); 400 glEnable(GL_TEXTURE_2D); 401 glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture()); 402 glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 403 404 } 368 405 369 406 /** 370 407 * @brief Sets the Materials Ambient Map 371 * @param aMap the Name of the Image to Use 372 @todo implement this 408 * @todo implement this 373 409 */ 374 410 void Material::setAmbientMap(const std::string& aMap, GLenum target) -
trunk/src/lib/graphics/importer/material.h
r7919 r8037 30 30 31 31 bool select () const; 32 bool activateTextureUnit(unsigned int textureNumber); 33 static void unselect(); 32 34 33 35 void setIllum (int illum); … … 55 57 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 56 58 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 59 void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); 57 60 58 61 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); -
trunk/src/lib/graphics/shader.cc
r7221 r8037 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 … … 40 42 this->setClassID(CL_SHADER, "Shader"); 41 43 42 this->fragmentShaderFile = "";43 this->vertexShaderFile = "";44 44 this->shaderProgram = 0; 45 45 this->vertexShader = 0; … … 48 48 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100) 49 49 { 50 GLint status = 0;51 52 50 this->shaderProgram = glCreateProgramObjectARB(); 53 51 54 52 if (!vertexShaderFile.empty()) 55 this->loadShaderProgramm(S HADER_VERTEX, vertexShaderFile);53 this->loadShaderProgramm(Shader::Vertex, vertexShaderFile); 56 54 if (!fragmentShaderFile.empty()) 57 this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile); 58 glLinkProgramARB(this->shaderProgram); 59 // link error checking 60 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status); 61 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 62 this->printError(this->shaderProgram); 55 this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile); 56 57 this->linkShaderProgram(); 58 63 59 } 64 60 else … … 78 74 79 75 // delete what has to be deleted here 80 this->deleteProgram(S HADER_VERTEX);81 this->deleteProgram(S HADER_FRAGMENT);76 this->deleteProgram(Shader::Vertex); 77 this->deleteProgram(Shader::Fragment); 82 78 83 79 if (this->fragmentShader != 0) … … 116 112 117 113 118 bool Shader::loadShaderProgramm(S HADER_TYPEtype, const std::string& fileName)114 bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName) 119 115 { 120 116 GLhandleARB shader = 0; 121 117 122 if (type != S HADER_VERTEX && type != SHADER_FRAGMENT)118 if (type != Shader::Vertex && type != Shader::Fragment) 123 119 return false; 124 120 this->deleteProgram(type); 125 121 126 122 127 std::vector<char*>* program = fileReadArray(fileName); 128 129 if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader) 123 std::string program; 124 if (!readShader(fileName, program)) 125 return false; 126 127 if (type == Shader::Vertex && GLEW_ARB_vertex_shader) 130 128 { 131 129 this->vertexShaderFile = fileName; … … 134 132 } 135 133 136 if (type == S HADER_FRAGMENT&& GLEW_ARB_fragment_shader)134 if (type == Shader::Fragment && GLEW_ARB_fragment_shader) 137 135 { 138 136 this->fragmentShaderFile = fileName; … … 144 142 { 145 143 GLint status = 0; 146 /// FIXME do it back 147 // glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL); 144 const char* prog = program.c_str(); 145 146 glShaderSourceARB(shader, 1, &prog, NULL); 148 147 glCompileShaderARB(shader); 149 148 // checking on error. … … 154 153 glAttachObjectARB(this->shaderProgram, shader); 155 154 } 156 for (unsigned int i=0; i< program->size(); i++) 157 delete[] (*program)[i]; 158 delete program; 159 } 160 161 char* Shader::fileRead(const std::string& fileName) 162 { 163 FILE* fileHandle; 164 char* content = NULL; 165 166 int count = 0; 167 168 if (fileName.empty()) 169 return NULL; 170 171 fileHandle = fopen(fileName.c_str(), "rt"); 172 173 if (fileHandle == NULL) 174 return NULL; 175 fseek(fileHandle, 0, SEEK_END); 176 count = ftell(fileHandle); 177 rewind(fileHandle); 178 if (count > 0) { 179 content = new char[count+1]; 180 count = fread(content, sizeof(char), count, fileHandle); 181 content[count] = '\0'; 182 } 183 fclose(fileHandle); 184 return content; 185 } 186 187 188 std::vector<char*>* Shader::fileReadArray(const std::string& fileName) 189 { 190 FILE* stream; //< The stream we use to read the file. 191 192 if( (stream = fopen (fileName.c_str(), "rt")) == NULL) 193 { 194 PRINTF(1)("Shader could not open %s\n", fileName.c_str()); 195 return NULL; 196 } 197 std::vector<char*>* file = new std::vector<char*>; 198 199 char lineBuffer[PARSELINELENGHT]; 200 char* addString; 201 while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL) 202 { 203 addString = new char[strlen(lineBuffer)+1]; 204 strcpy(addString, lineBuffer); 205 file->push_back(addString); 206 } 207 fclose(stream); 208 return file; 155 } 156 157 158 void Shader::linkShaderProgram() 159 { 160 GLint status = 0; 161 162 glLinkProgramARB(this->shaderProgram); 163 // link error checking 164 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status); 165 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 166 this->printError(this->shaderProgram); 167 } 168 169 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 output += "\n"; 185 } 186 187 188 shader.close(); 189 return true; 209 190 } 210 191 … … 228 209 229 210 230 void Shader::deleteProgram(S HADER_TYPEtype)211 void Shader::deleteProgram(Shader::Type type) 231 212 { 232 213 GLint status = 0; 233 if (type == S HADER_VERTEX&& this->vertexShader != 0)214 if (type == Shader::Vertex && this->vertexShader != 0) 234 215 { 235 216 this->vertexShaderFile = ""; … … 241 222 this->vertexShader = 0; 242 223 } 243 else if (type == S HADER_FRAGMENT&& this->fragmentShader != 0)224 else if (type == Shader::Fragment && this->fragmentShader != 0) 244 225 { 245 226 this->fragmentShaderFile = ""; -
trunk/src/lib/graphics/shader.h
r7785 r8037 12 12 13 13 14 typedef enum15 {16 SHADER_NONE = 0,17 SHADER_FRAGMENT = 1,18 SHADER_VERTEX = 0,19 20 } SHADER_TYPE;21 22 14 // FORWARD DECLARATION 23 15 24 16 17 25 18 //! A class for ... 26 class Shader : public BaseObject { 19 class Shader : public BaseObject 20 { 21 public: 22 class Uniform 23 { 24 public: 25 Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; } 26 Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; }; 27 Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; }; 27 28 28 public: 29 void set(float v0) const { glUniform1f(this->uniform, v0); } 30 void set(float v0, float v1) const { glUniform2f(this->uniform, v0, v1); } 31 void set(float v0, float v1, float v2) const { glUniform3f(this->uniform, v0, v1, v2); } 32 void set(float v0, float v1, float v2, float v3) const { glUniform4f(this->uniform, v0, v1, v2, v3); } 33 34 void set(int v0) const { glUniform1i(this->uniform, v0); } 35 void set(int v0, int v1) const { glUniform2i(this->uniform, v0, v1); } 36 void set(int v0, int v1, int v2) const { glUniform3i(this->uniform, v0, v1, v2); } 37 void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); } 38 39 void setV(unsigned int count, float* vv) const 40 { 41 switch (count) 42 { 43 case 1: 44 glUniform1fv(this->uniform, 1, vv); 45 break; 46 case 2: 47 glUniform2fv(this->uniform, 2, vv); 48 break; 49 case 3: 50 glUniform3fv(this->uniform, 3, vv); 51 break; 52 case 4: 53 glUniform4fv(this->uniform, 4, vv); 54 break; 55 } 56 } 57 void setV(unsigned int count, int* vv) const 58 { 59 switch (count) 60 { 61 case 1: 62 glUniform1iv(this->uniform, 1, vv); 63 break; 64 case 2: 65 glUniform2iv(this->uniform, 2, vv); 66 break; 67 case 3: 68 glUniform3iv(this->uniform, 3, vv); 69 break; 70 case 4: 71 glUniform4iv(this->uniform, 4, vv); 72 break; 73 } 74 } 75 private: 76 GLint uniform; 77 }; 78 79 typedef enum 80 { 81 None = 0, 82 Fragment = 1, 83 Vertex = 2, 84 85 Program = 4, 86 } 87 Type; 88 89 public: 29 90 Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); 30 91 virtual ~Shader(); … … 32 93 static bool unload(Shader* shader); 33 94 34 bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName); 95 96 static bool checkShaderAbility(); 35 97 void activateShader(); 36 98 static void deactivateShader(); 37 void deleteProgram(SHADER_TYPE type);38 99 39 char* fileRead(const std::string& fileName); 40 std::vector<char*>* fileReadArray(const std::string& fileName); 100 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); } 41 101 42 static bool checkShaderAbility(); 102 bool loadShaderProgramm(Shader::Type type, const std::string& fileName); 103 void deleteProgram(Shader::Type type); 43 104 44 inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; 105 void linkShaderProgram(); 106 107 108 bool readShader(const std::string& fileName, std::string& output); 109 110 111 inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; 45 112 inline static Shader* getActiveShader() { return Shader::storedShader; }; 46 113 inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 47 114 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 48 115 49 GLhandleARB getProgram() { return this->shaderProgram; }50 GLhandleARB getVertexS() { return this->vertexShader; }51 GLhandleARB getFragmentS() { return this->fragmentShader; }52 116 53 void printError(GLhandleARB program); 117 118 119 GLhandleARB getProgram() const { return this->shaderProgram; } 120 GLhandleARB getVertexS() const { return this->vertexShader; } 121 GLhandleARB getFragmentS() const { return this->fragmentShader; } 122 54 123 void debug() const; 55 124 56 private:125 static void printError(GLhandleARB program); 57 126 58 private:59 std::string fragmentShaderFile;60 std::string vertexShaderFile;61 GLhandleARB shaderProgram;62 GLhandleARB vertexShader;63 GLhandleARB fragmentShader;64 127 65 static Shader* storedShader; 128 private: 129 std::string fragmentShaderFile; 130 std::string vertexShaderFile; 131 132 GLhandleARB shaderProgram; 133 134 GLhandleARB vertexShader; 135 GLhandleARB fragmentShader; 136 137 138 static Shader* storedShader; 66 139 }; 67 140 -
trunk/src/lib/graphics/text_engine/text.cc
r7919 r8037 225 225 // setting the Blending effects 226 226 glColor4f(this->color.x, this->color.y, this->color.z, this->blending); 227 228 229 glActiveTexture(GL_TEXTURE0); 230 227 231 glEnable(GL_BLEND); 228 232 glEnable(GL_TEXTURE_2D);
Note: See TracChangeset
for help on using the changeset viewer.