XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

How do a texture repeat itself?

Last post 5/8/2009 4:45 AM by Baltico X. 6 replies.
  • 5/6/2009 9:30 PM

    How do a texture repeat itself?

    Hello, I am Brazilian and make games with XNA 3.0.

    but I have a question:

    How do a texture repeat itself? Equal the Guitar Hero where pass the notes. I am using a plane 3D (exported of 3d Max) ans Scaled for 150.

    But no can make a pixel shader functional.

    Tanks!


  • 5/7/2009 12:39 AM In reply to

    Re: How do a texture repeat itself?

    Send in texture U and V coordinates that are greater than 1.0 or less than 0.0.
    Set AddressU and AddresV to WRAP for the sampler you're using.

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 5/7/2009 2:53 AM In reply to

    Re: How do a texture repeat itself?

    I do this in my shader code?

    And how I can stretch a texture?

    You can give a example for me please?

    See ya!
  • 5/7/2009 3:20 AM In reply to

    Re: How do a texture repeat itself?

    It seems there are 2 things that you ask:

    1. How to stretch a texture?
    Basically, you need to draw a textured quad. For each vertex of the quad, you can specify the texture coordinate. To stretch the texture, you need to map the whole texture into the quad, i.e. the texture coordinate must range from 0 - 1

    To setup the quad, you need to setup the vertices. This is done in CPU

    2. How to repeat the texture?
    To repeat the texture, you need to setup the quad such that the texture coordinates are greater than 1 or less than 0 (just like what jwatte) said. This setting up of texture coords is done in CPU.

    In addition of setting up of texture coordinate, you need to set the texture addressing mode. Setting up the texture address mode can be done through shader.
  • 5/7/2009 4:55 AM In reply to

    Re: How do a texture repeat itself?

    Hi, in case you are using the BasicEffect to draw your model, do something like this. Please note that the default setting is for the texture to repeat itself, so setting the device to Wrap the texture is not mandatory, I just wanted to give you information on how to do it.

    myTexture = content.Load<Texture2D>("texture");  
     
    ...  
     
    basicEffect.Texture = myTexture;  
    basicEffect.TextureEnabled = true;  
     
    device.SamplerStates[0].AddressU = TextureAddressMode.Wrap;  
    device.SamplerStates[0].AddressV = TextureAddressMode.Wrap;  
     
    basicEffect.Begin();  
    foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)  
    {  
    pass.Begin();  
     
    //Draw your model  
     
    pass.End();  
    }  
    basicEffect.End(); 


  • 5/7/2009 11:22 PM In reply to

    Re: How do a texture repeat itself?

    Oh I will try this. Tanks. But, how extends a small texture for fill a big plane, but only in horizontal.

    Tanks.
  • 5/8/2009 4:45 AM In reply to

    Re: How do a texture repeat itself?

    Try to achieve your original goal of showing the texture repeated all over the model. As Jon said, it will all depend on the U and V coordinates that your model has, values kept between 0 and 1 will make the texture extend, but if values are higher than 1, the texture will start repeating itself because of the Wrap setting. You can also use Clamp or even Mirror settings, but I really suggest you try to show some texture at alll, then post again with the behaviour you got so we can help you further.
Page 1 of 1 (7 items) Previous Next