Testing PB on Linux...

Linux specific forum
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Testing PB on Linux...

Post 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 ? :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Testing PB on Linux...

Post by Trond »

You need to add an event loop with WaitWindowEvent(). :)
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post 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...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Testing PB on Linux...

Post 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
Last edited by Trond on Fri Aug 21, 2015 9:23 pm, edited 1 time in total.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post 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 !
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Testing PB on Linux...

Post by Trond »

Why does my first code run ok on Windows
You got lucky. ;)

See the example above.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Testing PB on Linux...

Post 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.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post 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)
Little John
Addict
Addict
Posts: 4803
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Testing PB on Linux...

Post 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.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post 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.
Little John
Addict
Addict
Posts: 4803
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Testing PB on Linux...

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Testing PB on Linux...

Post by Trond »

For some reason I can't get the OpenScreen() and OpenWindowedScreen() to work on Linux.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post 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 ... ?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Testing PB on Linux...

Post by ts-soft »

libxxf86vm-dev is installed?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply