Thread: Texture Objects and ID's

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Texture Objects and ID's

    Okay, so I know in OpenGL you create a texture ID with glBindTexture(...)

    A few questions..

    Does this create an ID you tell it to create? If you bind a texture, you have to give it an ID yourself? Or does it have some kind of stack in the background so you don't ever repeat texture ID's?

    I'm having issues in creating a generic bitmap texture object because I need to generate ID's for glBindTexture without repeating them..

    I basically want to have a Bitmap class with a pointer to the bitmap data in memory in it as well as an ID..

    So when I want to texture something (by way of my resource manager), I can do this easily because I can access any texture via the resource manager based on a texture string.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    You don't create an ID with any OpenGL function. All glBindTexture does, is binds loaded texture data to an ID.

    Code:
    GLuint CreateTexture(int texId)
    {
    glGenTextures(1, &texId);
    glBindTexture(GL_TEXTURE_2D, texId);
    
    return texId
    }
    
    ...
    
    Init()
    {
    GLuint texture = CreateTexture(0);
    }
    
    ...
    
    Draw()
    {
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);
    //drawstuff
    }
    Variations can be made of this method to suit your needs. All your really doing, is passing the texture data, through and unsigned integer via glBindTexture(). The texture is initialized with glGenTextures().

    Texture creation is frairly straight forward, but if you have any questions (or, more likely, if this isn't what you mean/were looking for), just ask
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Oh, so no matter what you have to input the texture ID yourself?

    Well, the problem with creating a texture object, is that somewhere I need to keep track of texture ID's so I don't repeat them..

    I can't just add 1 to the tex ID counter every time in the object, I have to do it somewhere else so I don't repeat them..

    Somewhere I need to keep track of texture id's
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Ok, so rather than take the textureID from a function arg, just increment the texture ID after each texture is created.

    Code:
    int texcount = 0;
    
    GLuint CreateTexture() //new texture creation function
    {
      glGenTextures(1, &texcount);
      glBindTextures(GL_TEXTURE_2D, texcount);
    
      //do other texture stuff...
    
      texcount++;
      return texcount;
    }
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  5. #5
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Good idea, but the thing is..

    Hmm, how to explain this..

    Okay, so we have an object

    Bitmap Texture

    In bitmap texture, we have a tex ID gluint, we have a load function...

    Now, to create a new texture, I'll be using my resource manager..

    All I have to do is pass my resource manager a string, and it will automatically load a texture using a new bitmap texture object..

    Like this..

    Code:
    	Resource_Observer Request_Resource(const std::string & name)
    	{
    		Resource_Map::iterator  it = mResources.find(name);
    
    		if (it == mResources.end())
    		{
    			Resource_Ptr Raw_Resource(new T_);
    			Raw_Resource->Load(name);
    			mResources.insert(std::make_pair(name, Raw_Resource));
    			Resource_Observer Resource(Raw_Resource);
    			return Resource;
    		}
    		else
    		{
    			return Resource_Observer(it->second);
    		}
    	}
    For every type T_ replace it with a Bitmap Texture object.. Now you understand how this works.. it returns a pointer resource observer, which I can use to access the tex ID inside the object.

    The beauty of this is that I will never repeat textures in memory, but I can still access them magnificently easy through ID's. Well, at this point we're accessing them through strings, but they have the ID's in them..

    I can't make the load function manage ID's, it kinda has to get them from somewhere else, seeing as we'll have multiple instances of these objects.

    So, what should I do? Should I keep a global GLuint of ID's, and increase that one, and then get that gluint and increase it for the ID's?

    EDIT:

    I just noticed you had texcount declared globally, guess that is what I'll do....
    Last edited by Shamino; 03-14-2006 at 05:35 PM.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. More resource management troubles
    By VirtualAce in forum Game Programming
    Replies: 4
    Last Post: 09-25-2007, 02:23 AM
  2. Resource management...again
    By VirtualAce in forum Game Programming
    Replies: 3
    Last Post: 11-29-2006, 04:50 AM
  3. So you want to be a game programmer?
    By dxfoo in forum Game Programming
    Replies: 23
    Last Post: 09-26-2006, 08:38 AM
  4. Finally, I understand!
    By Shamino in forum Game Programming
    Replies: 23
    Last Post: 06-10-2005, 11:24 AM
  5. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM