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 3 123 LastLast
Results 1 to 10 of 21

Thread: Texture Mapping & Texture Coordinates

  1. #1
    Intern Newbie
    Join Date
    Jun 2005
    Posts
    39

    Texture Mapping & Texture Coordinates

    I have texture coordinate arrays and vertex arrays. I try to load them in CPP&opengl.
    Object is ok geometrically. Texture is .tga file. But there are some problems with texture coordinates, because .tga(512x512) picture is strange on texture. I think there is a problem with texture coordinates.

    Texture coordinate array dimension is more than vertex array.

    I use following functions.

    glTexCoord2f..
    glVertex3fv..

    Can texture coordinate array dimension be more than vertex? How will I use them? Should vertex array index and texture array index be equal to each other?

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2007
    Location
    Fairfax, VA
    Posts
    252

    Re: Texture Mapping & Texture Coordinates

    You can only have one set of texture coordinates per vertex. Anything else wouldn't make sense.

    As for specifically which texture coordinates go with which vertices, that's something you'll have to decide based on your use-case.

  3. #3
    Intern Newbie
    Join Date
    Feb 2007
    Location
    Tourlaville, France
    Posts
    49

    Re: Texture Mapping & Texture Coordinates

    Since the texture lies on a plane, meshes need to be unfolded.

    By doing so, the number of geometry faces is the same as the number of texture faces, but the number of texture vertices may be greater than the number of 3D vertices since the mesh is cut.

    Since you have the correspondance between texture faces and 3D faces, you can render them using the indices of the texture vertices and of the 3D vertices.

  4. #4
    Intern Newbie
    Join Date
    Jun 2005
    Posts
    39

    Re: Texture Mapping & Texture Coordinates

    I have texture coordinate array, texture index array, vertex coordinate array, vertex index array already.
    I use same index to reach index arrays, and then I reach texture index array and vertex index array and then I reach texture coordinates and vertex coordinate arrays.

    But object texture mapping is missing for some part of objects. Some part is OK.

    How will I render for fallowing pseudo code and how will I use vertex index and vertex coordinate arrays, texture index and texture coordinate arrays together ?

    Pseudo Code
    TextureCoordinates [][]=....
    TextureIndex=[]
    VertexCoordinates[][]=...
    VertexIndex=[]

    for i..1t o N {
    glTexCoord2f(TextureCoordinates[TextureIndex[i]][0],TextureCoordinates[TextureIndex[i]][1]);
    glVertex3fv(VertexCoordinates[VertexIndex=[i]];
    }

  5. #5
    Intern Newbie
    Join Date
    Feb 2007
    Location
    Tourlaville, France
    Posts
    49

    Re: Texture Mapping & Texture Coordinates

    You cannot do that.
    You need to make the loop over the faces:

    Pseudo code for immediate mode:
    Code :
    int va, vb, vc, tca, tcb, tcc;
    for (int i = 0; i < nbFaces; ++i) {
       getNthFace(i, &amp;va, &amp;vb, &amp;vc); // assuming faces are triangles
       getNthTextureFace(i, &amp;tca, &amp;tcb, &amp;tcc); // idem
     
       glTexCoord2f(TextureCoordinates[tca][0], TextureCoordinates[tca][1]);
       glVertex3fv(&amp;VertexCoordinates[3*va]);
     
       glTexCoord2f(TextureCoordinates[tcb][0], TextureCoordinates[tcb][1]);
       glVertex3fv(&amp;VertexCoordinates[3*vb]);
     
       glTexCoord2f(TextureCoordinates[tcc][0], TextureCoordinates[tcc][1]);
       glVertex3fv(&amp;VertexCoordinates[3*vc]);
    }

  6. #6
    Intern Newbie
    Join Date
    Jun 2005
    Posts
    39

    Re: Texture Mapping & Texture Coordinates

    But, if I remove glTexCoord2f, if I don't use texture then object shape is rendered correctly with this code. Just texture doesn't run.

  7. #7
    Intern Newbie
    Join Date
    Jun 2005
    Posts
    39

    Re: Texture Mapping & Texture Coordinates

    Following code runs correctly. Object is OK.
    But, texture is not OK.

    VertexCoordinates[][]=...
    VertexIndex=[]

    for i..1t o N {
    glVertex3fv(VertexCoordinates[VertexIndex=[i]];
    }

    How will texture coordinated be used?

  8. #8
    Intern Newbie
    Join Date
    Jun 2005
    Posts
    39

    Re: Texture Mapping & Texture Coordinates

    Is it about dimensions of .tga(512*512)?
    Because some part of object are covered with the texture. But some part of object is blank.

    Maybe object size is big for .tga ???

  9. #9
    Intern Newbie
    Join Date
    Feb 2007
    Location
    Tourlaville, France
    Posts
    49

    Re: Texture Mapping & Texture Coordinates

    Texture coordinates have nothing to do with the texture size.
    Except for GL_TEXTURE_RECTANGLE, they are normalized, meaning they are between 0 and 1, independently of the texture resolution.
    The texture could be 512x512, 128x1024, or anything else, the texture coordinates would stay between 0 and 1.

    If your rendering work by using the vertex in the order they appear instead of using the faces, you are lucky they appear in the same order as they would by looping over the faces.

  10. #10
    Intern Newbie
    Join Date
    Jun 2005
    Posts
    39

    Re: Texture Mapping & Texture Coordinates

    I use faces already.
    I use vertex indexes and texture indexes to reach vertex and texture coordinates.
    Vertex coordinates are OK. But texture is not OK
    ???

Posting Permissions

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