Skip to content

Add SDL3_gfx.pas #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions units/SDL3_framerate.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
This file is part of:

SDL3 for Pascal
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
SPDX-License-Identifier: Zlib
}

Const
{*!
\brief Highest possible rate supported by framerate controller in Hz (1/s).
*}
FPS_UPPER_LIMIT = 200;

{*!
\brief Lowest possible rate supported by framerate controller in Hz (1/s).
*}
FPS_LOWER_LIMIT = 1;

{*!
\brief Default rate of framerate controller in Hz (1/s).
*}
FPS_DEFAULT = 30;

Type
{*!
\brief Structure holding the state and timing information of the framerate controller.
*}
PPFPSmanager = ^PFPSmanager;
PFPSmanager = ^TFPSmanager;
TFPSmanager = record
framecount: cuint32;
rateticks: cfloat;
baseticks: cuint64;
lastticks: cuint64;
rate: cuint32;
end;

{* Functions return 0 or value for sucess and -1 for error *}

procedure SDL_initFramerate(manager: PFPSmanager); cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_initFramerate' {$ENDIF} {$ENDIF};

function SDL_setFramerate(manager: PFPSmanager; rate: cuint32): cint; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_setFramerate' {$ENDIF} {$ENDIF};

function SDL_getFramerate(manager: PFPSmanager): cint; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_getFramerate' {$ENDIF} {$ENDIF};

function SDL_getFramecount(manager: PFPSmanager): cint; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_getFramecount' {$ENDIF} {$ENDIF};

function SDL_framerateDelay(manager: PFPSmanager): cuint64; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_framerateDelay' {$ENDIF} {$ENDIF};
55 changes: 55 additions & 0 deletions units/SDL3_gfx.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
unit SDL3_gfx;

{
This file is part of:

SDL3 for Pascal
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
SPDX-License-Identifier: Zlib
}

{$I sdl.inc}

Interface
uses
{$IFDEF FPC}
ctypes,
{$ENDIF}
SDL3;

const
{$IFDEF WINDOWS}
GFX_LibName = 'SDL3_gfx.dll';
{$ENDIF}

{$IFDEF UNIX}
{$IFDEF DARWIN}
GFX_LibName = 'libSDL3_gfx.dylib';
{$IFDEF FPC}
{$LINKLIB libSDL3_gfx}
{$ENDIF}
{$ELSE}
{$IFDEF FPC}
GFX_LibName = 'libSDL3_gfx.so';
{$ELSE}
GFX_LibName = 'libSDL3_gfx.so.0';
{$ENDIF}
{$ENDIF}
{$ENDIF}

{$IFDEF MACOS}
GFX_LibName = 'SDL3_gfx';
{$IFDEF FPC}
{$linklib libSDL3_gfx}
{$ENDIF}
{$ENDIF}

{$INCLUDE SDL3_framerate.inc}
{$INCLUDE SDL3_gfxPrimitives.inc}
{$INCLUDE SDL3_gfxPrimitives_font.inc}
{$INCLUDE SDL3_imageFilter.inc}
{$INCLUDE SDL3_rotozoom.inc}

Implementation

End.
216 changes: 216 additions & 0 deletions units/SDL3_gfxPrimitives.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
This file is part of:

SDL3 for Pascal
(https://github.com/PascalGameDevelopment/SDL3-for-Pascal)
SPDX-License-Identifier: Zlib
}

Const
SDL3_GFXPRIMITIVES_MAJOR = 1;
SDL3_GFXPRIMITIVES_MINOR = 0;
SDL3_GFXPRIMITIVES_MICRO = 0;

{* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA *}

{* Pixel *}

