Results 1 to 3 of 3

Thread: multitexturing

  1. #1
    Guest

    multitexturing

    (I posted this is the linux section, but that forum looks rather dead.)

    I am trying to use an indexed array to draw a multitextured scene as follows:
    ------------------------
    // load vertices
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer (2, GL_FLOAT, v_stride, pVertices);

    // load normals
    glEnableClientState(GL_NORMAL_ARRAY);
    glNormalPointer(GL_FLOAT, n_stride, pNormals);

    // set unit 0
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, t_stride0, pTexCoords0);
    glBindTexture(GL_TEXTURE_2D, base_texture);

    // set unit 1
    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, t_stride1, pTexCoords0);
    glBindTexture(GL_TEXTURE_2D, lightmap);

    // draw it.
    glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_SHORT, pIndexes);
    ----------------------

    The problem is that the texture coordinates intended for unit 1 are actually overwriting the ones intended for unit 0, and unit 1 coordinates are never initilized. So it looks like glTexCoordPointer() is stuck on unit 0. How do I tell glTexCoordPointer that the data is intended for a texture unit other than 0?

    (I've looked at a number of tutorials and examples, and I can't see anything wrong with the above code, which makes me start wondering if the NVidia opengl on linux has a bug.)

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: multitexturing

    I don't see anything related to vertex arrays, but I do see something related to multitexturing.
    Code :
    // set unit 0
    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, t_stride0, pTexCoords0);
    glBindTexture(GL_TEXTURE_2D, base_texture);
     
    // set unit 1
    glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2, GL_FLOAT, t_stride1, pTexCoords0);
    glBindTexture(GL_TEXTURE_2D, lightmap);
    You set active texture on the client side, which is what you need to do for vertex arrays. But then you bind a texture, and the texture is bound to the active texture unit on the server side, which may have a different active texture unit than the client side. Make sure the correct texture unit is active on the server side also.

    In the next part, you bind another texture, but you haven't changed active texture unit, effectively "overwriting" the previously bound texture.

  3. #3
    Guest

    Re: multitexturing

    Leaving the glActiveTexture calls out of my sample code was a typo. I call glActiveTexture() just before each of the glClientActiveTexture in the actual code.

Similar Threads

  1. VBO+multitexturing
    By dletozeun in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-19-2006, 02:20 PM
  2. Multitexturing
    By Jeff_Mills in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 10-19-2004, 12:56 PM
  3. arb multitexturing
    By divide in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 12-30-2002, 09:15 AM
  4. Multitexturing
    By tobiaso in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-26-2002, 08:39 AM
  5. Multitexturing
    By Fredy in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-28-2001, 11:13 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