Testing PB on Linux...

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

Re: Testing PB on Linux...

Post by Joubarbe »

For me, yes.
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 »

ts-soft wrote:libxxf86vm-dev is installed?
It compiles, it just shows a black screen or hangs the computer.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post by Joubarbe »

Same here (no hangs however). And I don't see me living without those fantastic Screens :)
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Testing PB on Linux...

Post by BasicallyPure »

HI Joubarbe,
I don't see anything wrong with your event loop (except there is no way to exit the program).

Code: Select all

; main loop
Repeat
 
  While WindowEvent() : Wend
 
  FlipBuffers()
  ClearScreen(0)
 
  ShowHexes()
  
  Delay(1)
  
  ExamineKeyboard() ;<-- added this
Until KeyboardPushed(#PB_Key_Escape) ;<-- added this
The problem seems to be with the sprite.
I made a couple of changes to your DrawHex() procedure and now it seems to almost work.
I say "almost" because sometimes when you run the program the blue square has several pixels missing.
Other times it looks correct. I made the square larger so it is easier to see what I mean.
I know there are a lot of open bug reports about Linux and the use of 'screen'.
Such as this one: http://www.purebasic.fr/english/viewtop ... 23&t=61238
I am using Linux Mint, same as you.

Code: Select all

Procedure DrawHex(x.i, y.i, hexSize.i)
  Define loop.i
 
  ; DEBUG
  DrawingMode(#PB_2DDrawing_AllChannels) ;<-- added this
  Box(x, y, 50, 50, $FF000000 | #Blue) ;<-- added the alpha channel value
 
;   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
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post by Joubarbe »

Yeah that's weird, a big crack in the middle. I have always the same pixels missing when trying with AllChannels.

Does somebody know if Fred/freak are working on fixing those Linux bugs ? I don't want to be too critical, but when I bought PB, it said "Linux compatible"... :)

Maybe in the 5.40 !

(and thanks for the answer BasicallyPure ^^)
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 »

BasicallyPure wrote:HI Joubarbe,
I don't see anything wrong with your event loop (except there is no way to exit the program).

Code: Select all

; main loop
Repeat
 
  While WindowEvent() : Wend
 
  FlipBuffers()
  ClearScreen(0)
 
  ShowHexes()
  
  Delay(1)
  
  ExamineKeyboard() ;<-- added this
Until KeyboardPushed(#PB_Key_Escape) ;<-- added this
Generally speaking, I think it's not a good idea to "throw away" events by doing this

Code: Select all

While WindowEvent() : Wend
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post by Joubarbe »

You think wrong :)

Fred said it himself. When you have no events to check, you do that. And I understand that, the loop go through all events before continuing. I always used it for all my projects.
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:You think wrong :)

Fred said it himself. When you have no events to check, you do that. And I understand that, the loop go through all events before continuing. I always used it for all my projects.
Please provide a link to the post where Fred wrote that.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Testing PB on Linux...

Post by heartbone »

Joubarbe wrote:
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 ... ?
For me compiler v5.22 works best to produce windowed executables, and v5.31 for full screen apps.
Here's hope that v5.4x will combine the best of both for a unified experience.
Joubarbe wrote:Yeah that's weird, a big crack in the middle. I have always the same pixels missing when trying with AllChannels.

Does somebody know if Fred/freak are working on fixing those Linux bugs ? I don't want to be too critical, but when I bought PB, it said "Linux compatible"... :)

Maybe in the 5.40 !
At this point it sure looks like PB development has totally stopped dead for Linux.
Has it really been close to a year since numerous major graphics bugs were reported?
Should we continue to expect that things will be fixed?
Keep it BASIC.
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post by Joubarbe »

Yeah, because if we take the crossplatform argument out from PureBasic, well, sorry, but PB loses a lot of its value. Especially today, when you see many games on Steam for Windows/OSX/Linux (I've got 116 games compatible out of 395 ; that's a decent score and a thing we cannot ignore anymore).

I wonder what is the point of view of Fantaisie Software on this matter.

EDIT : does anyone have ever coded a small game without a screen ? I guess, by using the Canvas gadget as a screen ? It seems hard... No FPS limiter/VSync, redraw everything for the tiniest animation... I don't suppose it has the same good performance as a screen ?
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Testing PB on Linux...

Post by Joubarbe »

The following code works fine with me :

Code: Select all

EnableExplicit

; constants
Enumeration
  #WinMain
EndEnumeration

Enumeration
  #SpriteHex
EndEnumeration

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

; structures


; globals


; 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
  DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
  Box(x, y, 15, 15, RGBA(0,0,255,255))
  
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
  
  ExamineKeyboard()
  
  While WindowEvent() : Wend
  
  FlipBuffers()
  ClearScreen(0)
  
  ShowHexes()
  
  Delay(1)
  
Until KeyboardReleased(#PB_Key_Escape)
I've just changed this :

Code: Select all

; DEBUG
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
Box(x, y, 15, 15, RGBA(0,0,255,255))
I suspect that #PB_Sprite_AlphaBlending is not managed the same way in Linux than in Windows, or at least there's something not right about it. In Windows, you can draw on a #PB_Sprite_AlphaBlending sprite with the default drawing mode. In Linux, it seems you cannot.

Funny thing is that on Windows, I always needed to pass by an intermediary image to have a proper transparent image, like this :

Code: Select all

Procedure ImageToSprite(img, sprt)
  StartDrawing(SpriteOutput(sprt))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawImage(ImageID(img), 0, 0)
  StopDrawing()
  FreeImage(img)
EndProcedure

Define img.i

img = CreateImage(#PB_Any, 60, 60, 32, #PB_Image_Transparent)
CreateSprite(#SpriteHexBlue, 60, 60, #PB_Sprite_AlphaBlending)
StartDrawing(ImageOutput(img))
DrawHex(30, 30, myHex\hexSize, RGBA(0,0,255,255))
StopDrawing()
ImageToSprite(img, #SpriteHexBlue)
And I draw with :

Code: Select all

DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
Box(x, y, 15, 15, RGBA(0,0,255,255))
Otherwise there always is a problem at some point. On Linux, it works fine without the ImageToSprite procedure. Just check the following code on both platforms :

Code: Select all

EnableExplicit

; constants
Enumeration
  #WinMain
EndEnumeration

Enumeration
  #SpriteHexRed
  #SpriteHexGreen
  #SpriteHexBlue
EndEnumeration

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

; structures
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  Structure point
    x.f
    y.f
  EndStructure
CompilerEndIf

Structure s_hex
  hexSize.i
  height.f
  width.f
  distV.f
  distH.f
EndStructure

; globals
Global myHex.s_hex

; procedures
Procedure ImageToSprite(img, sprt)
  StartDrawing(SpriteOutput(sprt))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawImage(ImageID(img), 0, 0)
  StopDrawing()
  FreeImage(img)
EndProcedure

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

Procedure.d 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, color.i)
  Define loop.i
  
  DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
  For loop = 0 To 5
    If loop < 5
      LineXY(HexCornerX(x, hexSize, loop), HexCornerY(y, hexSize, loop), HexCornerX(x, hexSize, loop + 1), HexCornerY(y, hexSize, loop + 1), RGBA(1,1,1,255))
    Else
      LineXY(HexCornerX(x, hexSize, loop), HexCornerY(y, hexSize, loop), HexCornerX(x, hexSize, 0), HexCornerY(y, hexSize, 0), RGBA(1,1,1,255))
    EndIf
  Next loop
  
  FillArea(x, y, -1, color)

EndProcedure

Procedure ShowHexes()
  Define start.point
  start\x = 100
  start\y = 100
  
  With start
    DisplayTransparentSprite(#SpriteHexRed, \x, \y)
    DisplayTransparentSprite(#SpriteHexGreen, \x + myHex\distH, \y)
    DisplayTransparentSprite(#SpriteHexBlue, \x - myHex\distH, \y)
    DisplayTransparentSprite(#SpriteHexRed, \x + myHex\distH*1.5, \y + myHex\distV)
    DisplayTransparentSprite(#SpriteHexGreen, \x + myHex\distH/2, \y + myHex\distV)
    DisplayTransparentSprite(#SpriteHexBlue, \x - myHex\distH*0.5, \y + myHex\distV)
  EndWith
EndProcedure

Procedure Init()
  Define img.i
  
  ; init environment
  If InitSprite() And InitKeyboard()
    OpenWindow(#WinMain, 100, 100, 640, 480, "Hexperimentations", #PB_Window_BorderLess)
    OpenWindowedScreen(WindowID(#WinMain), 0, 0, 640, 480, 0, 0, 0)
  Else
    MessageRequester("Error", "Cannot initialize environment")
    End
  EndIf
  
  ; init hexes variables
  With myHex
    \hexSize = 30
    \height = \hexSize * 2
    \distV = \height * 3 / 4
    \width = Sqr(3) / 2 * \height
    \distH = \width
  EndWith
  
  ; draw hexes individually
;   img = CreateImage(#PB_Any, 60, 60, 32, #PB_Image_Transparent)
  CreateSprite(#SpriteHexRed, 60, 60, #PB_Sprite_AlphaBlending)  
  StartDrawing(SpriteOutput(#SpriteHexRed))
;   StartDrawing(ImageOutput(img))
  DrawHex(30, 30, myHex\hexSize, RGBA(255,0,0,255))
  StopDrawing()
;   ImageToSprite(img, #SpriteHexRed)
  img = CreateImage(#PB_Any, 60, 60, 32, #PB_Image_Transparent)
  CreateSprite(#SpriteHexGreen, 60, 60, #PB_Sprite_AlphaBlending)
  StartDrawing(ImageOutput(img))
  DrawHex(30, 30, myHex\hexSize, RGBA(0,255,0,255))
  StopDrawing()
  ImageToSprite(img, #SpriteHexGreen)
  img = CreateImage(#PB_Any, 60, 60, 32, #PB_Image_Transparent)
  CreateSprite(#SpriteHexBlue, 60, 60, #PB_Sprite_AlphaBlending)
  StartDrawing(ImageOutput(img))
  DrawHex(30, 30, myHex\hexSize, RGBA(0,0,255,255))
  StopDrawing()
  ImageToSprite(img, #SpriteHexBlue)
  
EndProcedure


; init
Init()

; main loop
Repeat
  
  ExamineKeyboard()
  
  While WindowEvent() : Wend
  
  FlipBuffers()
  ClearScreen(0)
  
  ShowHexes()
  
Until KeyboardReleased(#PB_Key_Escape)
The black border of the red hexagon will not be transparent on Windows.

Note : this is NOT the good way to draw hexagons :)
Post Reply