MODULE showcase_lines ; (* m2SDL3 showcase, ported from SDL upstream examples/renderer/03-lines/lines.c (public domain). Draws brown house-like line segments, a green polyline batch and a 360-line multicolor circle every frame. Porting notes - SDL_RenderLine/RenderLines take SHORTREAL coordinates; REAL math (cos/sin) converts via VAL(SHORTREAL, ...). - SDL_rand(256) becomes libc rand() MOD 256. - Callback structure flattened into a main loop; auto-quit after 8 s so the showcase also terminates unattended. *) FROM SYSTEM IMPORT ADDRESS, ADR, 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_SetRenderDrawColor, SDL_RenderClear, SDL_RenderPresent, SDL_SetRenderLogicalPresentation, LogicalLetterbox, SDL_RenderLine, SDL_RenderLines; FROM SDL3Rect IMPORT SDLFPoint, MakeFPoint; FROM SDL3Utils IMPORT DrainEvents; FROM MathLib0 IMPORT cos, sin; FROM libc IMPORT printf, rand, srand; CONST FrameMs = 16; MaxMs = 8000; CONST WinW = 640; WinH = 480; CONST Pi = 3.141592653589793; VAR win: WindowHandle; ren: RendererHandle; linePts: ARRAY [0..8] OF SDLFPoint; quit: BOOLEAN; start: LONGCARD; i: INTEGER; ang: REAL; cx, cy, ex, ey: SHORTREAL; PROCEDURE F (v: REAL) : SHORTREAL; BEGIN RETURN VAL(SHORTREAL, v) END F; PROCEDURE Col () : CARDINAL8; BEGIN RETURN VAL(CARDINAL8, rand() MOD 256) END Col; BEGIN IF NOT SDL_Init(SDLInitVideo) THEN printf("showcase_lines: SDL_Init failed\n"); HALT(1) END; IF NOT SDL_CreateWindowAndRenderer("m2SDL3 lines", WinW, WinH, VAL(LONGCARD, WindowResizable), win, ren) THEN printf("showcase_lines: CreateWindowAndRenderer failed\n"); SDL_Quit; HALT(1) END; SDL_SetRenderLogicalPresentation(ren, WinW, WinH, LogicalLetterbox); srand(VAL(INTEGER, SDL_GetTicks())); linePts[0] := MakeFPoint(F(100.0), F(354.0)); linePts[1] := MakeFPoint(F(220.0), F(230.0)); linePts[2] := MakeFPoint(F(140.0), F(230.0)); linePts[3] := MakeFPoint(F(320.0), F(100.0)); linePts[4] := MakeFPoint(F(500.0), F(230.0)); linePts[5] := MakeFPoint(F(420.0), F(230.0)); linePts[6] := MakeFPoint(F(540.0), F(354.0)); linePts[7] := MakeFPoint(F(400.0), F(354.0)); linePts[8] := MakeFPoint(F(100.0), F(354.0)); printf("showcase_lines: close window or wait 8s\n"); quit := FALSE; start := SDL_GetTicks(); WHILE NOT quit DO DrainEvents(quit); SDL_SetRenderDrawColor(ren, VAL(CARDINAL8, 100), VAL(CARDINAL8, 100), VAL(CARDINAL8, 100), VAL(CARDINAL8, 255)); SDL_RenderClear(ren); (* brown house segments, one call per line. *) SDL_SetRenderDrawColor(ren, VAL(CARDINAL8, 127), VAL(CARDINAL8, 49), VAL(CARDINAL8, 32), VAL(CARDINAL8, 255)); SDL_RenderLine(ren, F(240.0), F(450.0), F(400.0), F(450.0)); SDL_RenderLine(ren, F(240.0), F(356.0), F(400.0), F(356.0)); SDL_RenderLine(ren, F(240.0), F(356.0), F(240.0), F(450.0)); SDL_RenderLine(ren, F(400.0), F(356.0), F(400.0), F(450.0)); (* green polyline batch. *) SDL_SetRenderDrawColor(ren, VAL(CARDINAL8, 0), VAL(CARDINAL8, 255), VAL(CARDINAL8, 0), VAL(CARDINAL8, 255)); SDL_RenderLines(ren, ADR(linePts), 9); (* multicolor circle around (320, 80), radius 30. *) cx := F(320.0); cy := F(80.0); FOR i := 0 TO 359 DO ang := VAL(REAL, i) * (Pi / 180.0); ex := F(320.0 + cos(ang) * 30.0); ey := F(80.0 + sin(ang) * 30.0); SDL_SetRenderDrawColor(ren, Col(), Col(), Col(), VAL(CARDINAL8, 255)); SDL_RenderLine(ren, cx, cy, ex, ey) END; 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_lines: bye\n") END showcase_lines.