ResizeScreen(..)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Env
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 27, 2010 3:20 pm
Location: Wales, United Kingdom

ResizeScreen(..)

Post by Env »

I know this has been asked before but the last post I could find was a number of years ago;

Resizing the viewport with autostretch, and having it reflect the new screen dimensions rather than stretching the contents - The fact we can't do this without workarounds is a bit of a pitfall, especially when your application has loaded a metric tonne of sprites, which loading them all again each time a resize window is called is unacceptable.

My OpenGL is highly rusty, but even when I attempt a workaround by trying to resize it directly with API calls, it's failing..

Can we expect this to be something that can and will be implemented? At risk of sounding petty .. all the others are doing it~

Thanks :)
Thanks!
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: ResizeScreen(..)

Post by Mijikai »

Ungetestet!

Faktor Native Auflösung -> neue Auflösung.
-> glScalef(FactorX,FactorY,1)
-> glTranslate(ScreenCenterX * FactorX,ScreenCenterY * FactorY,0)
Env
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 27, 2010 3:20 pm
Location: Wales, United Kingdom

Re: ResizeScreen(..)

Post by Env »

Mijikai wrote:Ungetestet!

Faktor Native Auflösung -> neue Auflösung.
-> glScalef(FactorX,FactorY,1)
-> glTranslate(ScreenCenterX * FactorX,ScreenCenterY * FactorY,0)
What would this be applied to? The screen? A snippet would be great :)

Was wäre das für? Der Bildschirm? Eine Probe wäre toll :)
Thanks!
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: ResizeScreen(..)

Post by Mijikai »

Just did a Test here is the Code :)

Code: Select all

EnableExplicit

;TestWindow ScreenResize OpenGL
;PureBasic 5.62 (x64)
;by mijikai

