Change Line width in Direct3D

Is there any simple way to draw a thick line in Direct3D In OGL one can simple set linewidth by call glLineWidth(). Is there a similiar method in D3D

Thanks!


Answer this question

Change Line width in Direct3D

  • ChrisC11

    Just as a quick follow up. I mentioned that I would probably wrap all that code in a generic line creation function, well I went ahead and whipped up a quick and dirty DirectX line class wrapper to hide most of what you need to do to draw a line.

    I figured I would probably end up wanting to draw lines for my own project and I would want to make it as simple of a process as possible so this is what I came up with.

    Here it is if anyone is interested. I'm not saying this is the best solution and I definitely welcome any feedback about what I'm doing right or wrong. Anyway, hope it helps someone out.


  • Ewoud

    Use the line class in Direct3DX - it renders the lines as quads so you can go as think as you want.

  • murpheux

    Just by way of reference: ID3DXLine is the class you want to look into (See D3DXCreateLine()), the ID3DXLine::SetWidth( ) function being the one of interest to you...

    hth
    Jack



  • Michael Green - MSFT

    I'm glad you answered that one before I had my answer ready ZMan. I was creating my own line class, talk about re-inventing the wheel or the Line in this case....

    Well, now that I know there is a DirectX Line class, here's one way to use it to draw a line (not sure if it's the correct way, but it renders a line for me so I know it's ONE way to use it at least)


    Public Sub Render()
            mDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0), 1.0F, 0)
            mDevice.BeginScene()

            'Creating a Line object (mDevice is a Device Object)
            Dim aLine As New Microsoft.DirectX.Direct3D.Line(mDXEngine.myDevice)

            'Create the Line vectors
            Dim aLineVectors(1) As Microsoft.DirectX.Vector2

            'Set the starting point of the line
            aLineVectors(0).X = 5
            aLineVectors(0).Y = 100

            'Set the ending point of the line
            aLineVectors(1).X = 500
            aLineVectors(1).Y = 100

            'Give the line it's width (there's that width you were needing....)  
            aLine.Width = 5

            'Render the line
            aLine.Begin()
            aLine.Draw(aLineVectors, System.Drawing.Color.Blue)
            aLine.End()

            mDevice.EndScene()

            Try
                'Present the rendered scene
                mDevice.Present()
            Catch
            End Try
        End Sub

     


    You could of course create your own Line function and just pass in a starting point, ending point, width and color and hide all of these other steps needed, that's probably what I'll end up doing for my code just to make it even simpler to use the Line class.

    [Edit: There appears to be a bug in the way VB code is displayed, guess you're not supposed to use comments in your code.....]


  • PrashantT

    Cooool. You guys are so helpful! Thanks!
  • Change Line width in Direct3D