Example #1
0
void Surface::initTexture(const AttributeSet& attributes,
                          GLTexture& texture,
                          int line, int column, 
                          ErrorManager* errorManager)
{
  for(unsigned int i=0; i< attributes.size(); i++)
  {
    if (attributes[i].attribute == "file")
      texture.setTexName(attributes[i].value);
    else if(attributes[i].attribute == "mode")
    {
      if(attributes[i].value == "GL_MODULATE")
        texture.setMode(GL_MODULATE);
      else if(attributes[i].value == "GL_REPLACE")
        texture.setMode(GL_REPLACE);
      else if(attributes[i].value == "GL_ADD")
        texture.setMode(GL_ADD);
      else if(attributes[i].value == "GL_DECAL")
        texture.setMode(GL_DECAL);
    }
    else if (attributes[i].attribute == "wrapS")
    {
      GLenum mode = (GLenum)ParserUtilities::toTextureWrapMode(attributes[i].value);
      if(mode == GL_NONE)
        errorManager->addError("Unknown Texture Mode", "Unknown Texture Mode \""
          + attributes[i].value + "\". Try( GL_CLAMP | GL_CLAMP_TO_EDGE | GL_CLAMP_TO_BORDER | GL_MIRRORED_REPEAT | GL_REPEAT)", line, column);
      else
        texture.setWrapS(mode);
    }
    else if (attributes[i].attribute == "wrapT")
    {
      GLenum mode = (GLenum)ParserUtilities::toTextureWrapMode(attributes[i].value);
      if(mode == GL_NONE)
        errorManager->addError("Unknown Texture Mode", "Unknown Texture Mode \""
          + attributes[i].value + "\". Try( GL_CLAMP | GL_CLAMP_TO_EDGE | GL_CLAMP_TO_BORDER | GL_MIRRORED_REPEAT | GL_REPEAT)", line, column);
      else
        texture.setWrapT(mode);
    }
    else if (attributes[i].attribute == "wrapR")
    {
      GLenum mode = (GLenum)ParserUtilities::toTextureWrapMode(attributes[i].value);
      if(mode == GL_NONE)
        errorManager->addError("Unknown Texture Mode", "Unknown Texture Mode \""
          + attributes[i].value + "\". Try( GL_CLAMP | GL_CLAMP_TO_EDGE | GL_CLAMP_TO_BORDER | GL_MIRRORED_REPEAT | GL_REPEAT)", line, column);
      else
        texture.setWrapR(mode);
    }
    else if (attributes[i].attribute == "priority")
      diffuseTexture.setPriority((GLclampf)ParserUtilities::toDouble(attributes[i].value));
    else
    {
      errorManager->addError("Unknown Texture Parameter",
        "The provided texture parameter \"" + name + "\" is unknown", line, column);
    }
  }
}
Example #2
0
GLTexture* ShaderInterface::getTexture(const std::string& filename)
{
  // check for a existing texture with the same name
  std::vector<GLTexture*>::iterator texIter;
  for(texIter = staticTextures.begin(); texIter != staticTextures.end(); texIter++)
  {
    if((*texIter)->getTexName() == filename)
      return *texIter;
  }

  GLTexture* tex = new GLTexture();
  tex->setTexName(filename);

  // special case: color and noise texture
  if(filename == "Noise")
    tex->setWidth(128);

  staticTextures.push_back(tex);
  return tex;
}