Results 1 to 7 of 7

Thread: [OpenGL] Help me with texture mapping please.

  1. #1

    Question [OpenGL] Help me with texture mapping please.

    Hello folks.

    I wanted to ask you how to map texture onto triangle like in the provided image:



    Uploaded with ImageShack.us

    So, I have one triangle and two different textures which parts I would like to have mapped on the triangle. The problem is that I could not find example for this on the Web. (There is a lot of examples for quads and triangles but not in this specific case).

    I don't know if it is possible to map the red texture with specifying 4 different points for mapping.
    And I don't know if it is possible to map more than one texture onto triangle in a different part of that triangle.

    Thanks for your time

  2. #2
    Hi there.

    You must need too set textures to CLAMP mode and enable 2 texture stages for 2 different textures.
    Then you must just set UV for every vertex like this (clockwise from top):
    1st texture:
    0.5 0.0
    1.5 1.0
    0.5 1.0

    2nd texture:
    -0.5 0
    0.5 1.0
    -0.5 1.0

    Something like that. Or you can try different way by deviding your triangle with 3. And put first texture into 2 triangles and a second ine on third triangle.
    Theory is - when you know everything but nothing works.
    Practice is - when all works, but you don't know why.
    We combine theory and practice - nothing works and nobody knows why

  3. #3
    Quote Originally Posted by Darthman View Post
    Hi there.

    You must need too set textures to CLAMP mode and enable 2 texture stages for 2 different textures.
    Then you must just set UV for every vertex like this (clockwise from top):
    1st texture:
    0.5 0.0
    1.5 1.0
    0.5 1.0
    Thank you for answer

    I guess you meant for the first texture those coordinates?

    0.5 0.0
    0.5 1.0
    1.0 1.0

  4. #4
    Red texture:
    up vertex 0.5 0.0 0
    down vertex 0.5 1.0
    down right vertex 1.5 1.0

    Thing is, you can't stop texture drawing midway of a triangle. Red part texture will show under that green one, and green will be drawn on top of whole of red. What prevents this is alpha channel of texture. (Only green texture in this case needs alpha if it is drawn after the red one)

    Green texture coordinates:
    up -0.5 0.0
    down -0.5 1.0
    down right 0.5 1.0
    Last edited by User137; 15-02-2011 at 03:50 PM.

  5. #5
    Thank you User123.

    If I understand you correctly, both of the textures must be in GL_REPEAT mode, right?

  6. #6
    GL_REPEAT is on by default, and ye that is the most useful one. If you try to draw with texture coordinates outside 0..1 (in this case you have coordinates to -0.5 and 1.5) then the rendering takes rules of what clamp is set to.

  7. #7
    Thanks for your time

Tags for this Thread

Bookmarks

Posting Permissions

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