Setting texture in effect pass

Started by
1 comment, last by ChristianFrantz 10 years, 9 months ago

I created different types of cubes for my cube class and based on the height of the cube, the cube type is different. This means changing the texture for the cube.


if (y >= 1)
                        {
                            SetUpIndicesAndVertices(x, map[x, z] - y, z, vertices, indices);
                            cubes.Add(new Cube.Stone(device, new Vector3(x, map[x, z] - y, z), stone));
                        }

                        else
                        {
                            SetUpIndicesAndVertices(x, map[x, z] - y, z, vertices, indices);
                            cubes.Add(new Cube.Grass(device, new Vector3(x, map[x, z] - y, z), grass));
                        }

So I thought this would work, but my texture for all cubes is still grass. I noticed in my draw method these few lines:


 foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                no++;
                pass.Apply();
                effect.VertexColorEnabled = false;
                effect.TextureEnabled = true;
                effect.Texture = grass;

Which sets every cube to grass. Is there a way that I can set the texture based on each cube type in the list "cubes"?

If you see a post from me, you can safely assume its C# and XNA :)

Advertisement

Short answer is not quite :) what you could do is group the cubes by texture, then set the texture only when you start to draw another group. Like I said in a previous thread if this is not possible, then your next option is to pack all the textures you need into 1 big texture, this involves manipulating the UV texture coordinates in order for that particular "sub-texture" to be used. If you get stuck feel free to pm me on skype (XpodGames).

Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

Well the cubes will be manipulated almost all the time, so setting all of them into one big texture might be an issue. I don't know much about texture atlases, but each cube has the same texture on all sides so that shouldn't be too hard

If you see a post from me, you can safely assume its C# and XNA :)

This topic is closed to new replies.

Advertisement