grabbing the device pointer

Advanced game related topics
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

grabbing the device pointer

Post by xorc1zt »

hi

can you run this code and tell me if the screen is red please. You must use DirectX9.

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()
UsePNGImageDecoder()

Macro D3DRGBA (r, g, b, a)
  (a&$ff)<<24 | (r&$ff)<<16 | (g&$ff)<<8 | (b&$ff)
EndMacro

OpenWindow(0, 0, 0, 860, 660, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 5, 5, 840, 640, 0, 0, 0,#PB_Screen_NoSynchronization)

; grab the d3d device pointer
Procedure GrabDevicePointer()
  Variable.l
  Start3D()
  Stop3D()
  ! MOV EAX, [ESP-24]
  ! MOV dword [p.v_Variable], EAX
  ProcedureReturn Variable
EndProcedure

*D3DDevice.IDirect3DDevice9 = GrabDevicePointer()

Repeat
  ExamineKeyboard()      
  Repeat  
    Event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End 
    EndSelect   
  Until Event = 0
   
*D3DDevice\Clear(0, 0, 1, D3DRGBA(255,0,0,255), 0.0, 0) 
*D3DDevice\BeginScene()
*D3DDevice\EndScene()
*D3DDevice\Present(NULL, NULL, NULL, NULL)

Until KeyboardPushed(#PB_Key_Escape)
I wrote a ugly hack function to retrieve the pointer of the d3d device created by purebasic when the software call OpenWindowScreen().

Code: Select all

Procedure GrabDevicePointer()
  Variable.l
  Start3D()
  Stop3D()
  ! MOV EAX, [ESP-24]
  ! MOV dword [p.v_Variable], EAX
  ProcedureReturn Variable
EndProcedure
moogle
Enthusiast
Enthusiast
Posts: 372
Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK

Re: grabbing the device pointer

Post by moogle »

Screen is red for me, PB 4.60 Beta 3 (x86)

Seems to make the flicker bug disappear.
Image
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: grabbing the device pointer

Post by xorc1zt »

now with the device pointer i can use D3DXFONT font into purebasic library

example

Code: Select all

Import "lib\d3dx9.lib"
  D3DXCreateFontA(*pDevice, Height.i, Width.l, Weight.l, MipLevels.l, Italic.b, CharSet.l, OutputPrecision.l, Quality.l, PitchAndFamily.l, *pFacename, *ppFont)
EndImport

Global *D3DDevice.IDirect3DDevice9
Global *testfont.ID3DXFont

; grab the d3d device pointer
Procedure GrabDevicePointer()
  Variable.l
  Start3D()
  Stop3D()
  ! MOV EAX, [ESP-24]
  ! MOV dword [p.v_Variable], EAX
  ProcedureReturn Variable
EndProcedure

Procedure initfont()
  
  If Not *D3DDevice
    *D3DDevice.IDirect3DDevice9 = GrabDevicePointer()
  EndIf
  
  name.s = "Courrier New"
  D3DXCreateFontA(*D3DDevice, 12, 0,0,1,0, #DEFAULT_CHARSET, #OUT_DEFAULT_PRECIS, #DEFAULT_QUALITY, #DEFAULT_PITCH, @name,@*testfont)
EndProcedure

Procedure DrawText3D(x, y, text.s, color.l) 
  textrect.RECT
  textrect\left= x 
  textrect\top= y
  ;textrect\right
  ;textrect\bottom
  
  ;calcul the rectangle
  *testfont\DrawTextA(NULL, text, -1, textrect, #DT_CALCRECT |#DT_LEFT,NULL)
  
  ;draw the text
  *testfont\DrawTextA(NULL, text, -1, textrect, #DT_LEFT, color)
EndProcedure
then

Code: Select all

ClearScreen(RGB(0,0,0))
Start3D()
DrawText3D(20, 20, "Hello D3DXFONT", D3DRGBA(255,0,0,255))
DrawText3D(20, 30, "Hello D3DXFONT", D3DRGBA(0,255,0,255))
DrawText3D(20, 40, "Hello D3DXFONT", D3DRGBA(0,0,255,255))
DrawText3D(20, 50, "Hello D3DXFONT", D3DRGBA(255,255,255,255))
Stop3D()
FlipBuffers()
moogle
Enthusiast
Enthusiast
Posts: 372
Joined: Tue Feb 14, 2006 9:27 pm
Location: London, UK

Re: grabbing the device pointer

Post by moogle »

Going to download directx sdk to test it.

Edit: seems to work :)
Image
Post Reply