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