Results 1 to 4 of 4

Thread: glBindTexture problem

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

    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
    Member Contributor
    Join Date
    Feb 2000
    Location
    Italy
    Posts
    77

    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.

    Initialization
    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
    glTexParameterf(GL_TEXTURE_2D,
    GL_TEXTURE_MIN_FILTER,
    GL_LINEAR);
    // ... other params ...

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

    // 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.
    glDisable(GL_TEXTURE_2D);
    That's it. Have a try!
    --
    Paolo M.

  3. #3
    Guest

    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?
    Thanx!

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: glBindTexture problem

    What about reading the docs ?
    Choose your flavor :
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc02_3p6b .asp
    http://www.3dlabs.com/support/develo...entextures.htm
    http://pyopengl.sourceforge.net/docu...xtures.3G.html

    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.

Similar Threads

  1. glBindTexture() problem...
    By Sephiroth in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-17-2003, 07:01 AM
  2. A Problem with glBindTexture
    By nickcartwright in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 10-06-2003, 07:55 AM
  3. Problem with glBindTexture
    By Caran Elmoth in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 06-20-2003, 06:35 AM
  4. problem with glBindTexture()
    By MickeyMouse in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-08-2002, 08:34 AM
  5. glBindTexture problem
    By Xelatihy in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-02-2000, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean