Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. can't get Texture to draw in DirectX

can't get Texture to draw in DirectX

Scheduled Pinned Locked Moved C#
graphicsgame-devhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    melanieab
    wrote on last edited by
    #1

    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 below DrawBitmapBox(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 DrawBox private 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); } DrawBitmapBox private 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.

    A 1 Reply Last reply
    0
    • M melanieab

      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 below DrawBitmapBox(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 DrawBox private 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); } DrawBitmapBox private 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.

      A Offline
      A Offline
      Andy Moore
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups