Skip to content

SCREENRES


SCREENRES — Initialize a graphics mode

Syntax

Statement form:

vb
Screenres width, height [, [depth] [, [num_pages] [, [flags] [, refresh_rate] ] ] ]

Function form:

vb
result = Screenres( width, height [, [depth] [, [num_pages] [, [flags] [, refresh_rate] ] ] ] )

Parameters

ParameterTypeDescription
widthLongHorizontal resolution (display width in pixels)
heightLongVertical resolution (display height in pixels)
depthLongColor depth in bits-per-pixel. Default = 8. Valid values: 1, 2, 4, 8, 16, 32 (15 treated as 16; 24 treated as 32)
num_pagesLongNumber of video pages. Default = 1
flagsLongScreen attribute flags. Default = 0
refresh_rateLongRefresh rate (fullscreen mode only). Default = 0

Return Value

  • On success: returns 0
  • On failure: returns a non-zero error code (a runtime error is also thrown)

Flags

Graphics mode flags

FlagDescription
GFX_NULLStarts QB-on-GUI graphics mode: creates a graphics buffer but no window
GFX_OPENGLInitializes OpenGL mode (only OpenGL commands may be used)
(none)Enters QB-only graphics mode (default)

Window mode flags

FlagDescription
GFX_WINDOWEDWindowed mode (default)
GFX_FULLSCREENFullscreen mode
GFX_NO_SWITCHDisables Alt+Enter toggle between fullscreen/windowed
GFX_NO_FRAMECreates a borderless window
GFX_SHAPED_WINDOWCreates a shaped/transparent window (RGBA(255,0,255,0) = transparent)
GFX_ALWAYS_ON_TOPWindow is always on top of other windows

Option flags

FlagDescription
GFX_ALPHA_PRIMITIVESEnables alpha channel support for all drawing primitives
GFX_HIGH_PRIORITYEnables higher priority graphics processing
GFX_NO_X86_MMXDisables MMX blitters (x86 platforms, since fbc 1.20.0)

OpenGL buffer flags (used only with GFX_OPENGL)

FlagDescription
GFX_STENCIL_BUFFERUse a stencil buffer
GFX_ACCUMULATION_BUFFERUse an accumulation buffer
GFX_MULTISAMPLERequest full-scene antialiasing

Description

Screenres initializes a graphics mode. Three modes are supported:

  1. QB-compatible graphics mode — windowed or fullscreen. Standard FreeBASIC graphics commands work as expected.
  2. QB-on-GUI mode (GFX_NULL) — the user manages the window and refreshing manually. A graphics buffer is created but no window is shown.
  3. OpenGL mode (GFX_OPENGL) — provides a portable way to initialize OpenGL. Only OpenGL commands should be used; FreeBASIC graphics primitives are not available.

The default font is 8×8 pixels. The Width function can be used to adjust the number of text rows and columns. Console commands such as Locate and Print work in graphics mode.

Example

vb
' Set a 320x200 resolution with 8-bit color depth
ScreenRes 320, 200, 8

' Draw a colored diagonal pattern
For y As Long = 0 To 200 - 1
    For x As Long = 0 To 320 - 1
        PSet (x, y), (x + y) And 255
    Next x
Next y

' Display text in the upper-left corner
Print "Hello world!!"

' Wait for a key press
Sleep

Platform Differences

  • Windowed mode and OpenGL flags are not supported under DOS.

See Also

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