The following example draws lines at random positions using the SDL_GFX library.
DLL dependencies: SDL.DLL, SDL_GFX.DLL.
' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "SDL_GFX.INC"
%SCR_WIDTH = 320
%SCR_HEIGHT = 240
%SCR_BPP = 16
SUB RenderStuff (BYVAL pscreen AS SDL_Surface PTR)
LOCAL x1, y1, x2, y2 AS INTEGER
LOCAL r, g, b AS BYTE
LOCAL i AS INTEGER
FOR i = 1 to 1000
x1 = RND * (%SCR_WIDTH - 1)
y1 = RND * (%SCR_HEIGHT - 1)
x2 = RND * (%SCR_WIDTH - 1)
y2 = RND * (%SCR_HEIGHT - 1)
r = RND * 256
g = RND * 256
b = RND * 256
lineRGBA pscreen, x1, y1, x2, y2, r, g, b, 255
NEXT
END SUB
FUNCTION PBMAIN () AS LONG
LOCAL pscreen AS SDL_Surface PTR
' // Initialize SDL's subsystems - in this case, only video.
IF SDL_Init(%SDL_INIT_VIDEO) < 0 THEN
MSGBOX "Unable to init SDL: " & SDL_GetError()
EXIT FUNCTION
END IF
' // Attempt to create a 640x480 window with 32bit pixels.
pscreen = SDL_SetVideoMode(%SCR_WIDTH, %SCR_HEIGHT, %SCR_BPP, 0)
' // If we fail, return error.
IF pscreen = %NULL THEN
SDL_Quit
MSGBOX "Unable to set the video mode: " & SDL_GetError()
EXIT FUNCTION
END IF
' // Set the window title
SDL_WM_SetCaption("SDL_GFX Line", "")
LOCAL done AS LONG
LOCAL uevent AS SDL_Event
WHILE done = %FALSE
' // Render stuff
RenderStuff(pscreen)
SDL_Flip(pscreen)
' // Poll for events, and handle the ones we care about.
WHILE SDL_PollEvent(VARPTR(uevent))
SELECT CASE uevent.type
CASE %SDL_KEYDOWN
CASE %SDL_KEYUP
' // Quit if escape is pressed
IF uevent.key.keysym.sym = %SDLK_ESCAPE THEN
done = %TRUE
EXIT LOOP
END IF
CASE %SDL_QUIT
done = %TRUE
EXIT LOOP
END SELECT
WEND
WEND
' Shut down SDL
SDL_Quit
END FUNCTION