Logo Search packages:      
Sourcecode: gaia version File versions  Download package

void Texture::SetTexture (  ) 

Selects current texture in OpenGL.

Definition at line 47 of file Texture.cc.

References m_glFormat, m_glInternalFormat, m_Height, m_ID, m_Pixels, and m_Width.

Referenced by TextureTile::SetTexture().

                         {
      if (!m_ID && !m_Pixels)
            throw Exception("attempt to use empty texture");

      if (!m_ID) {
            /* we have pixels, but we need to load these into OpenGL */
            GLuint newtexture;
            glGenTextures(1, &newtexture);
            glBindTexture(GL_TEXTURE_2D, newtexture);
            glTexImage2D(GL_TEXTURE_2D, 0, m_glInternalFormat, m_Width, m_Height, 0, m_glFormat, GL_UNSIGNED_BYTE, m_Pixels);

            /* some default texture parameters */
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

            /* ok, done */
            m_ID = newtexture;

            /* we don't need this memory buffer any more */
            free(m_Pixels);
            m_Pixels = 0;
      } else {
            glBindTexture(GL_TEXTURE_2D, m_ID);
      }
}


Generated by  Doxygen 1.6.0   Back to index