Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:59:53+00:00 2026-06-03T13:59:53+00:00

Do forgive me if this has been asked before, I’ve been looking for the

  • 0

Do forgive me if this has been asked before, I’ve been looking for the answer to this all day and all I’m coming up with is help with tile based 2D games. x~x

I’m trying to create a skinnable GUI in Direct3D 9, using an XML file that has positions for each element and an option to stretch or tile them. Stretching’s a simple enough procedure, but I’ve been unable to figure out a way to tile a small section of a texture. Traditionally to tile a texture I would just set the UV coordinates to > 1.0, but the source texture coordinates are only going to be a small subset of the whole texture, such as 0.4 to 0.5.

I have a feeling I missed something really obvious, but how would I go about simply tiling instead of stretching? My best guess is it has something to do with having more than one set of texture coordinates, but from there, I’m not sure where to go.

The project currently uses the fixed function pipeline, so I would prefer an answer using that if possible, but I would not turn down an answer that uses a shader if that’s the only way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:59:54+00:00Added an answer on June 3, 2026 at 1:59 pm

    I understand you want to tile only a subset of the texture, right? Then things get complicated.

    Assume we want to tile u-coord between u1 and u2 values, u1 < u2.

    Then we need a function f(u), so that

    f(0.0) = u1
    f(0.5) = (u1+u2)/2
    f(0.9999) = u2
    f(1.0) = u1
    f(1.5) = (u1+u2)/2
    f(1.9999) = u2
    f(2.0) = u1
    and so on...
    

    An appropriate function is f(u) = frac(u) * (u2-u1) + u1

    The same goes for v-coord, f(v) = frac(v) * (v2-v1) + v1

    Notice that it’s tiling without mirroring. If you need mirroring, then the function should be a triangular-wave function, which is t(x) = arcsin(sin(pi*(x-0.5)))/pi+0.5 and f(u) = t(u) * (u2-u1) + u1. Using trigonometric functions can be expensive though.

    I don’t know if it’s possible with fixed pipeline, but you can do it easily in pixel shader (HLSL code):

    // float2 tex_coord -> (u,v) from vertex shader, in [0,n] range,
    //                     n - number of repetitions
    // float2 tex1, tex2 -> constants, subrange of [0,1] coords that will be tiled
    
    // no mirroring
    float4 color = tex2D(sampler, frac(tex_coord) * (tex2-tex1) + tex1);
    

    or

    // mirroring, t(x) = arcsin(sin(pi*(x-0.5)))/pi+0.5
    float4 color = tex2D(sampler, t(tex_coord) * (tex2-tex1) + tex1);
    

    EDIT:
    a better way to compute triangular-wave function: t1(x) = abs(2(0.5x-floor(0.5x+0.5))) or t2(x) = abs(2(frac(0.5x+0.5))-1) (not exactly the same as t1 but correct for non-negative numbers).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this has been asked before, but I assure you I've scoured
Forgive me if this has been asked before, I am sure it has but
If this has been asked before please forgive me, I could not find it.
Forgive me if this question has been asked before but I am new to
I am sure that the answer to this has been posted before. Forgive me
This is my first question, so forgive me if it has been asked before.
Forgive me if this has been answered before, I couldn't find an answer where
Please forgive me if this has been answered before. I'm looking for some advice
Forgive me if this has been asked before, but I was unable to find
Forgive me if this has been asked before. I have poured through this site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.