DX9

BlitzMax Forums/BlitzMax Beginners Area/DX9

Eric(Posted 2006) [#1]
How do I use the DX9 Driver that is located in the Mod Folder under dxgraphics.mod?

Is this a valid Module?


Dreamora(Posted 2006) [#2]
There is no DX9 driver
Thats only the DX9 declarations that were most likely used for the long ago "first showoff" of Max3D module.


Eric(Posted 2006) [#3]
Oh ok...thanks. I should have looked deeper.

Regards,
Eric


Grisu(Posted 2006) [#4]
Hopefully there will be bmx vista with 64Bit and Dx10 support. - I just like dreaming... :)


TartanTangerine (was Indiepath)(Posted 2006) [#5]
You can use dx9 now, you just need to make a few tweaks : (This is not my code and I can't remember where I got it from).
Strict

Global d3d:IDirect3D9
Global d3dDevice:IDirect3DDevice9
Global d3dVertexBuffer:IDIRECT3DVERTEXBUFFER9
Global d3dpp:D3DPRESENT_PARAMETERS
Global displaymode:D3DDISPLAYMODE
Global hwnd
Global pverts:Byte Ptr
Global fverts:Float Ptr
Global verts:Float[12]

Extern "win32"
 Function GetActiveWindow:Byte Ptr()
End Extern

Const D3DADAPTER_DEFAULT = 0
Const D3DPRESENT_INTERVAL_ONE = 1
Const D3DPRESENT_INTERVAL_IMMEDIATE = $80000000

Function InitDx(Width,Height,Depth,Fullscreen,VSync,UseHardware) 

 Graphics width,height,0,0
 hWnd = Int(GetActiveWindow())

 If d3d Then Return

 d3d = Direct3DCreate9($900)
 If Not d3d Then 
  Throw("Couldn't initialize direct3d!")
 EndIf

 If hwnd = 0 Then
  Throw("Couldn't find window!")
 EndIf

 d3dpp = New D3DPRESENT_PARAMETERS

 displaymode = New D3DDISPLAYMODE
 d3d.GetAdapterDisplayMode(D3DADAPTER_DEFAULT,displaymode)

 MemClear(d3dpp, SizeOf(d3dpp) )

 d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP    
 If Fullscreen = False Then
  d3dpp.Windowed = True
 Else
  d3dpp.Windowed = False
 EndIf
 d3dpp.BackBufferFormat = displaymode.Format
 d3dpp.EnableAutoDepthStencil = True
 d3dpp.AutoDepthStencilFormat = D3DFMT_D16 
 d3dpp.PresentationInterval = 1

 If Fullscreen=True Then
  d3dpp.BackBufferWidth = Width
  d3dpp.BackBufferHeight = Height
        
  If Depth=32 Then
   d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8
  Else
   d3dpp.BackBufferFormat = D3DFMT_R5G6B5
  EndIf     

   d3dpp.BackBufferCount = 0;
 EndIf

 If VSync = True Then d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE

 If UseHardware = False Then
  d3d.CreateDevice(0,D3DDEVTYPE_REF,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,d3dpp,d3dDevice)

  If Not d3dDevice Then
   Throw("Failed to create software device!")
  EndIf

 Else

  If d3d.CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,d3dpp,d3dDevice)<>D3D_OK Then
  	 If d3d.CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_MIXED_VERTEXPROCESSING,d3dpp,d3dDevice)<>D3D_OK Then
    	If d3d.CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,d3dpp,d3dDevice)<>D3D_OK Then
		 Throw("Failed to create device!")
        EndIf
     EndIf
  EndIf    

 EndIf

 Print "Device ready!"

End Function


InitDx(640,480,0,False,False,False)
CreateTriangle()

While Not KeyHit(KEY_ESCAPE)

	d3dDevice.Clear(0,Null,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,$453670,1.0,0)
	d3dDevice.BeginScene()
	renderTriangle()
	d3dDevice.EndScene()
	d3dDevice.Present(Null,Null,Null,Null)


Wend


Function CreateTriangle()
d3dDevice.CreateVertexBuffer(16*3, 0, D3DFVF_XYZRHW, D3DPOOL_MANAGED, d3dVertexBuffer,Null)

pVerts = verts
verts[0]=50
verts[1]=200
verts[2]=0
verts[3]=150

verts[4]=50.0
verts[5]=0.0
verts[6]=0
verts[7]=1

verts[8]=250.0
verts[9]=200.0
verts[10]=0
verts[11]=1

d3dVertexBuffer.Lock(0,16*3,pverts,0)
MemCopy(pverts,verts,16*3)
MemCopy(verts,pverts,16*3)
Print verts[0]+" "+verts[1]+" "+verts[2]+" "+verts[3]
Print verts[4]+" "+verts[5]+" "+verts[6]+" "+verts[7]
Print verts[8]+" "+verts[9]+" "+verts[10]+" "+verts[11]
d3dVertexBuffer.Unlock()


End Function

Function RenderTriangle()
	 d3dDevice.SetStreamSource(0,d3dVertexBuffer,0,16)
	 d3dDevice.SetFVF(D3DFVF_XYZRHW)
	 d3dDevice.SetTexture(0,Null)
	 d3dDevice.SetVertexShader( Null )
	 d3dDevice.DrawPrimitive(D3DPT_TRIANGLELIST,0,3)	
End Function



LarsG(Posted 2006) [#6]
hey.. that's pretty cool..
still.. it makes me appreciate OpenGL more.. lol

[edit] I didn't get it to work either, so that didn't help.. hehe [/edit]


Leiden(Posted 2006) [#7]
Change to InitDX call to
InitDx(640,480,32,True,True,true)



kfprimm(Posted 2006) [#8]
$900, is that the value of D3D_SDK_VERSION?


TartanTangerine (was Indiepath)(Posted 2006) [#9]
oh how they jest.


Leiden(Posted 2006) [#10]
Yup it is, They *could* have just used 'D3D_SDK_VERSION' instead...