Page 1 of 2

Testing PB on Linux...

Posted: Fri Aug 21, 2015 8:51 pm
by Joubarbe
Hello,

This code :

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "")
  
  CanvasGadget(0, 0, 0, 200, 200)
  
  StartDrawing(CanvasOutput(0))
  Circle(100, 100, 100, RGB(0,255,0))
  StopDrawing()
  
  Delay(1000)
  
  StartDrawing(CanvasOutput(0))
  Circle(100, 100, 80, RGB(255,0,0))
  StopDrawing()
  
  Delay(1000)

EndIf
Doesn't work as expected on my computer (Linux Mint). The first circle is only displayed when the second one is drawn.

Besides, I don't seem to access the help file, at least the topics themselves. I can only access the contents page.

sh checkinstall is happy, so I suppose I missed something ? :)

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 8:58 pm
by Trond
You need to add an event loop with WaitWindowEvent(). :)

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 9:10 pm
by Joubarbe
What ? This makes no sense, as it runs perfectly with Windows.

And how would you implement it ?

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "")
  
  CanvasGadget(0, 0, 0, 200, 200)
  
EndIf

Repeat
  
  event = WaitWindowEvent()
  
  StartDrawing(CanvasOutput(0))
  Circle(100, 100, 100, RGB(0,255,0))
  StopDrawing()
  
  Delay(1000)
  
  StartDrawing(CanvasOutput(0))
  Circle(100, 100, 80, RGB(255,0,0))
  StopDrawing()
  
  Delay(1000)
  
Until event = #PB_Event_CloseWindow
Even if the code is stupid, I don't understand the behavior. It's flickering and unpredictable. And what I want is pretty simple...

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 9:20 pm
by Trond
You don't use Delay() with WaitWindowEvent(). Even on Windows it is the "wrong way" and will backfire. This is the nature of event-based programming.

Use AddWindowTimer() instead. Example:

Code: Select all


If OpenWindow(0, 0, 0, 200, 200, "")
 
  CanvasGadget(0, 0, 0, 200, 200)
 
EndIf

 
  StartDrawing(CanvasOutput(0))
  Circle(100, 100, 100, RGB(0,255,0))
  StopDrawing()

AddWindowTimer(0, 0, 1000)

Repeat
 
  event = WaitWindowEvent()
 
  Select event
    Case #PB_Event_Timer
      StartDrawing(CanvasOutput(0))
      Circle(100, 100, 80, RGB(255,0,0))
      StopDrawing()
      RemoveWindowTimer(0, 0)
  EndSelect
Until event = #PB_Event_CloseWindow

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 9:23 pm
by Joubarbe
I agree but you did not answer my question. Why does my first code run ok on Windows and not at all on Linux ?

I don't need any events loop on Window to draw on a simple canvas !

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 9:23 pm
by Trond
Why does my first code run ok on Windows
You got lucky. ;)

See the example above.

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 9:30 pm
by Joubarbe
Hmm, so that isn't supposed to work either on Windows ?

Good enough. The event loop is mandatory when you use a Screen so I guess it makes sense :)

My question on the help file remains, because it's quite annoying ^^

Thanks.

Re: Testing PB on Linux...

Posted: Fri Aug 21, 2015 10:03 pm
by Trond
Joubarbe wrote:Hmm, so that isn't supposed to work either on Windows ?
That's what I think.
My question on the help file remains, because it's quite annoying ^^

Thanks.
You can only open the help file from inside the IDE, not from the file manager. If it doesn't work, you'll have to file a bug report.

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 8:52 am
by Joubarbe
This other piece of code doesn't work as intended :

Code: Select all

EnableExplicit

; constants
Enumeration
  #WinMain
EndEnumeration

Enumeration
  #SpriteHex
EndEnumeration

#Black = 0
#White = 16777215
#Red = 255
#Green = 65280
#Blue = 16711680

; structures


; globals


; imports
; XIncludeFile "LibAALines.pb"


