Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Using a texture over multiple places

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    9

    Question Using a texture over multiple places

    Hello.
    I want to be able to project a (consistent) texture over multiple faces. At the moment, if I bind a texture and draw multiple faces, each face will own its own texture. This works fine for low poly simple maps, but imagine if I have, say, a pillar. Obviously a pillar has many, many faces.

    If anyone could provide a tutorial, or some information on the topic, I would be greatly appreciative.

    Thanks.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Bremen, Germany
    Posts
    149
    Not sure if I understand you right but this sounds like you need to specify the right texture-coordinates for each vertex you render. The texture-coordinate indicates where on the texture the renderer should be when the vertex is drawn. So
    glBegin(GL_LINES);
    glTexCoords2f(0,0); glVertex(...)
    glTexCoords2f(0.5, 0); glVertex(...)
    glEnd();
    will draw a line that gets textured with the left half of the lowest pixel-line of the texture - roughly spoken.
    If you have for example 4 quads in line where the texture should be spanned over you will have to map the 5 different x-coordinates of the vertices used to draw them to 5 x-texture-coordinates.

    P0----P1----P2----P3----P4----P5 Point
    0.0---0.2---0.4---0.6---0.8---1.0 TexCoord
    Last edited by hlewin; 07-23-2013 at 05:22 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    9
    OH, so if I work out how many faces there are using the same texture, I can stretch it across something like this:

    F1 F2 F3
    v1 v2 v1 v2
    | | | |
    0.0 0.3 0.6 0.9

    Something like that?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Bremen, Germany
    Posts
    149
    The v's are confusing as v1=v1 and v2=v2. But your above sentence is correct.

    Code :
    0.0,1.0---------0.5,1.0-----------1.0,1.0
    |                   |                  |
    |                   |                  |
    |                   |                  |
    0.0,0.0---------0.5,0.0-----------1.0,0.0
    will Stretch the texture across the two quads, where the numbers denote the texture-coords and the places where the numbers are (and the lines intersect) denote the different Vertices.
    The 0.5,X.0 texcoord tells GL that it should have reached in the x-middle of the texture at that vertex as a texture is always of the width and height of 1 (logically).
    The middle-point on the line between the Vertices with the tex-coords (0.5,0.0) and (0.5,1.0) will be in the middle of the texture as ((0.5,0.0)+(0.5,1.0))/2 = (0.5, 0.5).
    Last edited by hlewin; 07-23-2013 at 08:40 PM.

Tags for this Thread

Posting Permissions

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