<--- 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.

    With GFXLIB, loading a bitmap (or ‘sprite’) into memory, then displaying it is as straightforward as this:

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

     

    Current version of GFXLIB:   2.06

      Note:   Version 2.06 completely replaces earlier versions

    Please read the v2.06 release notes

    Release date:   15-Feb-2013

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

    Download size:   4.51 MB

    Quick Start Guide (PDF):   Click here


    GFXLIB v2.05 is still available here

    GFXLIB Updater (v0.04 beta)

    GFXLIB Updater is no longer available because GFXLIB is no longer being developed.

     

    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 PROC_error

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

    REM Prevent the program window being resized
    PROC_fixWindowSize

    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 PROC_fixWindowSize
    LOCAL GWL_STYLE, WS_THICKFRAME, WS_MAXIMIZEBOX, ws%
    GWL_STYLE = -16
    WS_THICKFRAME = &40000
    WS_MAXIMIZEBOX = &10000
    SYS "GetWindowLong", @hwnd%, GWL_STYLE TO ws%
    SYS "SetWindowLong", @hwnd%, GWL_STYLE, ws% AND NOT (WS_THICKFRAME+WS_MAXIMIZEBOX)
    ENDPROC

    DEF PROC_error
    *REFRESH ON
    CLS : 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 September, 2013