Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Render on an image before sending to screen
#1
Hi.

I'm currently trying to make my drawing logic on an image of logical window dimensions then if the game runs in windowed mode, I just send this image on the window but if the game runs in fullscreen, I try to send this image on an image with the screen dimensions after applying code to calculate vertical or horizontal margins depending on the difference in aspect ratios between the physical screen and the window.

My windowed mode works fine.

In fullscreen :
-----------------
I succefully prepare graphics on the window sized image then send it to physical screen image then on the screen but I'm not able the fit the logical image on the screen size and place it accordingly with the margins.

Can you show me the way to do it properlly ?

Thank you.
Reply
#2
You want "letterboxed" graphics in fullscreen mode? I'll write an example as soon as I get home from work Smile
Reply
#3
Here's an example with borders on the left and right, which is what I assume you want:

Code:
' Window width and height.
winW = 640
winH = 480

' Aspect correct width based on height. I'm assuming that the problem is on the left and right sides now.
scrW = int(winH*screenw()/screenh())
scrH = winH

' Offset.
offsX = int((scrW - winW)/2)
offsY = 0

' 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
Reply
#4
(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 Smile

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.
Reply
#5
(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 Smile

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
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)