Procedure.i TestSprite(Width.i,Height.i,Color.i = $FF00FF)
  Protected Sprite.i
  Sprite = CreateSprite(#PB_Any,Width,Height)
  If IsSprite(Sprite)
    If StartDrawing(SpriteOutput(Sprite))
      Box(0,0,Width,Height,Color)
      StopDrawing()
      ProcedureReturn Sprite
    EndIf 
    FreeSprite(Sprite)
  EndIf 
EndProcedure

Procedure.i TestWindow(Width.i,Height.i,Title.s = #Null$)
  Protected Window.i
  Protected WindowHandle.i
  Protected WindowFlags.i
  Protected WindowMsg.i
  Protected Sprite.i
  Protected FactorX.f
  Protected FactorY.f
  Protected OffsetX.f
  Protected OffsetY.f
  WindowFlags|#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget
  WindowFlags|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
  If InitSprite()
    Window = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,WindowFlags)
    If Window
      WindowHandle = WindowID(Window)
      WindowBounds(window,Width,Height,#PB_Ignore,#PB_Ignore)
      If OpenWindowedScreen(WindowHandle,#Null,#Null,Width,Height,#True,#Null,#Null)
        FactorX = 1
        FactorY = 1
        Sprite = TestSprite(32,32)
        glLoadIdentity_()
        glOrtho_(0,Width,Height,0,0,1)
        glMatrixMode_(#GL_MODELVIEW)
        Repeat
          Repeat
            WindowMsg = WindowEvent()
            Select WindowMsg
              Case #PB_Event_SizeWindow
                FactorX = Width / WindowWidth(Window) 
                FactorY = Height / WindowHeight(Window)
                OffsetX = (WindowWidth(Window) - Width) / 2
                OffsetY = (WindowHeight(Window) - Height) / 2
              Case #PB_Event_CloseWindow
                Break 2
            EndSelect
          Until WindowMsg = #Null 
          ClearScreen(#Null)
          glLoadIdentity_()
          glScalef_(FactorX,FactorY,0)
          glTranslatef_(OffsetX,OffsetY,1)
          DisplaySprite(Sprite,150,80)
          FlipBuffers()
        ForEver
      EndIf 
      CloseWindow(Window)
    EndIf 
  EndIf
EndProcedure

TestWindow(320,200,"TestWindow")

End
Env
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 27, 2010 3:20 pm
Location: Wales, United Kingdom

Re: ResizeScreen(..)

Post by Env »

Mijikai wrote:Just did a Test here is the Code :)

Code: Select all

EnableExplicit

;TestWindow ScreenResize OpenGL
;PureBasic 5.62 (x64)
;by mijikai

Procedure.i TestSprite(Width.i,Height.i,Color.i = $FF00FF)
  Protected Sprite.i
  Sprite = CreateSprite(#PB_Any,Width,Height)
  If IsSprite(Sprite)
    If StartDrawing(SpriteOutput(Sprite))
      Box(0,0,Width,Height,Color)
      StopDrawing()
      ProcedureReturn Sprite
    EndIf 
    FreeSprite(Sprite)
  EndIf 
EndProcedure

Procedure.i TestWindow(Width.i,Height.i,Title.s = #Null$)
  Protected Window.i
  Protected WindowHandle.i
  Protected WindowFlags.i
  Protected WindowMsg.i
  Protected Sprite.i
  Protected FactorX.f
  Protected FactorY.f
  Protected OffsetX.f
  Protected OffsetY.f
  WindowFlags|#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget
  WindowFlags|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
  If InitSprite()
    Window = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,WindowFlags)
    If Window
      WindowHandle = WindowID(Window)
      WindowBounds(window,Width,Height,#PB_Ignore,#PB_Ignore)
      If OpenWindowedScreen(WindowHandle,#Null,#Null,Width,Height,#True,#Null,#Null)
        FactorX = 1
        FactorY = 1
        Sprite = TestSprite(32,32)
        glLoadIdentity_()
        glOrtho_(0,Width,Height,0,0,1)
        glMatrixMode_(#GL_MODELVIEW)
        Repeat
          Repeat
            WindowMsg = WindowEvent()
            Select WindowMsg
              Case #PB_Event_SizeWindow
                FactorX = Width / WindowWidth(Window) 
                FactorY = Height / WindowHeight(Window)
                OffsetX = (WindowWidth(Window) - Width) / 2
                OffsetY = (WindowHeight(Window) - Height) / 2
              Case #PB_Event_CloseWindow
                Break 2
            EndSelect
          Until WindowMsg = #Null 
          ClearScreen(#Null)
          glLoadIdentity_()
          glScalef_(FactorX,FactorY,0)
          glTranslatef_(OffsetX,OffsetY,1)
          DisplaySprite(Sprite,150,80)
          FlipBuffers()
        ForEver
      EndIf 
      CloseWindow(Window)
    EndIf 
  EndIf
EndProcedure

TestWindow(320,200,"TestWindow")

End

Incredible :) Thank you so much. Working perfectly on Linux x64 (Though fires a " [WARNING] GLib-GObject (CRITICAL): g_signal_handler_disconnect: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed", but we'll just ignore that haha)
Thanks!
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: ResizeScreen(..)

Post by Mijikai »

Env wrote: Can we expect this to be something that can and will be implemented? At risk of sounding petty .. all the others are doing it~

Thanks :)
+1

I would also love to have more 2D functions (like shader support, particles, layers, animation, screen in screen, timing...).
I personally think Audio (dsp, fft, synthesis...) and 2D are niche areas that could really push the popularity of PureBasic.
Its also nice to have modern web functions but thats expected nowdays and nothing that stands out.
Env
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 27, 2010 3:20 pm
Location: Wales, United Kingdom

Re: ResizeScreen(..)

Post by Env »

Just to confirm the solution above does not work with Engine3D - though there is an outstanding bug which was reported at least 4 years ago where the screen doesn't auto-stretch.

The latest bug post I found was here: viewtopic.php?f=4&t=66508 but it affects Linux (and I assume Mac) too

A huge shame because I'm using Engine3D to handle sprites using Eddy & Papala's work
Thanks!
Post Reply