01-27-2025, 03:56 PM
(01-27-2025, 03:27 PM)bul71 Wrote:(01-27-2025, 02:48 PM)Marcus Wrote: You want "letterboxed" graphics in fullscreen mode? I'll write an example as soon as I get home from work
I'm not sure what you name letterboxed graphies. I want to be able to run my game in fullscreen and the aspect ratio is respected what ever is the aspect ratio of the screen, displaying margins, vertical or horizontal if needed to center the game display area.
Like seeing cinema 16/9 films on old 4/3 tv screens.
Thank you.
This version should work in both cases (vertical and horizontal bars):
Code:
' Window width and height.
'winW = 640
'winH = 480
winW = 1024
winH = 480
' Letterboxing left and right or top and bottom?
if winW/winH < screenw()/screenh()
scrW = int(winH*screenw()/screenh())
scrH = winH
else
scrW = winW
scrH = int(winW*screenh()/screenw())
endif
' Offset.
offsX = int((scrW - winW)/2)
offsY = int((scrH - winH)/2)
' Create an image to draw to.
canvas = createimage(winW, winH)
' Create window.
set window "Letterboxing", scrW, scrH, true
set redraw off
while not keydown(KEY_ESCAPE, true)
' Use offsets to calculate correct mouse coordinates.
mx = min(max(mousex() - offsX, 0), winW - 1)
my = min(max(mousey() - offsY, 0), winH - 1)
' Set destination image to canvas.
set image canvas
' Draw everything.
set color 128, 128, 128
cls
for i = 1 to 100
set color rnd(256), rnd(256), rnd(256)
draw rect rnd(winW) - 32, rnd(winH) - 32, rnd(64), rnd(64), true
next
' Set destination image back to primary (window).
set image primary
' Draw black borders.
set color 0, 0, 0
cls
' Draw canvas.
set color 255, 255, 255
draw image canvas, offsX, offsY
' Write mouse coordnates.
set caret 0, 0
write "(" + mx + ", " + my + ")"
redraw
fwait 60
wend