directx 9

BlitzMax Forums/BlitzMax Programming/directx 9

nawi(Posted 2005) [#1]
How can I enable directx 9 commandset in blitzmax? Specially D3D


Sweenie(Posted 2005) [#2]
What do you mean by enabling it?
It's there by default, unless you're using Framework.

Try this...
Strict

Global d3d:IDirect3D9
Global d3dDevice:IDirect3DDevice9
Global d3dpp:D3DPRESENT_PARAMETERS
Global displaymode:D3DDISPLAYMODE
Global hwnd

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,True)

Local PresentResult
Local LostDevice = False

While Not KeyHit(KEY_ESCAPE)

 d3dDevice.Clear(0,Null,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,$406080,1.0,0)

 If LostDevice = False Then 

  PresentResult = d3dDevice.Present(Null,Null,Null,Null)

  If PresentResult = D3DERR_DEVICELOST Then
   LostDevice = True
   Print "Lost device"
  EndIf

 EndIf

Wend





nawi(Posted 2005) [#3]
thanks for the tuto.