Line Antialias.

BlitzMax Forums/BlitzMax Programming/Line Antialias.

Can people test the following for GL and DX drivers?
The GL drawlineaa works for me but I don't have a card which supports DX AA so no idea if it works.
SuperStrict
SetGraphicsDriver GLMax2DDriver()
Graphics 640,480
Global mycaps:TG_D3DDEVICEDESC7
If _max2dDriver.ToString() = "DirectX7"
	mycaps = New TG_D3DDEVICEDESC7
	D3D7GraphicsDriver().Direct3DDevice7().getcaps mycaps
EndIf

While Not KeyHit(KEY_ESCAPE)
	Cls
	SetBlend ALPHABLEND
	If MouseDown(1)
		DRAWLINEAA 0,0,MouseX(),MouseY()
	Else
		DrawLine 0,0,MouseX(),MouseY()
	EndIf
	Flip
Wend

Function DRAWLINEAA(from_x:Float,from_y:Float,to_x:Float,to_y:Float)
	If _max2dDriver.ToString() = "DirectX7"
		If mycaps.dwRasterCaps_LINE & 4096
			Local D3DRS_EDGEANTIALIAS:Int=40
			D3D7GraphicsDriver().Direct3DDevice7().setRenderState D3DRS_EDGEANTIALIAS,True
			DrawLine from_x,from_y,to_x,to_y
			D3D7GraphicsDriver().Direct3DDevice7().setRenderState D3DRS_EDGEANTIALIAS,False
		Else
		    DebugLog "AA not supported"
     	    DrawLine from_x,from_y,to_x,to_y
		EndIf
	Else
		Local saveblend:Int=GetBlend()
		SetBlend alphablend
	    glEnable(GL_LINE_SMOOTH) 
		DrawLine from_x,from_y,to_x,to_y
		SetBlend saveblend
	    glDisable(GL_LINE_SMOOTH) 
	EndIf
End Function

Type TG_D3DDeviceDesc7
	Field dwDevCaps:Int
	Field dwSize_LINE:Int               'Size of structure
    Field dwMiscCaps_LINE:Int           'Miscellaneous capabilities
    Field dwRasterCaps_LINE:Int         'Raster capabilities
    Field dwZCmpCaps_LINE:Int           'Z-comparison capabilities
    Field dwSrcBlendCaps_LINE:Int       'Source-blending capabilities
    Field dwDestBlendCaps_LINE:Int      'Destination-blending capa bilities
    Field dwAlphaCmpCaps_LINE:Int       'Alpha-test-comparison capabilities
    Field dwShadeCaps_LINE:Int          'Shading capabilities
    Field dwTextureCaps_LINE:Int        'Texture capabilities
    Field dwTextureFilterCaps_LINE:Int  'Texture-filtering capabilities
    Field dwTextureBlendCaps_LINE:Int   'Texture-blending capabilities
    Field dwTextureAddressCaps_LINE:Int 'Texture-addressing capabilities
    Field dwStippleWidth_LINE:Int       'Stipple width
    Field dwStippleHeight_LINE:Int      'Stipple height
    Field dwSize_TRI:Int               'Size of structure
    Field dwMiscCaps_TRI:Int           'Miscellaneous capabilities
    Field dwRasterCaps_TRI:Int         'Raster capabilities
    Field dwZCmpCaps_TRI:Int           'Z-comparison capabilities
    Field dwSrcBlendCaps_TRI:Int       'Source-blending capabilities
    Field dwDestBlendCaps_TRI:Int      'Destination-blending capa bilities
    Field dwAlphaCmpCaps_TRI:Int       'Alpha-test-comparison capabilities
    Field dwShadeCaps_TRI:Int          'Shading capabilities
    Field dwTextureCaps_TRI:Int        'Texture capabilities
    Field dwTextureFilterCaps_TRI:Int  'Texture-filtering capabilities
    Field dwTextureBlendCaps_TRI:Int   'Texture-blending capabilities
    Field dwTextureAddressCaps_TRI:Int 'Texture-addressing capabilities
    Field dwStippleWidth_TRI:Int       'Stipple width
    Field dwStippleHeight_TRI:Int      'Stipple height
	Field      dwDeviceRenderBitDepth:Int
	Field      dwDeviceZBufferBitDepth:Int
	Field      dwMinTextureWidth:Int
	Field  	   dwMinTextureHeight:Int
	Field      dwMaxTextureWidth:Int
	Field 	   dwMaxTextureHeight:Int
	Field      dwMaxTextureRepeat:Int
	Field      dwMaxTextureAspectRatio:Int
	Field      dwMaxAnisotropy:Float
	Field      dvGuardBandLeft:Float
	Field      dvGuardBandTop:Float
	Field      dvGuardBandRight:Float
	Field      dvGuardBandBottom:Float
	Field      dvExtentsAdjust:Float
	Field      dwStencilCaps:Int
	Field      dwFVFCaps:Int
	Field      dwTextureOpCaps:Int
	Field      wMaxTextureBlendStages:Short
	Field      wMaxSimultaneousTextures:Short
	Field      dwMaxActiveLights:Int
	Field      dvMaxVertexW:Float
	Field      GUID_Interface_type:Int
	Field      GUID_1:Short
	Field      GUID_2:Short
	Field      GUID_3:Byte
	Field      GUID_4:Byte
	Field      GUID_5:Byte
	Field      GUID_6:Byte
	Field      GUID_7:Byte
	Field      GUID_8:Byte
	Field      GUID_9:Byte
	Field      GUID_10:Byte
	Field      wMaxUserClipPlanes:Short
	Field      wMaxVertexBlendMatrices:Short
	Field      dwVertexProcessingCaps:Int
	Field      dwReserved1:Int
	Field      dwReserved2:Int
	Field      dwReserved3:Int
	Field      dwReserved4:Int
