Skip to content

GfxLib - FreeBASIC graphics library overview


The libary named GfxLib is the built-in graphics library included in FreeBASIC. As well as re-creating every QuickBASIC graphics command, GfxLib has built-in commands to handle input from the keyboard and mouse. Major contributors of the library are Lillo, coderJeff and DrV.

The library supports various drivers depending on the platform:

  • All:
  • Windows:
  • Linux & others:
  • DOS:

Screencontrol can be used (SET_DRIVER_NAME 103) to override the default driver preferences.

Platform Differences

  • In DOS, GfxLib will create and "manage" a mouse arrow if a mouse driver is detected. There is no "official" way to disable this. Also note that the arrow doesn't react to mouse movements while the screen is locked.
  • In DOS, Windowing and OpenGL related commands and switches are not available (they exist but do nothing, or return some values with no meaning)
  • In DOS, the refresh rate setting is not available (some VESA cards do support it, but FreeBASIC for now doesn't)
  • In DOS, the resolution must match one supported by the graphics card. GfxLib will try to find an appropriate mode from VGA modes, ModeX or VESA, preferring VESA LFB interface if available, or banked VESA otherwise. Unsupported resolutions may currently crash the program (if you fail to check SCREENPTR for ZERO before using it), though in future GfxLib may try to find a close match instead. For optimal compatibility, you should support "safe" resolutions like 640x480 and 800x600, and maybe 1024x768. There are various additional modes like 768x576 around, but they are vendor specific and lacking on many other cards. Also modes 1024x768 and above are not available on older cards and laptops.
  • It has been observed that SCREEN and SCREENRES may fail to clear the screen in DOS, actually this is probably a BIOS bug that GfxLib currently doesn't workaround.

Differences from QB

  • Graphics support was internally redesigned. QB used VGA graphics modes, and wrote directly into the VGA RAM. Multiple pages were available as long as the card supported them. FB uses backbuffers, one per defined page, and copies them to the video RAM (VGA (DOS), VESA (DOS), DirectX (Win32), ...) in the background. Graphics commands do work as they used to in QB, but a few notable differences are present:

See also

  • GFX Functions Index
  • Screen (Graphics) The QB-like way to set graphics mode
  • Screenres More flexible alternative to Screen
  • Screenlist Check display modes available for FB GfxLib to use
  • Screencontrol Select driver and more
  • Screenlock
  • Screenunlock
  • Screenptr Semi-low level access
  • Screenset
  • Screencopy
  • Screeninfo
  • Screenglproc
  • Internal pixel formats

Back to Programmer's Guide

Back to FreeBASIC Developer Information

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft