Sign in to follow this  
djsteffey

[xna] multiple images in one texture

Recommended Posts

I already tried the google thing and didnt find anything to help me. I basically have a tiles terrain. i want to have a different texture image for each tile (ie one square is dirt, one is grass, one is sand, etc..) if i load all three images into separate Texture2D variables then i can draw everything ok. When i try to place all these images side by side in one larger texture (for performance reasons), i have 4 images in one texture: upper left, upper right, lower left, lower right. now when i want to use the upper left image i specify texture coords of (0.0, 0.0) to (0.5, 0.5). now when i draw my terrain i get ugly white lines between all the tiles. i assume this is because the upper right and lower left images are pure white for the moment. so somehow xna is using data past the 0.5 i specify and sampling out of the white areas. i have looked into TextureAddressMode.Clamp but the documentation says it clamps from [0..1] and you cant specify to clamp to say 0.5 any suggestions ?

Share this post


Link to post
Share on other sites
Unless you adjust your texture coordinates, you're going to end up sampling a bit from the texels past the edges of your tile when using bilinear filtering. There's really 2 other solutions to this problem:

-Use point filtering (will make things look very blocky and PS1-ish if magnified or rotated)
-Put a 1-texel-wide buffer between your tiles that won't make things look bad. Usually a color with alpha = 0 is used.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this