how to convert this dx9 stuff

BlitzMax Forums/BlitzMax Programming/how to convert this dx9 stuff

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

drago helped the cause, heres the codez for anyone interested (using a template from er scouse i think on these forums)

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