Jump to content

  • Log In with Google      Sign In   
  • Create Account


Setting texture in effect pass


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 burnt_casadilla   Members   -  Reputation: 414

Like
0Likes
Like

Posted 16 July 2013 - 03:26 AM

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 :)


Sponsor:

#2 Tarika   Members   -  Reputation: 481

Like
0Likes
Like

Posted 16 July 2013 - 06:08 AM

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


#3 burnt_casadilla   Members   -  Reputation: 414

Like
0Likes
Like

Posted 16 July 2013 - 07:54 AM

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 :)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS