Directx 9 draw text problem
Posted: Sun Oct 24, 2010 1:21 am
It's my first time working with Directx...but it seems i can't draw text on the window.
Hum i have no idea whats wrong...
Hum i have no idea whats wrong...
Code: Select all
; ------------------------------------------------------------------------------------------------------
; Tutorial 2 - Rendering Vertices
; ------------------------------------------------------------------------------------------------------
; Constants
#D3DFMT_UNKNOWN = 0
#D3DSWAPEFFECT_DISCARD = 1
#D3DDEVTYPE_HAL = 1
#D3DADAPTER_DEFAULT = 0
#D3DCREATE_SOFTWARE_VERTEXPROCESSING = 32
#D3D_SDK_VERSION = 31
#D3DCLEAR_TARGET = 1
#D3DPOOL_DEFAULT = 0
#D3DFVF_XYZRHW = 4
#D3DFVF_DIFFUSE = 64
#D3DPT_TRIANGLELIST = 4
#FW_BOLD = 700
#DEFAULT_CHARSET = 1
#OUT_DEFAULT_PRECIS = 0
#DEFAULT_QUALITY = 0
#DEFAULT_PITCH = 0
#FF_DONTCARE = 0
#D3DFVF_CUSTOMVERTEX = #D3DFVF_XYZRHW | #D3DFVF_DIFFUSE
; Structures
Structure D3DPRESENT_PARAMETERS
BackBufferWidth.l
BackBufferHeight.l
BackBufferFormat.l
BackBufferCount.l
MultiSampleType.l
MultiSampleQuality.l
SwapEffect.l
hDeviceWindow.l
Windowed.l
EnableAutoDepthStencil.l
AutoDepthStencilFormat.l
flags.l
FullScreen_RefreshRateInHz.l
PresentationInterval.l
EndStructure
Structure CUSTOMVERTEX
X.f
Y.f
Z.f
RHW.f ; The transformed position for the vertex.
Color.l ; The vertex color.
EndStructure
; Macros
Macro D3DCOLOR_ARGB(A,R,G,B)
(A & $FF) << 24 | (R & $FF) << 16 | (G & $FF) << 8 | (B & $FF)
EndMacro
Macro D3DCOLOR_XRGB(R,G,B)
D3DCOLOR_ARGB($FF,R,G,B)
EndMacro
Declare Render(void)
Declare Cleanup()
Declare InitDX9(hwnd)
Declare SetVertex(Index,X,Y,Z,RHW,Color)
; Direct3D Interfaces
Global g_pD3D.IDirect3D9
Global g_pd3dDevice.IDirect3DDevice9
Global g_ID3DXFont.ID3DXFont
Global g_pVB.IDirect3DVertexBuffer9
Global d3dpp.D3DPRESENT_PARAMETERS
;app vars
Global WID, hWnd, *pVertices, Event ,VertextBufferSize
Global Dim vertices.CUSTOMVERTEX(2)
Procedure SetVertex(Index,X,Y,Z,RHW,Color)
vertices(Index)\X = X
vertices(Index)\Y = Y
vertices(Index)\Z = Z
vertices(Index)\RHW = RHW
vertices(Index)\Color = Color
EndProcedure
Procedure InitDX9(hwnd)
OpenLibrary(0,"D3D9.dll")
OpenLibrary(1, "d3dx9.dll")
g_pD3D = CallFunction(0,"Direct3DCreate9",#D3D_SDK_VERSION)
d3dpp\Windowed = #True
d3dpp\SwapEffect = #D3DSWAPEFFECT_DISCARD
d3dpp\BackBufferFormat = #D3DFMT_UNKNOWN
g_pD3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,hwnd,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,d3dpp,@g_pd3dDevice)
ProcedureReturn g_pD3D
EndProcedure
Procedure Render(void)
rcte.RECT
rcte\left = 0
rcte\right = 100
rcte\top = 0
rcte\bottom = 100
*Color = D3DCOLOR_ARGB(255, 0, 0, 255)
While 1
g_pd3dDevice\Clear(0,0,#D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255),1.0,0)
g_pd3dDevice\BeginScene()
g_pd3dDevice\SetStreamSource(0,g_pVB,0,SizeOf(CUSTOMVERTEX))
g_pd3dDevice\SetFVF(#D3DFVF_CUSTOMVERTEX)
g_pd3dDevice\DrawPrimitive(#D3DPT_TRIANGLELIST,0,1)
Debug g_ID3DXFont\DrawTextA(#Null, "Demo", -1, @rcte, #DT_CENTER, *Color)
g_pd3dDevice\EndScene()
g_pd3dDevice\Present(0,0,0,0)
Delay(20)
Wend
EndProcedure
Procedure Cleanup()
If g_pd3dDevice
g_pd3dDevice\Release()
g_pD3D\Release()
g_pVB\Release()
EndIf
EndProcedure
If OpenWindow(0,0,0,300,300,"Direct3D Tutorial 02: Rendering Vertices",#WS_OVERLAPPEDWINDOW | 1)
hwnd = WindowID(0)
If initDX9(hwnd)
SetVertex(0,150.0, 50.0,0.5,1.0,$FFFF0000)
SetVertex(1,250.0,250.0,0.5,1.0,$FF00FF00)
SetVertex(2, 50.0,250.0,0.5,1.0,$FF00FFFF)
VertextBufferSize = 3 * SizeOf(CUSTOMVERTEX)
g_pd3dDevice\CreateVertexBuffer(VertextBufferSize,0,#D3DFVF_CUSTOMVERTEX,#D3DPOOL_DEFAULT,@g_pVB,0)
g_pVB\Lock(0,VertextBufferSize,@*pVertices,0)
CopyMemory(vertices(),*pVertices,VertextBufferSize)
g_pVB\Unlock()
m_font.l = 0
Debug CallFunction(1, "D3DXCreateFontA", g_pd3dDevice, 7, 0, 0, 0, #False, #ANSI_CHARSET, #OUT_DEFAULT_PRECIS, #DEFAULT_QUALITY, #FF_MODERN, @"Courier New", @g_ID3DXFont)
CreateThread(@render(),0)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Cleanup()
Else
MessageRequester("DX9","failed To create surface")
EndIf
EndIf