' Draw to image buffer and scaler sample ' ' Last updated: <2024/02/12 05:09:06 +0900> 'Const SCRW = 320 : Const SCRH = 180 Const SCRW = 320 : Const SCRH = 240 'Const SCRW = 640 : Const SCRH = 480 #ifdef __FB_WIN32__ ' Windows : use mmsystem #include "windows.bi" #include "win/mmsystem.bi" #endif #include "fbgfx.bi" Using fb #include "imagescale2screen.bi" #ifdef __FB_WIN32__ ' Timer accuracy 1ms timeBeginPeriod(1) #endif ' set screen depth Dim As Integer sdepth = 32 Select Case Command(1) Case "8" : sdepth = 8 Case "16" : sdepth = 16 Case "32" : sdepth = 32 End Select ' get desktop size Dim As Integer dispw, disph ScreenInfo dispw, disph ' get scale (Integer) Dim As Double dscale = dispw / SCRW If dscale > (disph / SCRH) Then dscale = disph / SCRH ' get dest image size Dim As Integer tgtscrw, tgtscrh tgtscrw = Int(SCRW * dscale) tgtscrh = Int(SCRH * dscale) If tgtscrw > dispw Then tgtscrw = dispw If tgtscrh > disph Then tgtscrh = disph ' set screen size. like fullscreen ScreenRes dispw, disph, sdepth, 2, GFX_NO_FRAME Dim As Any Ptr gbuf = ImageCreate(SCRW, SCRH) Dim As Double angle = 0.0 Dim As Boolean running = True Const PI = 3.1415926535897932 #define MAX_FPS 60.0 Dim As Double start_time, prev_time, now_time, delta, next_time Dim As Integer frame_count, fps_count ' save start time start_time = Timer prev_time = start_time frame_count = 0 fps_count = 0 Dim As Integer workpage = 1 ScreenSet workpage, (workpage + 1) And &H01 ' Main Loop While running ' get delta time now_time = Timer delta = now_time - prev_time If delta < 0 Then delta = (1.0 / MAX_FPS) prev_time = now_time next_time = now_time + (1.0 / MAX_FPS) ' fps count If now_time >= start_time Then If (now_time - start_time) >= 1.0 Then ' get FPS fps_count = frame_count start_time += 1.0 frame_count = 0 End If Else start_time = now_time End If frame_count += 1 If Inkey <> "" Then running = False angle += (1.0 * MAX_FPS) * delta ' draw to image buffer ' clear screen line gbuf, (0, 0) - (SCRW - 1, SCRH - 1), RGB(30, 60, 120), BF ' cls Circle gbuf, (SCRW \ 2, SCRH \ 2), (SCRH \ 2 - 1), RGB(0, 255, 0) Dim As Integer x, y, r r = SCRH / 4 x = (SCRW / 2 - r - 1) * Cos(angle * PI / 180.0) + (SCRW / 2) y = (SCRH / 2 - r - 1) * Sin(angle * PI / 180.0) + (SCRH / 2) Circle gbuf, (x, y), r, RGB(0, 255, 255) Draw String gbuf, (0, 0), Str(SCRW) & "x" & SCRH & " (" & tgtscrw & "x" & tgtscrh & ") FPS:" & fps_count, RGB(255, 255, 255) ' draw to screen ScreenLock Color RGB(255, 255, 255), RGB(0, 0, 0) cls Dim As Integer ox, oy ox = (dispw - tgtscrw) / 2 oy = (disph - tgtscrh) / 2 ImageScale2screen(gbuf, ox, oy, tgtscrw, tgtscrh) ScreenUnlock workpage = (workpage + 1) And &H01 ScreenSet workpage, (workpage + 1) And &H01 If Timer < next_time Then ' sleep Dim As long wait_ms = (next_time - Timer) * 1000 If wait_ms > 0 Then sleep wait_ms End If Wend #ifdef __FB_WIN32__ ' reset timer accuracy timeEndPeriod(1) #endif