Simple d3d9 sample does not work in BMax
BlitzMax Forums/BlitzMax Programming/Simple d3d9 sample does not work in BMax
| ||
| Hi, I am currently working on the d3d9 port of miniB3dExtended. The main part of the implementation is nearly finished for a while, but when testing the whole thing...the screen keeped black. So, after hours of debugging I wrote a small hardcoded d3d9 sample, but it is the same -> nothing is be rendered! The strange thing is, that exactly the same source works fine with vc8... May be one of you knows what's wrong..
strict
local win:tGAdget = createwindow("test",32,32,832,632)
local hwnd:int = QueryGadget(win,QUERY_HWND)
local d3d9Graphics:Direct3d = new Direct3d
d3d9Graphics._Init(hwnd,800,600,false)
local lpD3DDevice:IDirect3DDevice9 = d3d9Graphics.GetDevice()
Type _TriangleVertices
Field x1:Float = 320.0
Field y1:Float = 150.0
Field z1:Float = 0.0
Field r1:Float = 1.0
Field c1:Int = $FF0000FF
Field x2:Float = 400.0
Field y2:Float = 330.0
Field z2:Float = 0.0
Field r2:Float = 1.0
Field c2:Int = $FFFF0000
Field x3:Float = 240.0
Field y3:Float = 330.0
Field z3:Float = 0.0
Field r3:Float = 1.0
Field c3:Int = $FF00FF00
End Type
Local TriangleVertices:_TriangleVertices = New _TriangleVertices
Local D3D_CUSTOMVERTEX:Int = (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
Local VertexBufferStart:Byte Ptr
Local VB_Triangle:IDirect3DVertexBuffer9 = Null
if lpD3DDevice.CreateVertexBuffer( 60,D3DUSAGE_WRITEONLY,D3D_CUSTOMVERTEX,D3DPOOL_MANAGED,VB_Triangle, Null) <> D3D_OK then
notify "faild to create vb"
end
endif
if VB_Triangle.Lock(0, 60, VertexBufferStart, 0) <> DD_OK then
notify "cant lock vb"
end
end if
MemCopy(VertexBufferStart, byte ptr ( TriangleVertices ), Sizeof(_TriangleVertices))
VB_Triangle.Unlock()
lpD3DDevice.SetFVF(D3D_CUSTOMVERTEX)
repeat
'waitevent
d3d9Graphics.BeginScene()
lpD3DDevice.SetStreamSource(0, VB_Triangle, 0, 60) ;
lpD3DDevice.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1) ;
d3d9Graphics.EndScene()
until KeyHit(Key_Escape)
end
type Direct3d
field clsColor :int = $FF0000FF
Field Direct3D9 :IDirect3D9 = null
Field Direct3DDevice9 :IDirect3DDevice9 = null
Field BackBuffer :IDirect3DSurface9 = null
field PParams :D3DPRESENT_PARAMETERS = null
field hwnd :int = 0
Method _Init(hwnd:int, w:Int, h:Int, bWindowed:Int = false)
Self.hwnd = hwnd
Direct3D9 = Direct3DCreate9( $900 )
if not Direct3D9 then
notify "error creating d3d9interface!"
end
endif
PParams = New D3DPRESENT_PARAMETERS
PParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
PParams.hDeviceWindow = hwnd;
PParams.Windowed = bWindowed;
PParams.BackBufferWidth = w;
PParams.BackBufferHeight = h;
PParams.BackBufferFormat = D3DFMT_A8R8G8B8;
local hr:int
hr = Direct3D9.CreateDevice( 0 ,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,PParams,Direct3DDevice9) <> D3D_OK
if hr then
notify "error creating d3d9device!"
end
endif
Direct3DDevice9.GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, BackBuffer );
end method
method SetClsColor(r:int,g:int,b:int)
clsColor = Int(( 255 Shl 24)| (r Shl 16)| (g Shl 8)| b )
end method
method BeginScene()
Direct3DDevice9.Clear(0,null,D3DCLEAR_TARGET,clsColor,0,0);
Direct3DDevice9.BeginScene();
end method
method EndScene()
Direct3DDevice9.EndScene();
Direct3DDevice9.Present(null,null,null,null);
end method
method GetDevice:IDirect3DDevice9()
return Direct3DDevice9
end method
method GetBackBuffer:IDirect3DSurface9()
return BackBuffer
end method
end type
|
| ||
| I dont have time to debug your code but take a look at my Dx9 Max2d driver. It works http://smokenmirrors.com/Downloads/Dx9Max2d(05).zip Doug |
| ||
the answer is simple: the code is just wrong.Strict
Local win:tGAdget = CreateWindow("test",32,32,832,632)
Local hwnd:Int = QueryGadget(win,QUERY_HWND)
Local d3d9Graphics:Direct3d = New Direct3d
d3d9Graphics._Init(hwnd,800,600,False)
Local lpD3DDevice:IDirect3DDevice9 = d3d9Graphics.GetDevice()
Type _TriangleVertices
Field x1:Float = 320.0
Field y1:Float = 150.0
Field z1:Float = 0.0
Field r1:Float = 1.0
Field c1:Int = $FF0000FF
Field x2:Float = 400.0
Field y2:Float = 330.0
Field z2:Float = 0.0
Field r2:Float = 1.0
Field c2:Int = $FFFF0000
Field x3:Float = 240.0
Field y3:Float = 330.0
Field z3:Float = 0.0
Field r3:Float = 1.0
Field c3:Int = $FF00FF00
End Type
Local TriangleVertices:_TriangleVertices = New _TriangleVertices
Local D3D_CUSTOMVERTEX:Int = (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
Local VertexBufferStart:Byte Ptr
Local VB_Triangle:IDirect3DVertexBuffer9 = Null
If lpD3DDevice.CreateVertexBuffer( 60,D3DUSAGE_WRITEONLY,D3D_CUSTOMVERTEX,D3DPOOL_MANAGED,VB_Triangle, Null) <> D3D_OK Then
Notify "faild to create vb"
End
EndIf
If VB_Triangle.Lock(0, 60, VertexBufferStart, 0) <> DD_OK Then
Notify "cant lock vb"
End
End If
MemCopy(VertexBufferStart, Byte Ptr ( TriangleVertices ), SizeOf(_TriangleVertices))
VB_Triangle.Unlock()
lpD3DDevice.SetFVF(D3D_CUSTOMVERTEX)
Repeat
'waitevent
If d3d9Graphics.BeginScene()
lpD3DDevice.SetStreamSource(0, VB_Triangle, 0, 20) ;
lpD3DDevice.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1) ;
lpD3DDevice.EndScene()
EndIf
lpD3DDevice.Present(Null,Null,Null,Null);
Until KeyHit(Key_Escape)
End
Type Direct3d
Field clsColor :Int = $FF0000FF
Field Direct3D9 :IDirect3D9 = Null
Field Direct3DDevice9 :IDirect3DDevice9 = Null
Field BackBuffer :IDirect3DSurface9 = Null
Field PParams :D3DPRESENT_PARAMETERS = Null
Field hwnd :Int = 0
Method _Init(hwnd:Int, w:Int, h:Int, bWindowed:Int = False)
Self.hwnd = hwnd
Direct3D9 = Direct3DCreate9( $900 )
If Not Direct3D9 Then
Notify "error creating d3d9interface!"
End
EndIf
PParams = New D3DPRESENT_PARAMETERS
PParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
PParams.hDeviceWindow = hwnd;
PParams.Windowed = bWindowed;
PParams.BackBufferWidth = w;
PParams.BackBufferHeight = h;
PParams.BackBufferFormat = D3DFMT_A8R8G8B8;
Local hr:Int
hr = Direct3D9.CreateDevice( 0 ,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,PParams,Direct3DDevice9) <> D3D_OK
If hr Then
Notify "error creating d3d9device!"
End
EndIf
Direct3DDevice9.GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, BackBuffer );
End Method
Method SetClsColor(r:Int,g:Int,b:Int)
clsColor = Int(( 255 Shl 24)| (r Shl 16)| (g Shl 8)| b )
End Method
Method BeginScene()
Direct3DDevice9.Clear(0,Null,D3DCLEAR_TARGET,clsColor,0,0);
Return Direct3DDevice9.BeginScene();
End Method
Method EndScene()
Direct3DDevice9.EndScene();
Direct3DDevice9.Present(Null,Null,Null,Null);
End Method
Method GetDevice:IDirect3DDevice9()
Return Direct3DDevice9
End Method
Method GetBackBuffer:IDirect3DSurface9()
Return BackBuffer
End Method
End Type
¨hard to believe it worked in C++, as the setstreamsource definitely broke it. There you normaly set sizeof(D3DVertex) in this case 20 the expanded code as well does correct checks for BeginScene succeeded before putting the triangle on it and end the scene. |
| ||
| thanks Dreamora...I am really blind :) In c++ I wrote certainly lpD3DDevice->SetStreamSource(0,VB_Triangle,0,sizeof(CVertex)); |