| Software | Version | Source | Description |
|---|---|---|---|
| MinGW C++ Compiler | 5.1.4 | http://www.mingw.org/ | The mainpage of the MinGW C++ Compiler, there look for "downloads" and get the most recent version, preferably with autoinstaller. |
| SDL_gfx-2.0.22.tar.gz | 2.0.22 | http://www.ferzkopp.net/ | SDL_gfx C++ source code from Andreas Schiffler's homepage. Look for "Software", there for "SDL_gfx". |
| SDL-devel-1.2.14-mingw32.tar.gz | 1.2.14 | http://www.libsdl.org/ | SDL development library. Look for "SDL 1.2" in the menu, then for the development libraries. |

CC = gcc AR=ar rc RANLIB=ranlib prefix=c:/dev/local bin_dir=$(prefix)/bin include_dir=$(prefix)/include lib_dir=$(prefix)/lib CFLAGS = -O3 -march=athlon-xp -mmmx -msse -m3dnow -DBUILD_DLL -DWIN32 -Ic:/dev/local/include/SDL LIBS = -Lc:/dev/local/lib -lSDL OBJS = SDL_framerate.o SDL_gfxPrimitives.o SDL_imageFilter.o SDL_rotozoom.o . . . . |
PROGRAM chap4a;
USES SDL, SDL_GFX, CRT;
CONST
x_array:ARRAY[0..5] OF SINT16 = (50, 150, 250, 250, 150, 50);
y_array:ARRAY[0..5] OF SINT16 = (100, 50, 100, 200, 250, 200);
VAR
screen,original_image,modified_image:pSDL_SURFACE;
angle_value, zoom_value:DOUBLE;
framerate:pFPSMANAGER;
calc_width, calc_height:LONGINT;
BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(400,400,32,SDL_SWSURFACE);
IF screen=NIL THEN HALT;
original_image:=SDL_LOADBMP('C:\FPC\2.2.2\bin\i386-win32\test\fpsdl.bmp');
IF original_image=NIL THEN HALT;
NEW(modified_image);
angle_value:=0.0;
zoom_value:=0.0;
NEW(framerate);
SDL_INITFRAMERATE(framerate);
SDL_SETFRAMERATE(framerate, 30);
REPEAT
angle_value:=angle_value+1.0;
zoom_value:=zoom_value+0.05;
IF angle_value>=359 THEN angle_value:=0.0;
IF zoom_value>=2.0 THEN zoom_value:=0.0;
ROTOZOOMSURFACESIZE(400, 400, angle_value, zoom_value, calc_width, calc_height);
WRITELN('Width: ',calc_width,' Height: ',calc_height);
modified_image:=ROTOZOOMSURFACE(original_image, angle_value, zoom_value, 1);
CIRCLECOLOR(screen, 200, 200, 100, $FFFF00FF);
FILLEDCIRCLECOLOR(screen, 200, 200, 50, $00FF00FF);
ELLIPSECOLOR(screen, 200, 200, 175, 75, $00FFFFFF);
FILLEDPIECOLOR(screen, 200, 200, 110, 10, 100, $FF0000FF);
POLYGONCOLOR(screen, @x_array[0], @y_array[0], 6, $000000FF);
BEZIERCOLOR(screen, @x_array[3], @y_array[3], 3, 2, $FFFFFFFF);
SDL_BLITSURFACE(modified_image,NIL,screen,NIL);
SDL_FLIP(screen);
SDL_FRAMERATEDELAY(framerate);
UNTIL keypressed;
SDL_FREESURFACE(original_image);
SDL_FREESURFACE(modified_image);
SDL_FREESURFACE(screen);
DISPOSE(framerate);
SDL_QUIT;
END.
|
PROGRAM chap4a; USES SDL, SDL_GFX, CRT; CONST x_array:ARRAY[0..5] OF SINT16 = (50, 150, 250, 250, 150, 50); y_array:ARRAY[0..5] OF SINT16 = (100, 50, 100, 200, 250, 200); VAR screen,original_image,modified_image:pSDL_SURFACE; angle_value, zoom_value:DOUBLE; framerate:pFPSMANAGER; calc_width, calc_height:LONGINT; |
BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(400,400,32,SDL_SWSURFACE);
IF screen=NIL THEN HALT;
original_image:=SDL_LOADBMP('C:\FPC\2.2.2\bin\i386-win32\test\fpsdl.bmp');
IF original_image=NIL THEN HALT;
NEW(modified_image);
angle_value:=0.0;
zoom_value:=0.0;
|

