I am trying to texture the faces of a cube independently using Managed Direct X. The cube is first created by using the Mesh.Box method. Its vertices are then converted to a PositionNormalTextured format and the texture location then set.
This works are the moment because all but one face is set just to use the first pixel of the texture which the program has already set to theses faces background colour. The face I want textured then uses the rest of the texture. This works ok, however now I want to use one of the other faces, with another texture.
The problem is I want to be able to move this texture independent of the first, which I assume means I need to use a second texture object. Is there someway of specifying each vertexes texture location for each texture separately.
Is there a better way to achieve this, it seems very long winded and very hackish (if that’s a word). I am not usually adverse to hackish coding but this seems to taking it to extremes J.
Is it possible to render each face of the cube separately allowing me to change the devices texture in the mean time

Texturing Cube Faces Separately
BA08
You can build your own vertex buffer from the scratch with the positions, normal’s and texture coordinates you want. After you have done this you can render each face separate and change the texture between the draw calls.
Have to look like this:
SetTexture (0, texface1);
DrawPrimitive (D3DPT_TRIANGLESTRIP, 0, 2)
SetTexture (0, texface2);
DrawPrimitive (D3DPT_TRIANGLESTRIP, 4, 2)
SetTexture (0, texface3);
DrawPrimitive (D3DPT_TRIANGLESTRIP, 8, 2)
…
Or use a loop for it.
Andrea_1
I think I will experiment with trying to draw each face separatly. My only worry is how I apply the transformation to each face relative to its position in the cube as the Mesh class kindly takes care of that for me at the momment.
Thanks for the feed back everyone.
vov4uk
My problem is now for one of the faces I want to have two textrues. I know I can use texture stages to do this but I am strugling to combine them properly. I have two textures, there is a base texture and a top one. The top one has a large amount of transparent pixels in it. I only want the base texture to show through where the top one is transparent. Below are my current texture states (stage 0 is the base and 1 the top texture).
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
device.TextureState[1].ColorArgument1 = TextureArgument.Current;
device.TextureState[1].ColorArgument2 = TextureArgument.TextureColor;
device.TextureState[1].ColorOperation = TextureOperation.AddSigned;
The above code just blends the two textures togeather. How is it best to combine the textures to acheave the effect I described
chrisharden
You can still use for all faces positions that are relative to the same base (the center of the cube). In this case you don’t need to change the transformation for each face.
Bells
There are two possible problems here, from your description I'm not entirely sure which yours is though..
In your instance you have one texture coordinate per vertex, that is, any triangle that shares this vertex (can be as many as 6 for a cube) will also "inherit" this part of the texture. If you want two faces to use different parts of the texture you'll have to duplicate the vertex. Trying to get a single vertex to contain the properties of two different ones can be done, but it's both ugly and unintuitive as well as a bit pointless
A simple cube can be defined using 8 vertices and 36 indices - off the top of my head I think that's what Mesh.Box( ) will be giving you. Instead, you really want to have 24 vertices and 36 indices. That way you can set independent properties for texture coordinates and normals for each face of the cube.
You might not have seen it yet, but if you use an 8-vertex cube you won't be able to generate normal vectors that give "sharp lighting" like you'd expect from a cube - you'll end up with a sort of sphere like lighting shape...
The second thing you mention is about different faces using different textures. You will have to split them up into multiple draw calls if you use seperate texture objects. Apart from some strange hacks, you can't really change a texture mid-way through a draw call - the geometry you pass via a draw call assumes the state of the pipeline at the time it was drawn.
hth
Jack
Jonn
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[1].ColorArgument2 = TextureArgument.Current;
device.TextureState[1].ColorOperation = TextureOperation.BlendTextureAlpha;