abhi2011 Posted April 2, 2014 Author Share Posted April 2, 2014 Hi guys, I was brainstorming to find a way to render a line in DX8 for a various purposes and I found that DX8 didn't have a method to render a line with a width. It'll always have a width of I think 1 pixel. So I googled and found the only way this was possible is by rendering a Quadrilateral with a length and a width. So here is my function for this: ```Public Sub RenderLine(ByVal x As Long, ByVal y As Long, width As Long, ByVal length As Long, ByVal Colour As Long, Optional ByVal Horizontal As Boolean = True) Dim linev(0 To 3) As TLVERTEX, i As Long ' THIS PROCEDURE DOES NOT USE D3DPT_LINESTRIP. It USES QUADS TO SIMULATE A LINE. For i = 0 To 3 linev(i).color = dx8Colour(colour, -1) linev(i).RHW = 1 Next If Horizontal Then linev(0).x = x linev(0).y = y linev(1).x = x + width linev(1).y = y linev(2).x = x linev(2).y = y + length linev(3).x = x + width linev(3).y = y + length Else linev(0).x = x linev(0).y = y linev(1).x = x + length linev(1).y = y linev(2).x = x linev(2).y = y + width linev(3).x = x + length linev(3).y = y + width End If Call D3DDevice8.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, linev(0), FVF_Size)End Sub```This accepts a x and y coordinate as the start position of the "line" and a length for the line and it's width. A color can also be given. The last variable is for determining how to render the line. Along the x axis or the y axis. One problem to this that you can't (or I don't think you can) render a line diagonally. If you can't understand a specific part of the above code post below and I'll be glad to help. Link to comment Share on other sites More sharing options...
Stach Posted April 2, 2014 Share Posted April 2, 2014 Diagonal:```linev(0).x = xlinev(0).y = ylinev(1).x = x + widthlinev(1).y = y - widthlinev(2).x = x + lengthlinev(2).y = y + lengthlinev(3).x = linev(1).x + lengthlinev(3).y = linev(1).y + length```Now all you have to do is tell it which way to go (this goes from left to right), but this is the basics. Link to comment Share on other sites More sharing options...
YourBestNightmare Posted October 6, 2014 Share Posted October 6, 2014 If you understand basic maths then you can make this working at any angle, not only diagonal, horizontal or vertical lines. Link to comment Share on other sites More sharing options...
abhi2011 Posted October 7, 2014 Author Share Posted October 7, 2014 > If you understand basic maths then you can make this working at any angle, not only diagonal, horizontal or vertical lines.Yes, yes you can except none of this works… DX8 is crap. Link to comment Share on other sites More sharing options...
Growlith1223 Posted October 7, 2014 Share Posted October 7, 2014 Dx8 is not the one in the wrong right now, it's your code. for one, you'd want to use D3DPT_LINESTRIP instead of a trianglestrip. linestrip uses 2 points, instead of what YOU are doing, which is 4 points… Link to comment Share on other sites More sharing options...
YourBestNightmare Posted October 7, 2014 Share Posted October 7, 2014 ```Private buffer As Direct3DVertexBuffer8Const fvfUDVertex = (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE)Public Sub DrawPolyLine(Vertices() As typUDVertex, lPointCount As Integer)Dim VertexSize As LongVertexSize = Len(Vertices(0))Set buffer = d_D3DDevice.CreateVertexBuffer(VertexSize * lPointCount, 0, fvfUDVertex, D3DPOOL_DEFAULT)Call D3DVertexBuffer8SetData(buffer, 0, VertexSize * lPointCount, 0, Vertices(0))d_D3DDevice.SetStreamSource 0, buffer, VertexSized_D3DDevice.SetVertexShader fvfUDVertexd_D3DDevice.DrawPrimitive D3DPT_LINESTRIP, 0, lPointCount - 1End Sub ```Nope, isn´t that big crap that it cannot handle basic shapes. With this f.e. you can draw basic polyline using DX8: Link to comment Share on other sites More sharing options...
abhi2011 Posted October 7, 2014 Author Share Posted October 7, 2014 > Dx8 is not the one in the wrong right now, it's your code. for one, you'd want to use D3DPT_LINESTRIP instead of a trianglestrip. linestrip uses 2 points, instead of what YOU are doing, which is 4 points…Using a line strip or a triangle strip doesn't matter. The rendered image won't show up. I never could figure out why. > ```> Private buffer As Direct3DVertexBuffer8> Const fvfUDVertex = (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE)> > Public Sub DrawPolyLine(Vertices() As typUDVertex, lPointCount As Integer)> Dim VertexSize As Long> VertexSize = Len(Vertices(0))> > Set buffer = d_D3DDevice.CreateVertexBuffer(VertexSize * lPointCount, 0, fvfUDVertex, D3DPOOL_DEFAULT)> Call D3DVertexBuffer8SetData(buffer, 0, VertexSize * lPointCount, 0, Vertices(0))> d_D3DDevice.SetStreamSource 0, buffer, VertexSize> d_D3DDevice.SetVertexShader fvfUDVertex> d_D3DDevice.DrawPrimitive D3DPT_LINESTRIP, 0, lPointCount - 1> End Sub > ```> Nope, isn´t that big crap that it cannot handle basic shapes. With this f.e. you can draw basic polyline using DX8:Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now