Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: undesired results of texture binding

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    California, USA
    Posts
    167

    undesired results of texture binding

    Ok, Im rendering some font on the screen using texture mapped quads. Now when I start introducing other primitives into my scene, binding other textures onto them, my texture mapped font quads just go all black.

    If I comment out the glBindTexture that binds a texture to my other primitives, my font returns to legible text. Does anyone have an idea of what is happening?

    Old GLman


    [This message has been edited by Old GLman (edited 03-21-2002).]

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: undesired results of texture binding

    Did you re-bind the font texture when you start drawing your font quads?

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    California, USA
    Posts
    167

    Re: undesired results of texture binding

    Korval, thanks for your reply. The problem is not how I bind the textures, but how I'm generating texture objects. Im using a structure similar to the one found on NeHe, which has variable unsigned int texID. Lets call my texture structure TEXTURE. I declare
    an array for 3 textures: TEXTURE tex[3].
    So each texture is identified by tex[i].texID, where i is the desired texture. How do I pass this to glGenTextures so it will generate 3 textures in one call? It works fine if I bind each texture seperatley, but I should be able to do them all in one call right? I hope this makes sense. Thanks

    [This message has been edited by Old GLman (edited 03-22-2002).]

  4. #4
    Intern Newbie
    Join Date
    Mar 2001
    Location
    New Zealand
    Posts
    41

    Re: undesired results of texture binding

    You must bind each texture before creating it, it is fine to generate multiple texture names at once (glGenTextures) but when you create the texture you must bind it before you call your load texture function.

    glBindTexture(GL_TEXTURE_2D, tex[0].ID);
    LoadTexture("tex0.tga");

    glBindTexture(GL_TEXTURE_2D, tex[1].ID);
    LoadTexture("tex1.tga");

    glBindTexture(GL_TEXTURE_2D, tex[2].ID);
    LoadTexture("tex2.tga");

    hope that fixes your problem, don't forget to rebind them when you need to use them, also don't forget to disable(GL_TEXTURE_2D) when drawing things which shouldn't be textured.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    California, USA
    Posts
    167

    Re: undesired results of texture binding

    Brent thanks for the info. My problem is that I dont believe glGenTextures is parsing the array im passing it correctly. Sorry, maybe I wasnt clear enough in the above post Hope this makes more sense now

    Old GLman

  6. #6
    Member Regular Contributor
    Join Date
    Nov 2000
    Posts
    409

    Re: undesired results of texture binding

    Post a code snippet then.

    If you did like what Brent said, then in your rendering loop, have something like:

    glBindTexture(GL_TEXTURE_2d,tex[0].texid);
    draw...
    bind the next texture
    draw...
    and so on, and you might want to throw in some push/pop matrix commands depending on what exactly you are doing, hence the request for code snippet.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    California, USA
    Posts
    167

    Re: undesired results of texture binding

    Ok, my problem has nothing to do with glBindTextures. I mentioned this in my prior posts. It has to do with glGenTextures. You should be able to pass it an array and let it generate texture objects right? In other words I should only have to call glGenTextures once. Sorry for being abrupt, but I'm wondering if you even read my prior posts in full. Right now I'm doing this:

    glGenTextures(1,&tgaimage[0].texID);
    glGenTextures(1,&tgaimage[1].texID);
    glGenTextures(1,&tgaimage[2].texID);

    tgaimage is my structure that holds all my texture information. texID is the indentifier. It works correctly if I do it this way, but it's not correct. I want to be able to do this:

    glGenTextures(3,&tgaimage[0].texID);

    so it will generate all the texture objects in one call. My understanding is that glGenTextures will go through an array and generate texture names.

    Old GLman


    [This message has been edited by Old GLman (edited 03-22-2002).]

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: undesired results of texture binding

    No.

    OpenGL knows nothing about the layout of your structures and there's no way you can change that. You can do this
    Code :
    uint tex_object_id[3];
    glGenTextures(3,tex_object_id);
    for (int i=0;i<3;++i)
    {
        your_array[i].texID=tex_object_id[i];
    }
    But you won't get any closer.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    California, USA
    Posts
    167

    Re: undesired results of texture binding

    Hi, yeah I thought of that. I guess I was just hoping for a cleaner solution. That will work though, thanks for the info.

    Old GLman


    [This message has been edited by Old GLman (edited 03-22-2002).]

  10. #10
    Guest

    Re: undesired results of texture binding

    Hi,
    I did a programm in which I didn't use glBindTexture()...every time I change the texture using glTexImage2D...so...glBindTexture() is used to avoid repeating every time glTexImage bla bla bla or there are other functions?
    Thank you

Posting Permissions

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