Documentation - PureBasic and DirectX

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Documentation - PureBasic and DirectX

Post by blueznl »

I would like a better description of what works and what doesn't when using the different subsystems. It would also be great if there would be an example included that shows smooth sprite movement when in windowed screen mode...

I'm now trying to figure it out trial and error, and that's not the right way to do things, especially when things work differently in DirectX7 and DirectX9...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: Documentation - PureBasic and DirectX

Post by Thorium »

Hm. I have no problem with smooth sprite movement on windowed mode. I don't do anything special. Coded it initialy for fullscreen but works on windowed mode without problems.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Documentation - PureBasic and DirectX

Post by Fluid Byte »

Not really worth it since DX9 is the standard now anyway and you should use it whenever possible. DX7 turns of Vista Aero which is really annoying for most people. Furthermore it's not 64-Bit compatible which is a major issue. Most bugs with DX9 are already known and will hopefully fixed by the team in the near future. Apart from that you can only continue reporting bugs and problems to help improve the subsystem.

Besides, you only seem to have one specific problem here. Maybe post some example code and we can have a closer look since I don't really understand the problem.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Documentation - PureBasic and DirectX

Post by djes »

Fluid byte> Just try examples/sources/windowedscreen.pb example with directx9 subsystem in pb4.40b5 ;)

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Windowed Screen example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

  CompilerIf Subsystem("DirectX9") = #False
    MessageRequester("MessageRequester","Please use DirectX9 subsystem",#PB_MessageRequester_Ok)
    End
  CompilerEndIf

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 340, 285, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10,  10, 100, 25, "Grab input")
  ButtonGadget(2, 120,  10, 100, 25, "Button 2")
  ButtonGadget(3, 230,  10, 100, 25, "Button 3")
  TextGadget  (4, 10, 40, 300, 30, "Press 'F1' to ungrab keyboard and mouse")

  If OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0,2 )
    LoadSprite(0, "Data/PureBasicLogo.bmp")
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf

EndIf

SetFrameRate(60)
direction = 1
playerX = 1
playerY = 1

Repeat
  Repeat
    ; Always process all the events to flush the queue at every frame
    Event = WindowEvent()
    
    Select Event
      Case #PB_Event_CloseWindow
        Quit = 1
    
      Case #PB_Event_Gadget
        
        ; Do the normal application management here
        Gadget = EventGadget()
    
        Select Gadget
          Case 1
            InputReleased = 0
            ReleaseMouse(#False)
            SetGadgetText(4, "Press 'F1' to ungrab keyboard and mouse")

          Case 2, 3
            SetGadgetText(4, "Button "+Str(Gadget)+" pressed.")
        EndSelect
    
    EndSelect
    
  Until Event = 0 ; Quit the event loop only when no more events are available
  
  If InputReleased = 0

    ExamineMouse()

    ; do the sprite & screen management at every frame
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_Up)    And playerY > 0   : playerY -3 : EndIf  
    If KeyboardPushed(#PB_Key_Down)  And playerY < 280 : playerY +3 : EndIf  
    If KeyboardPushed(#PB_Key_Left)  And playerX > 0   : playerX -3 : EndIf  
    If KeyboardPushed(#PB_Key_Right) And playerX < 300 : playerX +3 : EndIf  

    If KeyboardPushed(#PB_Key_F1)
      ReleaseMouse(#True)
      InputReleased = 1
    EndIf
  EndIf
  
  ; Clear the screen and draw our sprites
  ClearScreen(RGB(0,0,0))
  ClipSprite(0, 0, 0, x, x/8)
  DisplaySprite(0, x, 100)
  DisplaySprite(0, x, x)
  DisplaySprite(0, 300-x, x)
  DisplaySprite(0, playerX, playerY)

  x + direction
  If x > 300 : direction = -1 : EndIf   ; moving back to the left with negative value
  If x < 0   : direction =  1 : EndIf   ; moving to the right with positive value
    
  FlipBuffers()       ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back

Until  Quit Or KeyboardPushed(#PB_Key_Escape)
Last edited by djes on Wed Oct 14, 2009 9:40 pm, edited 1 time in total.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Documentation - PureBasic and DirectX

Post by blueznl »

Well, that code runs at max speed without any synchronization on my machine, no matter what parameter I provide as flipmode...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Documentation - PureBasic and DirectX

Post by Fred »

The DX9 windowed synchronization has been fixed.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Documentation - PureBasic and DirectX

Post by blueznl »

Ah! So it wasn't me after all :-) I hope :-(

Just FYI: I tried it with 4.40b5. If there's a new library I'm going to try it with that one.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Documentation - PureBasic and DirectX

Post by nco2k »

the example from djes runs awfully fast, since SetFrameRate() for dx9 is still broken. maybe thats blueznl's problem?

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Documentation - PureBasic and DirectX

Post by Trond »

Yes, the frame rate isn't kept. It runs like it is trying to escape from David Hasselhoff!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Documentation - PureBasic and DirectX

Post by blueznl »

THen I'll just have to wait for PB v4.40b6 :-(
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Documentation - PureBasic and DirectX

Post by djes »

What do you think I'm waiting for :twisted:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Documentation - PureBasic and DirectX

Post by blueznl »

Winning lottery tickets?
Nekkid' double D pole dancers?
A new paintjob for both your Ferrari's?

;-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Documentation - PureBasic and DirectX

Post by djes »

Tsss tsss! A date with Fred of course, or if he's not available, with Leonard Nimoy. :mrgreen:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Documentation - PureBasic and DirectX

Post by blueznl »

You aim too low :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Documentation - PureBasic and DirectX

Post by djes »

Well, as Carla married Nicolas Sarkozy, and as I can't afford this splendid vehicle Image, my dreams are now limited. :(
Post Reply