Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Render on an image before sending to screen
#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


Messages In This Thread
RE: Render on an image before sending to screen - by Marcus - 01-27-2025, 03:24 PM

Forum Jump:


Users browsing this thread: 5 Guest(s)