NEW(framerate); SDL_INITFRAMERATE(framerate); SDL_SETFRAMERATE(framerate, 30); |
REPEAT
angle_value:=angle_value+1.0;
zoom_value:=zoom_value+0.05;
IF angle_value>=359 THEN angle_value:=0.0;
IF zoom_value>=2.0 THEN zoom_value:=0.0;
ROTOZOOMSURFACESIZE(400, 400, angle_value, zoom_value, calc_width, calc_height);
WRITELN('Width: ',calc_width,' Height: ',calc_height);
modified_image:=ROTOZOOMSURFACE(original_image, angle_value, zoom_value, 1);
|
| rotation once by 25 degree | 25 rotations by one degree |
CIRCLECOLOR(screen, 200, 200, 100, $FFFF00FF); FILLEDCIRCLECOLOR(screen, 200, 200, 50, $00FF00FF); ELLIPSECOLOR(screen, 200, 200, 175, 75, $00FFFFFF); FILLEDPIECOLOR(screen, 200, 200, 110, 10, 100, $FF0000FF); POLYGONCOLOR(screen, @x_array[0], @y_array[0], 6, $000000FF); BEZIERCOLOR(screen, @x_array[3], @y_array[3], 3, 2, $FFFFFFFF); |
| Primitive | Definition | Description |
|---|---|---|
| Of all functions two types exist: ...Color and ...RGBA. They are in fact equal and differ only in the way you put in the colour information. For ...Color functions there is the color:Uint32 argument where you put in the colour code in hexadecimal form, e.g. $FF0000FF for red without transparency. For ...RGBA functions there are four arguments r:Uint8; g:Uint8; b:Uint8; a:Uint8 where you enter 255; 0; 0; 255 for red without transparency. | ||
| Functions with the prefix aa are equal to the functions without this prefix but are printing antialiased primitives. Functions with the prefix filled are equal to the functions without this prefix but the enclosed area of the primitive is filled with the given colour. Antialiased primitives are never filled and vice versa. | ||
| All functions return 0 as INTEGER on success. | ||
| Pixel (Dot) | function pixelColor( dst : PSDL_Surface; x : Sint16; y : Sint16; color : Uint32 ) : integer | Draws one pixel at position (x/y) in the given colour. |
| function pixelRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Line | function hlineColor( dst : PSDL_Surface; x1: Sint16; x2 : Sint16; y : Sint16; color : Uint32 ) : integer | Draws a horizontal line from x1 to x2 at height y in the given colour. |
| function hlineRGBA( dst : PSDL_Surface; x1: Sint16; x2 : Sint16; y : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function vlineColor( dst : PSDL_Surface; x : Sint16; y1 : Sint16; y2 : Sint16; color : Uint32 ) : integer | Draws a vertical line at position x from y1 to y2 in the given colour. | |
| function vlineRGBA( dst : PSDL_Surface; x : Sint16; y1 : Sint16; y2 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function lineColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; color : Uint32 ) : integer | Draws a free line from position (x1/y1) to (x2/y2) in the given colour. | |
| function lineRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function aalineColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; color : Uint32 ) : integer | ||
| function aalineRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Rectangle (Box) | function rectangleColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; color : Uint32 ) : integer | Draws a rectangle from position (x1/y1) to (x2/y2) in the given colour. |
| function rectangleRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function boxColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; color : Uint32 ) : integer | ||
| function boxRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Circle | function circleColor( dst : PSDL_Surface; x : Sint16; y : Sint16; r : Sint16; color : Uint32 ) : integer | Draws a circle with the center at position (x/y) and the radius r in the given colour. |
| function circleRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function aacircleColor( dst : PSDL_Surface; x : Sint16; y : Sint16; r : Sint16; color : Uint32 ) : integer | ||
| function aacircleRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function filledCircleColor( dst : PSDL_Surface; x : Sint16; y : Sint16; r : Sint16; color : Uint32 ) : integer | ||
| function filledCircleRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Pie | function pieColor( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; start : Sint16; finish : Sint16; color : Uint32 ) : integer | Draws a pie chart with the pie's edge being at position (x/y) with the radius rad. "start" and "finish" define the arc length of the pie in degree. If "start" is 0 then the pie starts at the right (east) side of a circle. To start at the top, "start" should be 270 or -90. If "start" is 0 and "finish" is 90, you get one quarter of a circle. |
| function pieRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; start : Sint16; finish : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function filledPieColor( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; start : Sint16; finish : Sint16; color : Uint32 ) : integer | ||
| function filledPieRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rad : Sint16; start : Sint16; finish : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Ellipse | function ellipseColor( dst : PSDL_Surface; x : Sint16; y : Sint16; rx : Sint16; ry : Sint16; color : Uint32 ) : integer | Draws an ellipse with its center at position (x/y) and the two radii rx and ry for its horizontal and vertical axes in the given colour. |
| function ellipseRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rx : Sint16; ry : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function aaellipseColor( dst : PSDL_Surface; xc : Sint16; yc : Sint16; rx : Sint16; ry : Sint16; color : Uint32 ) : integer | ||
| function aaellipseRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rx : Sint16; ry : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function filledEllipseColor( dst : PSDL_Surface; x : Sint16; y : Sint16; rx : Sint16; ry : Sint16; color : Uint32 ) : integer | ||
| function filledEllipseRGBA( dst : PSDL_Surface; x : Sint16; y : Sint16; rx : Sint16; ry : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Polygon | function trigonColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; x3 : Sint16; y3 : Sint16; color : Uint32 ) : integer | Draws a trigon with its edges at (x1/y1), (x2/y2) and (x3/y3) in the given colour. |
| function trigonRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; x3 : Sint16; y3 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function aatrigonColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; x3 : Sint16; y3 : Sint16; color : Uint32 ) : integer | ||
| function aatrigonRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; x3 : Sint16; y3 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function filledTrigonColor( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; x3 : Sint16; y3 : Sint16; color : Uint32 ) : integer | ||
| function filledTrigonRGBA( dst : PSDL_Surface; x1 : Sint16; y1 : Sint16; x2 : Sint16; y2 : Sint16; x3 : Sint16; y3 : Sint16; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function polygonColor( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; color : Uint32 ) : integer | Draws a polygon with x values from array of SINT16 in vx. y values are from array of SINT16 in vy. n is the number of edges/points the polygon has. | |
| function polygonRGBA( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function aapolygonColor( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; color : Uint32 ) : integer | ||
| function aapolygonRGBA( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| function filledPolygonColor( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; color : Uint32 ) : integer | ||
| function filledPolygonRGBA( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
| Bézier curve | function bezierColor( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; s : integer; color : Uint32 ) : integer | Draws a Bézier curve of any order. n is the number of points, well n+1 is the order of the curve then. The x and y values are from arrays of SINT16. The higher value s the smoother the curve gets. s should be 2 at least. |
| function bezierRGBA( dst : PSDL_Surface; const vx : PSint16; const vy : PSint16; n : integer; s : integer; r : Uint8; g : Uint8; b : Uint8; a : Uint8 ) : integer | ||
SDL_BLITSURFACE(modified_image,NIL,screen,NIL); SDL_FLIP(screen); SDL_FRAMERATEDELAY(framerate); UNTIL keypressed; |
SDL_FREESURFACE(original_image); SDL_FREESURFACE(modified_image); SDL_FREESURFACE(screen); DISPOSE(framerate); SDL_QUIT; END. |
![]() |
The final result should look and behave like this: The image fpsdl.bmp is rotated and zoomed continouisly and some primitives (circle, filled circle, ellipse, pie, hexagon, Bézier curve) are drawn onto the image. If you use the pre-compiled exe file make sure to have the image copied to c:\. |