can't get Texture to draw in DirectX
-
Hi, I'm just starting out with DirectX and am running into some trouble (I've been piecing parts of examples together). I have a couple rectangles that yaw, roll, and pitch as they zoom in. When they come back to face the front (so it only looks 2d), I stop the movement and add a couple triangles. Up to here it works just fine. Now I'd like to add a bitmap under the rectangles but run into trouble. I have:
private override OnPaint() {
some twirling of boxes for a few seconds that become still with this line:DrawBox(0.0f, 0.0f, 0.0f, -0.45f, 0.8f, 9.5f);
(code for DrawBox below) then I add a couple triangles...CustomVertex.TransformedColored[] vert = new CustomVertex.TransformedColored[3];
... describe the vert ...device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vert);
Things work fine up to here. At this point I'd like to add my bitmap (Texture tex). I change the VertexFormat and call DrawBitmapBox (this is how one example added a texture to a box):device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, vb, 0);
vb is the VertexBuffer - also belowDrawBitmapBox(0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 9.5f, tex);
(code also below)}
Instead of drawing the bitmap image, the original rectangles themselves kind of blink (not at any contant rate), while the triangles just sit there like everything's ok. I know I'm probably making some obvious mistake(s), but any help in getting this bitmap up would be great!!! :) Mel DrawBoxprivate void DrawBox(float yaw, float pitch, float roll, float x, float y, float z) { angle += 0.01f; device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z); Material boxMaterial = new Material(); device.Lights[0].Type = LightType.Directional; device.Lights[0].Diffuse = Color.Red; device.Lights[0].Direction = new Vector3(0,-1,-1); device.Lights[0].Commit(); device.Lights[0].Enabled = true; boxMaterial.Diffuse = Color.White; device.Material = boxMaterial; mesh.DrawSubset(0); }
DrawBitmapBoxprivate void DrawBitmapBox(float yaw, float pitch, float roll, float x, float y, float z, Texture t) { angle += 0.00f; device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z); device.SetTexture(0, t); device.
-
Hi, I'm just starting out with DirectX and am running into some trouble (I've been piecing parts of examples together). I have a couple rectangles that yaw, roll, and pitch as they zoom in. When they come back to face the front (so it only looks 2d), I stop the movement and add a couple triangles. Up to here it works just fine. Now I'd like to add a bitmap under the rectangles but run into trouble. I have:
private override OnPaint() {
some twirling of boxes for a few seconds that become still with this line:DrawBox(0.0f, 0.0f, 0.0f, -0.45f, 0.8f, 9.5f);
(code for DrawBox below) then I add a couple triangles...CustomVertex.TransformedColored[] vert = new CustomVertex.TransformedColored[3];
... describe the vert ...device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vert);
Things work fine up to here. At this point I'd like to add my bitmap (Texture tex). I change the VertexFormat and call DrawBitmapBox (this is how one example added a texture to a box):device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, vb, 0);
vb is the VertexBuffer - also belowDrawBitmapBox(0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 9.5f, tex);
(code also below)}
Instead of drawing the bitmap image, the original rectangles themselves kind of blink (not at any contant rate), while the triangles just sit there like everything's ok. I know I'm probably making some obvious mistake(s), but any help in getting this bitmap up would be great!!! :) Mel DrawBoxprivate void DrawBox(float yaw, float pitch, float roll, float x, float y, float z) { angle += 0.01f; device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z); Material boxMaterial = new Material(); device.Lights[0].Type = LightType.Directional; device.Lights[0].Diffuse = Color.Red; device.Lights[0].Direction = new Vector3(0,-1,-1); device.Lights[0].Commit(); device.Lights[0].Enabled = true; boxMaterial.Diffuse = Color.White; device.Material = boxMaterial; mesh.DrawSubset(0); }
DrawBitmapBoxprivate void DrawBitmapBox(float yaw, float pitch, float roll, float x, float y, float z, Texture t) { angle += 0.00f; device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z); device.SetTexture(0, t); device.
Are the dimensions of your bitmap powers of 2? If I recall correctly they have to be powers of two to work as textures. I hope this helps. Deus caritas est