function pixelColor(renderer: PSDL_Renderer; x, y: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_pixelColor' {$ENDIF} {$ENDIF};
function pixelRGBA(renderer: PSDL_Renderer; x, y: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_pixelRGBA' {$ENDIF} {$ENDIF};

{* Horizontal line *}

function hlineColor(renderer: PSDL_Renderer; x1, x2, y: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_hlineColor' {$ENDIF} {$ENDIF};
function hlineRGBA(renderer: PSDL_Renderer; x1, x2, y: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_hlineRGBA' {$ENDIF} {$ENDIF};

{* Vertical line *}

function vlineColor(renderer: PSDL_Renderer; x, y1, y2: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_vlineColor' {$ENDIF} {$ENDIF};
function vlineRGBA(renderer: PSDL_Renderer; x, y1, y2: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_vlineRGBA' {$ENDIF} {$ENDIF};

{* Rectangle *}

function rectangleColor(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_rectangleColor' {$ENDIF} {$ENDIF};
function rectangleRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_rectangleRGBA' {$ENDIF} {$ENDIF};

{* Rounded-Corner Rectangle *}

function roundedRectangleColor(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_roundedRectangleColor' {$ENDIF} {$ENDIF};
function roundedRectangleRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_roundedRectangleRGBA' {$ENDIF} {$ENDIF};

{* Filled rectangle (Box) *}

function boxColor(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_boxColor' {$ENDIF} {$ENDIF};
function boxRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_boxRGBA' {$ENDIF} {$ENDIF};

{* Rounded-Corner Filled rectangle (Box) *}

function roundedBoxColor(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_roundedBoxColor' {$ENDIF} {$ENDIF};
function roundedBoxRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, rad: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_roundedBoxRGBA' {$ENDIF} {$ENDIF};

{* Line *}

function lineColor(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_lineColor' {$ENDIF} {$ENDIF};
function lineRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_lineRGBA' {$ENDIF} {$ENDIF};

{* AA Line *}

function aalineColor(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aalineColor' {$ENDIF} {$ENDIF};
function aalineRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aalineRGBA' {$ENDIF} {$ENDIF};

{* Thick Line *}

function thickLineColor(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; width: cuint8; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_thickLineColor' {$ENDIF} {$ENDIF};
function thickLineRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2: cint16; width, r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_thickLineRGBA' {$ENDIF} {$ENDIF};

{* Circle *}

function circleColor(renderer: PSDL_Renderer; x, y, rad: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_circleColor' {$ENDIF} {$ENDIF};
function circleRGBA(renderer: PSDL_Renderer; x, y, rad: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_circleRGBA' {$ENDIF} {$ENDIF};

{* Arc *}

function arcColor(renderer: PSDL_Renderer; x, y, rad, start, end_: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_arcColor' {$ENDIF} {$ENDIF};
function arcRGBA(renderer: PSDL_Renderer; x, y, rad, start, end_: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_arcRGBA' {$ENDIF} {$ENDIF};

{* AA Circle *}

function aacircleColor(renderer: PSDL_Renderer; x, y, rad: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aacircleColor' {$ENDIF} {$ENDIF};
function aacircleRGBA(renderer: PSDL_Renderer; x, y, rad: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aacircleRGBA' {$ENDIF} {$ENDIF};

{* Filled Circle *}

function filledCircleColor(renderer: PSDL_Renderer; x, y, r: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledCircleColor' {$ENDIF} {$ENDIF};
function filledCircleRGBA(renderer: PSDL_Renderer; x, y, rad: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledCircleRGBA' {$ENDIF} {$ENDIF};

{* Ellipse *}

function ellipseColor(renderer: PSDL_Renderer; x, y, rx, ry: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_ellipseColor' {$ENDIF} {$ENDIF};
function ellipseRGBA(renderer: PSDL_Renderer; x, y, rx, ry: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_ellipseRGBA' {$ENDIF} {$ENDIF};

{* AA Ellipse *}

function aaellipseColor(renderer: PSDL_Renderer; x, y, rx, ry: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aaellipseColor' {$ENDIF} {$ENDIF};
function aaellipseRGBA(renderer: PSDL_Renderer; x, y, rx, ry: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aaellipseRGBA' {$ENDIF} {$ENDIF};

{* Filled Ellipse *}

function filledEllipseColor(renderer: PSDL_Renderer; x, y, rx, ry: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledEllipseColor' {$ENDIF} {$ENDIF};
function filledEllipseRGBA(renderer: PSDL_Renderer; x, y, rx, ry: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledEllipseRGBA' {$ENDIF} {$ENDIF};

{* Pie *}

function pieColor(renderer: PSDL_Renderer; x, y, rad, start, end_: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_pieColor' {$ENDIF} {$ENDIF};
function pieRGBA(renderer: PSDL_Renderer; x, y, rad, start, end_: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_pieRGBA' {$ENDIF} {$ENDIF};

{* Filled Pie *}

function filledPieColor(renderer: PSDL_Renderer; x, y, rad, start, end_: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledPieColor' {$ENDIF} {$ENDIF};
function filledPieRGBA(renderer: PSDL_Renderer; x, y, rad, start, end_: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledPieRGBA' {$ENDIF} {$ENDIF};

{* Trigon *}

function trigonColor(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_trigonColor' {$ENDIF} {$ENDIF};
function trigonRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_trigonRGBA' {$ENDIF} {$ENDIF};

{* AA-Trigon *}

function aatrigonColor(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aatrigonColor' {$ENDIF} {$ENDIF};
function aatrigonRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aatrigonRGBA' {$ENDIF} {$ENDIF};

{* Filled Trigon *}

function filledTrigonColor(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: cint16; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledTrigonColor' {$ENDIF} {$ENDIF};
function filledTrigonRGBA(renderer: PSDL_Renderer; x1, y1, x2, y2, x3, y3: cint16; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledTrigonRGBA' {$ENDIF} {$ENDIF};

{* Polygon *}

function polygonColor(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_polygonColor' {$ENDIF} {$ENDIF};
function polygonRGBA(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_polygonRGBA' {$ENDIF} {$ENDIF};

{* AA-Polygon *}

function aapolygonColor(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aapolygonColor' {$ENDIF} {$ENDIF};
function aapolygonRGBA(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_aapolygonRGBA' {$ENDIF} {$ENDIF};

{* Filled Polygon *}

function filledPolygonColor(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledPolygonColor' {$ENDIF} {$ENDIF};
function filledPolygonRGBA(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_filledPolygonRGBA' {$ENDIF} {$ENDIF};

{* Textured Polygon *}

function texturedPolygon(renderer: PSDL_Renderer; const vx, vy: pcint16; n: cint; texture: PSDL_Surface; texture_dx: cint; texture_dy: cint): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_texturedPolygon' {$ENDIF} {$ENDIF};

{* Bezier *}

function bezierColor(renderer: PSDL_Renderer; const vx, vy: pcint16; n, s: cint; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_bezierColor' {$ENDIF} {$ENDIF};
function bezierRGBA(renderer: PSDL_Renderer; const vx, vy: pcint16; n, s: cint; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_bezierRGBA' {$ENDIF} {$ENDIF};

{* Characters/Strings *}

procedure gfxPrimitivesSetFont(const fontdata: Pointer; cw, ch: cuint32); cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_gfxPrimitivesSetFont' {$ENDIF} {$ENDIF};
procedure gfxPrimitivesSetFontRotation(rotation: cuint32); cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_gfxPrimitivesSetFontRotation' {$ENDIF} {$ENDIF};
function characterColor(renderer: PSDL_Renderer; x, y: cint16; c: cuint8; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_characterColor' {$ENDIF} {$ENDIF};
function characterRGBA(renderer: PSDL_Renderer; x, y: cint16; c, r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_characterRGBA' {$ENDIF} {$ENDIF};
function stringColor(renderer: PSDL_Renderer; x, y: cint16; const s: pcuint8; color: cuint32): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_stringColor' {$ENDIF} {$ENDIF};
function stringRGBA(renderer: PSDL_Renderer; x, y: cint16; const s: pcuint8; r, g, b, a: cuint8): Boolean; cdecl;
external GFX_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_stringRGBA' {$ENDIF} {$ENDIF};
Loading
Loading