Jump to content
  • Advertisement
Sign in to follow this  
Boder

[.net] [XNA] Texture Repeat and SpriteBatch and Wrap0

This topic is 3955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm repeating a tile over and over again (a repeated texture), and currently I have a for loop with repeated calls to SpriteBatch.Draw(). But I know texture repeating is a better way to do this. So I was wondering if anyone has been able to use texture repeating with SpriteBatch. Or if anyone can explain what the difference is between Wrap0, Wrap1, Wrap2, Wrap3, Wrap4, etc of RenderState and how to use it to repeat the u,v (s,t) coordinates. Someone showed me this thread. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1133363&SiteID=1 But I don't want to go beyond BasicEffect and SpriteBatch.

Share this post


Link to post
Share on other sites
Advertisement
Texture tiling happens when (it's enabled, and) the u or v texcoord is >1 or <0.
I haven't tried it, but here's something you might try:
On the Draw call, when drawing the sprite, use the function with rect objects for the source and destination. Have the source go beyond the image bounds.

If this doesn't do it, well, I don't know what to tell ya. No, actually, if this doesn't work, skip the sprites idea and wrap a quad with Sprite looking function calls. (but you already knew this)

-M

Share this post


Link to post
Share on other sites
UV wrapping should be the default addressing mode. You don't have to set anything.

Try it out. Like the previous post, your texture coordinates have to go <0 or >1 to be wrapped. Should just work.

Share this post


Link to post
Share on other sites
I tried this and it doesn't work. If you set your source rectangle to more than the size of the texture, it gets clamped to the size of the texture. Setting the GraphicsDevice sampler properties does not affect sprite drawing at all it seems.

Share this post


Link to post
Share on other sites
I was having trouble getting a texture to wrap along a triangle strip (not sprite-based, I know, but it may help). I tried using a BasicEffect, and also using an effect from an fx file (thanks Riemer!) but neither way worked. I tried changing AddressU and AddressV in several places, but it always seemed to clamp the texture rather than mirroring or wrapping it.

Eventually, I found the problem, and it was related to the image I was using as the texture. I was using a standard PNG with alpha from Photoshop (and importing it via the content pipeline "Content.Load<Texture2D>"). However, after days of going round in circles I discovered that after redimensioning the image to be a power of two in each dimension, the texture wrapped just fine.

Incidentally, I found this out by first converting the PNG to a DDS using NVIDIA's Photoshop plugin, whereupon I found that XNA would not load the image because, it told me, its dimensions were not powers of 2.

Maybe this will help someone who has the same problem as me.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!