raafal - a cross-platform 3d application framework project

Developed or developing a new product in PureBasic? Tell the world about it.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: raafal - a cross-platform 3d application framework proje

Post by wilbert »

Have you considered something like OpenGL instead of a canvas or use native drawing routines on each platform instead of the PureBasic ones ?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

wilbert wrote:Have you considered something like OpenGL instead of a canvas or use native drawing routines on each platform instead of the PureBasic ones ?
Yes indeed, that's why I've asked to Fred for an OpenGLCanvasGadget. I don't know if nor when it will be available.

I prefer not to use native drawing routines on each platform, or I better go back to C/C++. To me the point of using PureBasic is to use as few as possible native API while making cross-platform applications.

But I also want to try the Screen (WindowedSreen actually) way with OpenGL subsystem. It requires a different approach to handle events, and constantly polling like in a game application so I'm not sure in terms of resources it will be more efficient. But I'm gonna try anyway.
guy rabiller | radfac founder / ceo | raafal.org
marc_256
Enthusiast
Enthusiast
Posts: 742
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by marc_256 »

For some time now, I am working on my cad, cam, cnc software.
I used all the parts in canvas gadget,
but the canvas gadget is having some limits,
I am reprogramming all to sprites now...
but there I am having some problems with the drawtext() and with the colors in OpenGL.

marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

marc_256 wrote:For some time now, I am working on my cad, cam, cnc software.
I used all the parts in canvas gadget,
but the canvas gadget is having some limits,
I am reprogramming all to sprites now...
but there I am having some problems with the drawtext() and with the colors in OpenGL.
marc,
That's interesting marc. Could you elaborate on the limits you found with the CanvasGadget ?

Also, what kind of issues do you have with DrawText() and OpenGL colors ?
guy rabiller | radfac founder / ceo | raafal.org
marc_256
Enthusiast
Enthusiast
Posts: 742
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by marc_256 »

Hi grabiller,

For me, the canvas gadget is one of the best gadgets there exist in PB.
It works very well, but for speed ??

If I make 'mesh drawings' with 1000st of edges and vertices, it works well, but the mouse control is very slow.
So my 3D cursor, is slow in motion.

For the color problems, there is a big difference between DirectX and OpenGL color management.

Also with DrawText() is a difference in DirectX and OpenGL mode.

see also this post, http://www.purebasic.fr/english/viewtop ... 36&t=56020
also mesh handeling is different in DirextX and OpenGL.

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: raafal - a cross-platform 3d application framework proje

Post by wilbert »

marc_256 wrote:Also with DrawText() is a difference in DirectX and OpenGL mode.
If you would only need one or two fonts in a few different sizes, you could use sprite sheets instead to draw the text.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

I wanted to try with the OpenWindowedScreen() approach but I've immediately encountered a showstopper.

I didn't find a way to 'resize' the hardware accelerated surface. Using the 'AutoStretch' isn't an option because when the main Window is resized, the HA surface is indeed 'stretched' which means the coordinates are all messed up in regard to the actual dimension of the HA surface in pixels. (yet it does not work at all with DirectX11 - on Win64 - and with OpenGL it is stretched only when you stop resizing the window, so no 'realtime' resizing).

@Marc
I wonder how you handle this in your CAD application !?
guy rabiller | radfac founder / ceo | raafal.org
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: raafal - a cross-platform 3d application framework proje

Post by wilbert »

grabiller wrote:I didn't find a way to 'resize' the hardware accelerated surface.
How about something like this ?

Code: Select all

Declare CreateSprites()
Declare ResizeWindowedScreen(Window)

; Init some things

If InitSprite() And InitMouse() And InitKeyboard()
Else
  MessageRequester("Error", "An error has occured while initializing the application!")
  End
EndIf

; Create sprites procedure

Procedure CreateSprites()
  CreateSprite(0, 50, 50)
EndProcedure

; Resize windowed screen procedure

Procedure ResizeWindowedScreen(Window)
  Static ScreenExists = #False
  If ScreenExists : CloseScreen() : EndIf
  If OpenWindowedScreen(WindowID(Window), 0, 0, WindowWidth(Window), WindowHeight(Window))
    ScreenExists = #True
    CreateSprites()
  Else
    MessageRequester("Error", "An error has occured while resizing the window!")
    End
  EndIf
EndProcedure


; Main loop