; procedures
Procedure.i HexCornerX(hexX.f, hexSize.i, i.i)
  Define angle.f
  
  angle = 60 * i + 30
  angle = Radian(angle)
  
  ProcedureReturn hexX + hexSize * Cos(angle)
  
EndProcedure

Procedure.i HexCornerY(hexY.f, hexSize.i, i.i)
  Define angle.f
  
  angle = 60 * i + 30
  angle = Radian(angle)
  
  ProcedureReturn hexY + hexSize * Sin(angle)
  
EndProcedure

Procedure DrawHex(x.i, y.i, hexSize.i)
  Define loop.i
  
  ; DEBUG
  Box(x, y, 5, 5, #Blue)
  
;   For loop = 0 To 5
;     If loop < 5
;       AALines::NormalL(HexCornerX(x, hexSize, loop), HexCornerY(y, hexSize, loop), HexCornerX(x, hexSize, loop + 1), HexCornerY(y, hexSize, loop + 1), #Red, 2)
;     Else
;       AALines::NormalL(HexCornerX(x, hexSize, loop), HexCornerY(y, hexSize, loop), HexCornerX(x, hexSize, 0), HexCornerY(y, hexSize, 0), #Red, 2)
;     EndIf
;   Next loop
EndProcedure

Procedure ShowHexes()
  DisplayTransparentSprite(#SpriteHex, ScreenWidth() / 2, ScreenHeight() / 2)
EndProcedure

Procedure Init()
  
  ; init environment
  If InitSprite() And InitKeyboard()
    OpenWindow(#WinMain, 100, 100, 640, 480, "Hexperimentations", #PB_Window_BorderLess)
    OpenWindowedScreen(WindowID(#WinMain), 0, 0, 640, 480)
  Else
    MessageRequester("Error", "Cannot initialize environment")
    End
  EndIf
  
  ; draw hexes individually
  CreateSprite(#SpriteHex, 60, 60, #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(#SpriteHex))
  DrawHex(30, 30, 25)
  StopDrawing()
  
EndProcedure


; init
Init()


; main loop
Repeat
  
  While WindowEvent() : Wend
  
  FlipBuffers()
  ClearScreen(0)
  
  ShowHexes()
  
  Delay(1)
  
ForEver
That should draw a little blue square (Box(x, y, 5, 5, #Blue)).
Works fine on Windows.

Note : I can't access native constants and structures such as #Red or point ; don't know if it's normal. (hence the manual declaration of color constants)

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 9:21 am
by Little John
Joubarbe wrote:This other piece of code doesn't work as intended :
I think it's actually time now that you learn how to write a proper event loop. :-)
Look at the PB Reference Manual and/or at the event loop in Trond's code above.
Joubarbe wrote:Note : I can't access native constants and structures such as #Red or point
These constants and structures are defined on Windows, but not on Linux.

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 10:10 am
by Joubarbe
And what the fuck is wrong with my loop ?

"While WindowEvent() : Wend" is all I need. I don't need to test window events.

The other statements are pretty straightforward. I flip the buffers, I clear the screen to black, then display a sprite, then put a (useless) Delay for other stuff that can happen.

Even in PB examples that's how they do it when they don't need to check for specific window events. Oh yeah, they FlipBuffers() at the end instead of at the beginning. Hurray.

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 10:32 am
by Little John
Joubarbe wrote:And what the fuck is wrong with my loop ?
I admire your elegant wording. ;-)
Little John wrote:Look at the PB Reference Manual and/or at the event loop in Trond's code above.

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 10:38 am
by Trond
For some reason I can't get the OpenScreen() and OpenWindowedScreen() to work on Linux.

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 10:44 am
by Joubarbe
Trond wrote:For some reason I can't get the OpenScreen() and OpenWindowedScreen() to work on Linux.
Hmm... That's very problematic then ! :)

I read somewhere features that were not compatible with Linux, but cannot find it now. Anyway, the help says it should work. Maybe an option somewhere or the driver ... ?

Re: Testing PB on Linux...

Posted: Sat Aug 22, 2015 10:57 am
by ts-soft
libxxf86vm-dev is installed?