Sign in to follow this  

Setting texture in effect pass

This topic is 1646 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

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"?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


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