Quantumdude

I want to use a single instance of Texture2D and a single bitmap image for a skybox. The image contains six smaller images that represent the skybox panels. If I use values between 0 and 1 for the texture coordinates, they seem to get rounded. Is there anyway I could use a texture sheet and use values between 0 and 1 as the texture coordinates, or do I have to create an instance of Texture2D every time I want a separate texture


Re: XNA Framework Texture Coordinate Issues

Pocketmnky

As far as I know, not only is it possible; it's pretty much standard practice for any unwrapped mesh. Check out the ship meshes and their diffuse maps from the spacewar startup kit. Basically how texture mapping works is that you take the texture, (any 2D image) and assign 0,0 to the top left corner, and 1,1 to the bottom right corner. Then for each of the vertex's texture coordinates you assign them to whatever part that coordinate system you want the vertex to represent. You could easily have a vertex point to (.3333f, .5f) which would be 1/3rd of the way across, and halfway down on your texture, etc.






Re: XNA Framework Texture Coordinate Issues

Quantumdude

This is what I've tried before:

skyboxVertexList[0].TextureCoordinates = new Vector2((float)(2 / 4), (float)(1 / 3));

When I debug it, it shows the values to be either 0 or 1. Do I have to use meshes in order for this to work, because I've just been using vertex lists.






Re: XNA Framework Texture Coordinate Issues

Pocketmnky

Oh; that would be a syntax mistake. try

skyboxVertexList[0].TextureCoordinates = new Vector2((2f / 4f), (1f / 3f));

In C#, if you don't case the denominator as a float, it'll always cast return an int. What you were doing was taking 2 / 4 (0.5) casting as an int (1) and then casting as a float (1.0f) for the x, taking 1 / 3 (0.3333) casting as int (0) and then casting it to float (0.0f)

I do that ALL the time.






Re: XNA Framework Texture Coordinate Issues

Quantumdude

Ah, I see. Thanks, it works now.