| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- MODULE showcase_clear ;
- (*
- m2SDL3 showcase, ported from SDL upstream
- examples/renderer/01-clear/clear.c (public domain).
- Clears the window to a smoothly fading color every frame; the
- sine-wave trick picks the color from the elapsed time.
- SDL3 native form (no SDL2 adaptation needed here):
- - SDL_CreateWindowAndRenderer(title, w, h, flags, win^, ren^).
- - SDL_SetRenderDrawColorFloat takes 0.0..1.0 SHORTREAL values.
- - Callback structure flattened into a plain main loop with
- DrainEvents; auto-quit after 8 s so it terminates unattended.
- *)
- FROM SYSTEM IMPORT CARDINAL8;
- FROM SDL3 IMPORT SDL_Init, SDL_Quit, SDL_Delay,
- SDL_GetTicks, SDLInitVideo;
- FROM SDL3Video IMPORT WindowHandle, SDL_DestroyWindow, WindowResizable;
- FROM SDL3Render IMPORT RendererHandle,
- SDL_CreateWindowAndRenderer, SDL_DestroyRenderer,
- SDL_SetRenderDrawColorFloat, SDL_RenderClear, SDL_RenderPresent,
- SDL_SetRenderLogicalPresentation, LogicalLetterbox;
- FROM SDL3Utils IMPORT DrainEvents;
- FROM MathLib0 IMPORT sin;
- FROM libc IMPORT printf;
- CONST FrameMs = 16; MaxMs = 8000;
- VAR
- win: WindowHandle;
- ren: RendererHandle;
- quit: BOOLEAN;
- start: LONGCARD;
- t: REAL;
- r, g, b: SHORTREAL;
- BEGIN
- IF NOT SDL_Init(SDLInitVideo) THEN
- printf("showcase_clear: SDL_Init failed\n");
- HALT(1)
- END;
- IF NOT SDL_CreateWindowAndRenderer("m2SDL3 clear", 640, 480,
- VAL(LONGCARD, WindowResizable),
- win, ren) THEN
- printf("showcase_clear: CreateWindowAndRenderer failed\n");
- SDL_Quit;
- HALT(1)
- END;
- SDL_SetRenderLogicalPresentation(ren, 640, 480, LogicalLetterbox);
- printf("showcase_clear: fading, close window or wait 8s\n");
- quit := FALSE;
- start := SDL_GetTicks();
- WHILE NOT quit DO
- DrainEvents(quit);
- (* seconds since start, as REAL (double). *)
- t := LFLOAT(SDL_GetTicks()) / 1000.0;
- r := VAL(SHORTREAL, 0.5 + 0.5 * sin(t));
- g := VAL(SHORTREAL, 0.5 + 0.5 * sin(t + 2.0944));
- b := VAL(SHORTREAL, 0.5 + 0.5 * sin(t + 4.1888));
- SDL_SetRenderDrawColorFloat(ren, r, g, b, VAL(SHORTREAL, 1.0));
- SDL_RenderClear(ren);
- SDL_RenderPresent(ren);
- IF SDL_GetTicks() - start > MaxMs THEN quit := TRUE END;
- SDL_Delay(FrameMs)
- END;
- SDL_DestroyRenderer(ren);
- SDL_DestroyWindow(win);
- SDL_Quit;
- printf("showcase_clear: bye\n")
- END showcase_clear.
|