Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7700 in orxonox.OLD for branches/water/src/lib/graphics


Ignore:
Timestamp:
May 18, 2006, 5:05:45 PM (18 years ago)
Author:
stefalie
Message:

branches/water: first attempt to realise reflection

Location:
branches/water/src/lib/graphics/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/water/src/lib/graphics/importer/material.cc

    r7687 r7700  
    333333// MAPPING //
    334334
    335 /**
    336  *  Sets the Materials Diffuse Map
     335void Material::setDiffuseMap(Texture* texture, unsigned int textureNumber)
     336{
     337  assert(textureNumber < Material::getMaxTextureUnits());
     338
     339  if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
     340    ResourceManager::getInstance()->unload(this->textures[textureNumber]);
     341
     342  if (this->textures.size() <= textureNumber)
     343    this->textures.resize(textureNumber+1, NULL);
     344
     345  //! @todo check if RESOURCE MANAGER is availiable
     346  this->textures[textureNumber] = texture;
     347}
     348
     349
     350/**
     351 * @brief Sets the Materials Diffuse Map
    337352 * @param dMap the Name of the Image to Use
    338353*/
  • branches/water/src/lib/graphics/importer/material.h

    r7687 r7700  
    5353
    5454    // MAPPING //
     55    void setDiffuseMap(Texture* texture, unsigned int textureNumber = 0);
    5556    void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    5657    void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
  • branches/water/src/lib/graphics/importer/texture.cc

    r7687 r7700  
    2929#endif
    3030
     31
     32
     33
     34Texture::Texture(GLenum target)
     35{
     36  this->init();
     37  this->generateTexture(texture, target);
     38}
     39
    3140/**
    3241 *  Constructor for a Texture
     
    4251  }
    4352}
     53
     54
    4455
    4556Texture::Texture(SDL_Surface* surface, GLenum target)
     
    150161
    151162/**
    152  * rebuilds the texture.
     163 * @brief rebuilds the texture.
    153164 * reloads the Texture from Memory to OpenGL.
    154165 */
     
    171182
    172183/**
    173  * set the surface this Texture handles
     184 * @brief set the surface this Texture handles
    174185 * @param newSurface the new Surface to set as the image for this Texture.
    175186 *
     
    191202
    192203/**
    193  * enables, disables textures
     204 * @brief enables, disables textures
    194205 * @param texturesEnabled true if the textures should be enabled
    195206 */
     
    204215//////////////////////////////////////
    205216/**
    206  * converts surface to a new SDL_Surface, that is loadable by openGL
     217 * @brief converts surface to a new SDL_Surface, that is loadable by openGL
    207218 * @param surface the Surface to convert
    208219 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false.
     
    266277
    267278/**
    268  * Loads a Texture to the openGL-environment.
     279 * @brief Loads a Texture to the openGL-environment.
    269280 * @param surface the Image to load to openGL
    270281 * @returns The ID of the texture.
     
    277288
    278289  int      errorCode = 0;           //!< the error code for the texture loading functions
    279   GLuint   texture;                 //!< the OpenGL texture handle
     290  GLuint   texture = 0;             //!< the OpenGL texture handle
    280291  int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
    281292  int      mipmapWidth = 0;         //!< the width of the mipmap
     
    287298
    288299  /* Create an OpenGL texture for the image */
    289   glGenTextures(1, &texture);
    290   glBindTexture(target, texture);
    291 
    292   glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
    293   glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
    294 
    295   glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    296   glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    297 
     300  this->generateTexture(texture, target);
    298301  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
    299 
    300 
    301   /* control the mipmap levels */
    302   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
    303   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
    304302
    305303  /* build the Texture  OpenGL V >= 1.1 */
     
    330328}
    331329
     330void Texture::generateTexture(GLuint& texture, GLenum target)
     331{
     332  if (!glIsTexture(texture))
     333  {
     334    glGenTextures(1, &texture);
     335  }
     336  glBindTexture(target, texture);
     337
     338  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
     339  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
     340
     341  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
     342  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     343
     344  /* control the mipmap levels */
     345  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
     346  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
     347}
     348
  • branches/water/src/lib/graphics/importer/texture.h

    r7687 r7700  
    1818  {
    1919    public:
    20       Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D);
     20      Texture(GLenum target = GL_TEXTURE_2D);
     21      Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
    2122      Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
    2223      virtual ~Texture();
     
    5051    private:
    5152      void init();
     53      static void generateTexture(GLuint& texture, GLenum target);
    5254
    5355    private:
Note: See TracChangeset for help on using the changeset viewer.