Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
ametcalfe's avatar
ametcalfe
Honored Guest
13 years ago

C++ development, stretching textures to faces

Hi all,

I am having a play with the tiny room demo and wondered if anybody knew how to specify that a texture should be stretched across the surface rather than be repeat tiled?

I am just wanting to experiment with a few things in the simple tiny room demo before taking on the oculus world demo in the Sdk.

I have tried to find an answer from the class documentation online but no success.

Thanks in advance.

3 Replies

  • Siduron's avatar
    Siduron
    Honored Guest
    To stretch a texture perfectly on a mesh, you need to edit the UV values of the texture.
  • "ametcalfe" wrote:
    I am having a play with the tiny room demo and wondered if anybody knew how to specify that a texture should be stretched across the surface rather than be repeat tiled?


    In order to represent complex geometry, many triangles are used for a given objects.

    Textures on the other hand will be typically be designed around the object as a whole.



    Because of this, many models intended to be textured will include what are called UV coordinates. For each XYZ 3D vertex coordinate, there will be a 2D UV coordinate which specifies the point on the 2D texture that corresponds to that point on the object's surface. For a triangle, you end up with 3 2D points cutting a triangle out of the original texture image, which is then pasted onto the actual geometry triangle.

    If you're struggling with this you may want to grab the OpenGL Programming Guide and go through the sections on textures.
  • I haven't looked in-depth at the Tiny demo, but I'll make some assumptions that maybe will help. I do know that the textures there are procedurally generated.

    It would make sense for the wall to be a single "quad" -- i.e., two triangles -- forming a very wide rectangle. So you have four vertices making the corners of the rectangle. Each vertex, besides having an XYZ position coordinate, has a UV texture coordinate (all included via the "vertex format" you define).

    To stretch a single texture across the quad both horizontally and vertically, here would be the UV values:

    (0.0, 0.0)           (1.0, 0.0)
    +--------------------+
    | '''--...__ |
    | '''--... |
    +--------------------+
    (0.0, 1.0) (1.0, 1.0)


    If you want to tile your texture, let's say three times horizontally, instead use the following UVs:

    (0.0, 0.0)           (3.0, 0.0)
    +--------------------+
    | '''--...__ |
    | '''--... |
    +--------------------+
    (0.0, 1.0) (3.0, 1.0)


    Increase either coordinate by whole values for each additional time you want the texture to tile.

    However, to directly answer your question, you will only want to use the range 0.0 to 1.0 to stretch the texture once from vertex to vertex.

    Hope this helps. Have fun!

    Tadd