<--- BB4W Games home

 

 

About GFXLIB

  • GFXLIB is an extensive library of bitmap graphics functions for BBC BASIC for Windows™
  • It is intended to aid the creation of 2D bitmap-based games
  • It's very easy to use!
  • Click here to go to the GFXLIB demos page.

     


    Initialising GFXLIB, loading a graphic (bitmap), and displaying it is as simple as this:

    MODE 8
    INSTALL @lib$ + "GFXLIB2"
    PROCInitGFXLIB
    ball% = FNLoadBMP( @dir$ + "graphics\ball", 0 )
    SYS GFXLIB_Plot%, dispVars{}, ball%, 64, 64, 320, 256
    PROCdisplay


     

    Download

    Current version of GFXLIB:   2.02

      Note:   Version 2.02 completely replaces earlier versions.

    Release date (version 2.02):   26th March 2011

    Download link:   Click here   (right-click then "Save As ...")

    Download size:   4.25 MB

    Quick Start Guide (PDF):   Click here

     


    Below is a simple program which uses GFXLIB to draw 40 rebounding 'balls'. If you have the full version of
    BBC BASIC for Windows installed on your computer, then you can copy & paste this program
    into the BB4W IDE and run it (so long as you have GFXLIB 2.02 or later installed).

    A link to a compiled executable of this program is given after the program listing. This can be run on
    practically any PC without the need to have BBC BASIC for Windows installed.

    REM Disable the Escape key
    *ESC OFF

    REM Set up a simple error handler
    ON ERROR PROCerror

    REM Make 2 MB of RAM available for this program
    HIMEM = LOMEM + 2 * &100000

    REM Prevent the program window being resized
    SYS "GetWindowLong", @hwnd%, -16 TO S%
    SYS "SetWindowLong", @hwnd%, -16, S% AND NOT &50000
    SYS "SetWindowPos", @hwnd%, 0, 0, 0, 0, 0, 32+7
    SYS "SetWindowPos", @hwnd%, -1, 0, 0, 0, 0, 3

    REM Set up display mode 8 (640x512 pixels)
    MODE 8
    OFF

    REM Install and initialise GFXLIB
    INSTALL @lib$ + "GFXLIB2"
    PROCInitGFXLIB

    REM Install the external GFXLIB module 'PlotShadow'
    INSTALL @lib$ + "GFXLIB_modules\PlotShadow"
    PROCInitModule

    REM Load the ball bitmap (64x64 BMP file)
    ballBmp = FNLoadBMP( @lib$ + "GFXLIB_media\ball1_64x64x8.BMP", 0 )

    REM We'll have 40 balls bouncing around...
    numBalls = 40

    REM Set up a structure to hold the position and velocity
    REM information for each ball
    DIM ball{( numBalls ) x, y, dx, dy}

    REM Define the initial positions and velocities of the balls
    FOR I = 0 TO numBalls
      ball{(I)}.x = RND(640 - 64)
      ball{(I)}.y = RND(512 - 64)
      ball{(I)}.dx = 1 + 5*RND(1)
      ball{(I)}.dy = 1 + 5*RND(1)
    NEXT I

    REM Switch off the automatic window refresh
    *REFRESH OFF

    REM Here's our main loop...
    REPEAT

      REM Clear the background (fill it with orange)
      SYS GFXLIB_Clr%, dispVars{}, FNrgb(230, 180, 20)

      REM Draw the ball shadows, then the actual balls,
      REM then update their positions
      FOR I = 1 TO numBalls

        SYS GFXLIB_PlotShadow%, dispVars{}, ballBmp, 64, 64, \
        \ ball{(I)}.x-12, ball{(I)}.y-12, 0

        SYS GFXLIB_Plot%, dispVars{}, ballBmp, 64, 64, \
        \ ball{(I)}.x, ball{(I)}.y

        ball{(I)}.x += ball{(I)}.dx
        ball{(I)}.y += ball{(I)}.dy

        IF ball{(I)}.x < 0 OR ball{(I)}.x > 640-64 THEN
          ball{(I)}.dx *= -1
        ENDIF

        IF ball{(I)}.y < 0 OR ball{(I)}.y > 512-64 THEN
          ball{(I)}.dy *= -1
        ENDIF

      NEXT I

      REM Render to the program window
      PROCdisplay

    UNTIL FALSE
    END

    DEF PROCerror
    *REFRESH ON
    ON
    PRINT '" ";
    PRINT REPORT$ + " at line "; ERL;
    REPEAT
      WAIT 10
    UNTIL FALSE
    ENDPROC

    Here is a screenshot of the above program in action:

    You can download a compiled standalone executable of the program (40balls.exe) by clicking on the link below
    (the download file size is only 68 KB!). The program should run directly from the ZIP folder, if not, then
    extract the EXE file first to a suitable folder of your choice.

    BBC BASIC for Windows is not required in order to run the compiled executable.

    Download link:  http://www.bb4wgames.com/gfxlib/40balls.zip


    This page was last modified on 15th January 2012