If OpenWindow(0, 0, 0, 320, 200, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  ResizeWindowedScreen(0)
  
  Repeat
    Repeat
      Event = WaitWindowEvent(10)
      Select Event
        Case #PB_Event_CloseWindow
          End
        Case #PB_Event_SizeWindow
          ResizeWindowedScreen(0)
      EndSelect
    Until Event = 0
    
    FlipBuffers()
    ClearScreen(RGB(0, 0, 200))
    
    DisplaySprite(0, 10, 10)
    DisplaySprite(0, ScreenWidth() - 60, 10)
    
  ForEver
  
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

Hey Wilbert,

Yes, this is the solution everyone gives, indeed, I also got it from the french forum and while searching through the messages.

But, in my case, this is unusable. Testing our exemple (with OpenGL subsystem) I get an horrible flicking yet (with OpenGL) the Screen is only updated when I stop resizing the Window. Yet, having to Close/ReOpen the WindowedScreen and re-initialize all the Sprites on resize is a non-sense to me.

Actually, I just found a much simpler workaround: I call OpenWindowedScreen() with the size of the Desktop, then I handle drawing with WindowWidth/Height instead of ScreenWidth/Height. No stretching anymore, no need to close/recreate everything and I have no flicking anymore.

Here is an exemple: windowed_screen_resize_20130831.rar (Win64)

The fact that even with a small window the screen is the size of the desktop is not a big issue in my case because the kind of application I'm creating is usually used maximized. But at least when restoring/resizing I get clean refresh.
guy rabiller | radfac founder / ceo | raafal.org
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

Here is the source code based on the PB exemple, it will be more useful than the executable:

Code: Select all

  If InitSprite() = 0
    MessageRequester("Error", "Can't open screen & sprite environment!", 0)
    End
  EndIf
  
  Procedure __OnSizeWindow()
    ClearScreen(RGB(0, 0, 200)) ; A blue background
    DisplaySprite(0, 10, 10)  ; Display our black box at the left-top corner
    DisplaySprite(0, WindowWidth(0) - 60, 10) ; Display our black box at the right-top corner
    FlipBuffers()
  EndProcedure
  
  ExamineDesktops()
  If OpenWindow(0, 0, 0, 320, 200, "A screen in a window...", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    SetWindowColor(0,RGB(0,0,200)) 
    BindEvent( #PB_Event_SizeWindow, @__OnSizeWindow(), #PB_All, #PB_All, #PB_All )
    If OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0),DesktopHeight(0))
  
      CreateSprite(0, 50, 50) ; Create an empty sprite, will be whole black
        
      Repeat
        ; It's very important to process all the events remaining in the queue at each frame
        ;
        Repeat
          Event = WaitWindowEvent(10)
          
          If Event = #PB_Event_CloseWindow
            End
          EndIf
        Until Event = 0
        
        ClearScreen(RGB(0, 0, 200)) ; A blue background
        DisplaySprite(0, 10, 10)  ; Display our black box at the left-top corner
        DisplaySprite(0, WindowWidth(0) - 60, 10) ; Display our black box at the right-top corner
        FlipBuffers()
        
      ForEver
      
    Else
      MessageRequester("Error", "Can't open windowed screen!", 0)
    EndIf
  EndIf
guy rabiller | radfac founder / ceo | raafal.org
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: raafal - a cross-platform 3d application framework proje

Post by wilbert »

It doesn't seem to work on OS X.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

wilbert wrote:It doesn't seem to work on OS X.
What happens on OSX ? It does not compile ? It crashes ?
Perhaps it is related to BindEvent ? (try to use the normal event in the event loop then).
guy rabiller | radfac founder / ceo | raafal.org
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: raafal - a cross-platform 3d application framework proje

Post by wilbert »

grabiller wrote:What happens on OSX ? It does not compile ? It crashes ?
Perhaps it is related to BindEvent ? (try to use the normal event in the event loop then).
The sprites aren't drawn while DisplaySprite() does get called.
So nothing but a blue window.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: raafal - a cross-platform 3d application framework proje

Post by Danilo »

grabiller wrote:
wilbert wrote:It doesn't seem to work on OS X.
What happens on OSX ? It does not compile ? It crashes ?
Perhaps it is related to BindEvent ? (try to use the normal event in the event loop then).
Compiles. Sometimes displays the sprites here, sometimes not (just blue window).
When displaying the sprites, the second one is definitely not displayed at "WindowWidth(0) - 60",
although "Debug WindowWidth(0)" gives the correct result.
User avatar
grabiller
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Jun 01, 2011 9:38 am
Location: France - 89220 Rogny-Les-Septs-Ecluses
Contact:

Re: raafal - a cross-platform 3d application framework proje

Post by grabiller »

That's odd. Works perfectly well here.

@Wilbert
@Danilo
Do the sprites show (at the right place) when the application start, before you do any resizing ?

@Danilo
Did you tried to use the opengl subsystem in the compiler options ?
Did you tried the executable from the link I gave ? Same result ?

Btw, I'm using v5.20 b13 here on Windows x64.
guy rabiller | radfac founder / ceo | raafal.org
Post Reply