Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Problems with textures

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2007
    Posts
    3

    Problems with textures

    Hi there,

    Im having some problems with creating textures.
    Im trying to load the textures with this procedure
    Code :
    void  setTextureToObject(char* textureFilename, int obj)
    {
      Mesh::Texture texture; 
      // this one works fine
      Mesh::loadTexture(textureFilename, texture);
      // glGenTextures returns the same IDs on different calls
      glGenTextures(1, &(Objects[obj].gTextureAccessor));
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
      glBindTexture(GL_TEXTURE_2D, Objects[obj].gTextureAccessor);
      gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, texture.pTextureData);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture.width, texture.height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture.pTextureData);
      Mesh::unloadTexture(texture);
    }
    (Objects is a Vector of a struct with the object data; Mesh::texture is a struct to hold the temporary texture on loading)

    the funny thing is I call this procedure twice in my initialization and it works just fine there, but as soon as Im in the main loop glGenTextures start setting gTextureAccessor to 1 again.
    I tried replacing this line with a global counter but although the texture-ids are correct now its not working.

    Sometimes this results in the correct texture, sometimes the objects have no texture and sometimes they disapear completely

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    924

    Re: Problems with textures

    Has the structure stored within the Objects vector a destructor that destroys the texture? When new elements are added to stl vector, the entire content is sometimes copied to new memory which will cause call of destructor on objects in the old memory.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2007
    Posts
    3

    Re: Problems with textures

    Thanks for the hint but unfortunately the structure has no destructor and there is (until now) no line of code that says "glDeleteTextures"

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2007
    Posts
    3

    Re: Problems with textures

    ohh I think I just found the problem: forgot to initialize gTextureAccessor ... *stupid*
    thanks agian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •