Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: glBindTexture problem

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2000
    Preston, lancs, Uk

    glBindTexture problem

    How do I use glBindTexture? - all the source code I can find is hopelessly unreadable and the OpenGL help file I have skips over most of it conveniantly. Simple examples preferred with some doc. if poss

  2. #2
    Intern Contributor
    Join Date
    Feb 2000

    Re: glBindTexture problem

    I did have the same problem, months ago.
    The fact is I was missing the meaning of the specs about binding texture objects.
    In short, OGL drivers maintain several distinct objects (data structures), which hold texture data + parameters.
    Binding works by associating a 'name'(actually an integer value) to each texture object; each time you have to make a particular object active, you simply set the binding to the name you had.
    Ok, now I will come up with an example.
    Here, for clarity, I use exclusively 2D textures, that is GL_TEXTURE_2D as the target.

    unsigned texture_handle; // holds the name

    //-- allocate a name
    glGenTextures(1, &texture_handle);

    //-- bind the named object to the target
    // this will make the object's data available // to all the operations on the associated target
    glBindTexture(GL_TEXTURE_2D, texture_handle);

    //-- set parameters
    // ... other params ...

    0, // no mipmap LoD
    4, // components
    0, // no border
    Rendering of scene
    //-- bind the named object
    // this recalls all stored states for the object
    glBindTexture(GL_TEXTURE_2D, texture_handle);

    // now subsequent operations that need
    // texturing data will fetch the previously
    // stored info from the bound object

    //... draw geometry, specifying TexCoords

    // the binding remains current until you call
    // glBindTexture with another name

    // when you don't need anymore texturing, you
    // simply disable it.
    That's it. Have a try!
    Paolo M.

  3. #3

    Re: glBindTexture problem

    What does the "1" mean?
    glGenTextures(1, &texture_handle);

    In the tutorials I've read the texture_handle was a kind of GLuint? What kind of data is it (I'd think just a kind of integer) But how can that store a texture?
    Is it possible to generate a texture from something like an arry of byte in which I place the RGB values for each pixel, it seems a lot easier than all the other stuff I read to me. And when yes how?

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Grenoble - France

    Re: glBindTexture problem

    What about reading the docs ?
    Choose your flavor : .asp

    glGenTextures( n, *textures);
    n: The number of texture names to be generated.
    textures: A pointer to the first element of an array in which the generated texture names are stored.

    You can see an OpenGL 'name' as an ID, an SQL key, it is a number that identifies a unique object (texture, display list, etc).

    To specify actual texels data, read the above post about glTexImage, and the reference docs as well.

Posting Permissions

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