End Type

P.S. If you do have a DX AA OK card and know what the AA code should be can you edit the code?
Thanks.

The GL set line smoothing works fine here on my Intel and PPC iMacs.

My linux seems to bork here :
Compile Error: Identifier 'D3D7GraphicsDriver' not found
[/home/brucey/programming/BlitzMax/tmp/untitled1.bmx;7;2]

which implies some code needs wrapped in "?".

But... line smoothing works fine for me using GL.

It smooths fine on my Windows system in GL when the mouse button is down, and it's sharp/jaggy with it up.

I then commented out "SetGraphicsDriver GLMax2DDriver()" to test DX and got "DebugLog:AA not supported" when pressing the mouse button (and the line remained sharp/jaggy). That was with my ATI Catalyst video driver at its default AA of "Use application settings." Turning it on manually in the control center provided AA smoothing for the line regardless of whether the mouse button was pressed or not (no DebugLog error when pressing it).

Your 9800 Pro might do the same?

@Brucey, I'm not too hot at '?' directives. I thought I split it DX and non-DX but don't know enough about Linux and don't have a system.
Can somebody with a Linux system suggest and/or test what needs to be included?
@WendellM, Hmmm, I don't get anti-aliasing whatever I do. I select 3D Settings / Anti-Aliasing / 2x.
I would hope that the DX EDGEANTIALIAS statements would count as 'Application Managed' but I will have to check further. It could just be I haven't got the DX commands right.
From checking the forums other people have manged to get DX line anti-alias working before so can they give this a once over?

Works in both DX and OpenGL on my PC, nice work! My DX AA drivers are set to "let App decide" or whatever. I can help with the technical stuff I'm afraid as it's not my area of knowledge.

Could I please add this to my framework (with a credit) even if you think it seems unreliable?

@GA, you can add it but I'd like to see any improvements (either technical or procedural) added here. I got much of the code from the forums and it was in response to cs_tbl request from the blitzmaxier thread.

sure no probs. For now I'm just book marking this page.