BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›BRL

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Format

    • Introduction
    • TFormatter

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

PUB

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType
Edit

BRL.Graphics

The graphics module provides the ability to create and 'flip' graphics objects.

A graphics object represents a rectangular area you can render to. However, the graphics module does not provide any commands for actual rendering - this is left to other modules such as max2D to implement.

The graphics module maintains 2 'current' objects - the current graphics driver and the currect graphics object. To change the current graphics driver, use SetGraphicsDriver. To change the current graphics object, use SetGraphics.

To create a graphics object, use either Graphics or CreateGraphics. The kind of graphics object created will depend upon the current graphics driver. For example, the following code:

SetGraphicsDriver GLGraphicsDriver()
Local g:TGraphics=CreateGraphics( 640,480,32,60,GRAPHICS_BACKBUFFER )

Will create an OpenGL graphics object.

You can 'select' this object for rendering using:

SetGraphics g           'we can now execute OpenGL code
glClearColor .5,0,1,1       'tada!
glClear             'yes!
Flip                'must do this as the graphics is double buffered

One you have finished with a graphics object, use CloseGraphics to close it.

Graphics and CreateGraphics both accept the following parameters: width, height, depth, hertz and flags.

The width and height parameters specify the dimensions of the graphics, in pixels.

The depth parameter selects a pixel bit depth. This value can be 0, 16, 24 or 32 depending on the graphics modes available. A depth of 0 can be used to select 'windowed mode' graphics, while non-0 depths select 'fullscreen' graphics.

The hertz parameter selects a refresh rate, which refers to the number of times the screen refreshes per second. The refresh rates available depend on the graphics modes available, which differ from graphics card to graphics card. Note that creating graphics with an unsupported refresh rate will not fail - instead, a default refresh rate will be used.

The Graphics command can be used to achieve a fixed refresh rate. When using Flip to present such graphics, BlitzMax will guarantee the desired refresh rate is honored regardless of the available hardware's capabilities. This is achieved by using software timing techniques when necessary.

The flags parameter can be any combination of the following:

FlagsMeaning
GRAPHICS_BACKBUFFERCreate graphics with a back buffer
GRAPHICS_ALPHABUFFERCreate graphics with an alpha buffer
GRAPHICS_DEPTHBUFFERCreate graphics with a depth buffer
GRAPHICS_STENCILBUFFERCreate graphics with a stencil buffer
GRAPHICS_ACCUMBUFFERCreate graphics with an accumulation buffer

Flags can be combined with the | (or) operator. For example, GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER can be used to create graphics which has both a back buffer and a depth buffer.

Graphics created with the GRAPHICS_BACKBUFFER flag must be 'flipped' after you have finished rendering using Flip.

Functions

Function SetGraphicsDriver( driver:TGraphicsDriver,defaultFlags=GRAPHICS_BACKBUFFER )

Set current graphics driver

The current graphics driver determines what kind of graphics are created when you use the CreateGraphics or Graphics functions, as well as the graphics modes available.

The GLGraphicsDriver, GLMax2DDriver, D3D7Max2DDriver and D3D9Max2DDriver functions can all be used to obtain a graphics driver.

The defaultFlags parameter allows you to specify graphics flags that will be applied to any graphics created with CreateGraphics or Graphics.

Example

SuperStrict

SetGraphicsDriver GLMax2DDriver()

Graphics 640,480
DrawText "OpenGL Max2D Graphics! Hit any key (next to the whatever key)...",0,0
Flip
WaitKey
EndGraphics

SetGraphicsDriver GLGraphicsDriver()

Graphics 640,480
glClear GL_COLOR_BUFFER_BIT
GLDrawText "'Raw' OpenGL Graphics! Hit any key...",0,0
Flip
WaitKey


Function GetGraphicsDriver:TGraphicsDriver()

Get current graphics driver

Returns the current graphics driver as selected by SetGraphicsDriver


Function DefaultGraphicsFlags()

Get current default graphics flags


Function GraphicsModes:TGraphicsMode[]()

Get graphics modes available under the current graphics driver

A TGraphicsMode object contains the following fields: width, height, depth and hertz

Returns

An array of TGraphicsMode objects

Example

SuperStrict

Print "Available graphics modes:"

For Local Mode:TGraphicsMode=EachIn GraphicsModes()

    Print Mode.width+","+Mode.height+","+Mode.depth+","+Mode.hertz

Next


Function CountGraphicsModes()

Get number of graphics modes available under the current graphics driver

Use GetGraphicsMode To obtain information about an individual Graphics mode

Returns

Number of available Graphics modes


Function GetGraphicsMode( index,width Var,height Var,depth Var,hertz Var )

Get information about a graphics mode

GetGraphicsMode returns information about a specific graphics mode. mode should be in the range 0 (inclusive) to the value returned by CountGraphicsModes (exclusive).


Function GraphicsModeExists( width,height,depth=0,hertz=0 )

Determine if a graphics mode exists

A value of 0 for any of width, height, depth or hertz will cause that parameter to be ignored.

Returns

True if a matching graphics mode is found


Function CreateGraphics:TGraphics( width,height,depth,hertz,flags,x,y )

Create a graphics object

CreateGraphics creates a graphics object. To use this object for rendering, you will first have to select it using SetGraphics.

The kind of graphics object returned depends upon the current graphics driver as set by SetGraphicsDriver.

Returns

A graphics object


Function CloseGraphics( g:TGraphics )

Close a graphics object

Once closed, a graphics object can no longer be used.


Function SetGraphics( g:TGraphics )

Set current graphics object

SetGraphics will also change the current graphics driver if g uses a different driver than the current driver.

Example

SuperStrict

Import MaxGUI.Drivers

Local G:TGraphics = Graphics(640,480) 'creates the normal graphic screen first
Local MyWindow:TGadget=CreateWindow("Canvas Example", 200,200,320,240)
Local MyCanvas:TGadget=CreateCanvas(10,10,290,140,MyWindow)

Repeat
    WaitEvent()
    Select EventID()
        Case EVENT_WINDOWCLOSE
            End
        Case EVENT_GADGETPAINT
            SetGraphics CanvasGraphics (MyCanvas)
            SetColor Int(Rnd(255)),Int(Rnd(255)),Int(Rnd(255))
            DrawRect 20 , 20 , 50 , 80
            Flip
            SetGraphics G
            SetColor Int(Rnd(255)),Int(Rnd(255)),Int(Rnd(255))
            DrawOval 100,100,100,100
            Flip
        Case EVENT_MOUSEMOVE
            RedrawGadget(MyCanvas)
    End Select

Until AppTerminate()


Function GraphicsResize( width:Int, height:Int )

Resize the current graphics object to width, height.


Function GraphicsPosition( x:Int, y:Int )

Sets the position of the graphics window to x, y.


Function GraphicsWidth()

Get width of current graphics object

The current graphics object can be changed using SetGraphics.

Returns

The width, in pixels, of the current graphics object

Example

SuperStrict

Graphics 640,480,0,60

DrawText "Graphics Width: "+GraphicsWidth(), 10 , 10
DrawText "Graphics Height: "+GraphicsHeight(), 10 , 30
DrawText "Graphics Depth: "+GraphicsDepth(), 10 , 50
DrawText "Graphics Hertz: "+GraphicsHertz(), 10 , 70
Flip
WaitKey()


Function GraphicsHeight()

Get height of current graphics object

The current graphics object can be changed using SetGraphics.

Returns

The height, in pixels, of the current graphics object

Example

SuperStrict

Graphics 640,480,0,60

DrawText "Graphics Width: "+GraphicsWidth(), 10 , 10
DrawText "Graphics Height: "+GraphicsHeight(), 10 , 30
DrawText "Graphics Depth: "+GraphicsDepth(), 10 , 50
DrawText "Graphics Hertz: "+GraphicsHertz(), 10 , 70
Flip
WaitKey()


Function GraphicsDepth()

Get depth of current graphics object

The current graphics object can be changed using SetGraphics.

Returns

The depth, in bits, of the current graphics object

Example

SuperStrict

Graphics 640,480,0,60

DrawText "Graphics Width: "+GraphicsWidth(), 10 , 10
DrawText "Graphics Height: "+GraphicsHeight(), 10 , 30
DrawText "Graphics Depth: "+GraphicsDepth(), 10 , 50
DrawText "Graphics Hertz: "+GraphicsHertz(), 10 , 70
Flip
WaitKey()


Function GraphicsHertz()

Get refresh rate of current graphics object

The current graphics object can be changed using SetGraphics.

Returns

The refresh rate, in frames per second, of the current graphics object

Example

SuperStrict

Graphics 640,480,0,60

DrawText "Graphics Width: "+GraphicsWidth(), 10 , 10
DrawText "Graphics Height: "+GraphicsHeight(), 10 , 30
DrawText "Graphics Depth: "+GraphicsDepth(), 10 , 50
DrawText "Graphics Hertz: "+GraphicsHertz(), 10 , 70
Flip
WaitKey()


Function GraphicsFlags()

Get flags of current graphics object

The current graphics object can be changed using SetGraphics.

Returns

The flags of the current graphics object


Function Flip( sync=-1 )

Flip current graphics object

Flip swap the front and back buffers of the current graphics objects.

If sync is 0, then the flip occurs as soon as possible. If sync is 1, then the flip occurs on the next vertical blank.

If sync is -1 and the current graphics object was created with the Graphics command, then flips will occur at the graphics object's refresh rate, unless the graphics object was created with a refresh rate of 0 in which case flip occurs immediately.

If sync is -1 and the current graphics object was NOT created with the Graphics command, then the flip will occur on the next vertical blank.

Example

SuperStrict

Graphics 640,480

Local x:Int = 100
Local sync:Int = 0

While Not (KeyHit(KEY_ESCAPE) Or AppTerminate())
    Cls 
    DrawText "Sync=" + Sync , x , 100
    x :+ 1 
    If x > 300 Then
        x = 100
        sync :+ 1
        If sync >1 Then
            sync=-1
        End If
  End If
  Flip sync
Wend


Function Graphics:TGraphics( width,height,depth=0,hertz=60,flags=0,x=-1,y=-1 )

Begin graphics

Graphics is a convenience function that simplifies the process of creating a graphics object.

Once Graphics has executed, you can begin rendering immediately without any need for SetGraphics.

Graphics also enables polled input mode, providing a simple way to monitor the keyboard and mouse.

Returns

A graphics object

Example 1

SuperStrict

Graphics 640,480

DrawRect 50,50,200,100
Flip
Repeat
Until KeyDown(KEY_ESCAPE) Or AppTerminate()

Example 2

SuperStrict

Import MaxGUI.Drivers

Local G:TGraphics = Graphics(640,480) 'creates the normal graphic screen first
Local MyWindow:TGadget=CreateWindow("Canvas Example", 200,200,320,240)
Local MyCanvas:TGadget=CreateCanvas(10,10,290,140,MyWindow)

Repeat
    WaitEvent()
    Select EventID()
        Case EVENT_WINDOWCLOSE
            End
        Case EVENT_GADGETPAINT
            SetGraphics CanvasGraphics (MyCanvas)
            SetColor Int(Rnd(255)),Int(Rnd(255)),Int(Rnd(255))
            DrawRect 20 , 20 , 50 , 80
            Flip
            SetGraphics G
            SetColor Int(Rnd(255)),Int(Rnd(255)),Int(Rnd(255))
            DrawOval 100,100,100,100
            Flip
        Case EVENT_MOUSEMOVE
            RedrawGadget(MyCanvas)
    End Select

Until AppTerminate()


Function EndGraphics()

End graphics

EndGraphics closes the graphics object returned by Graphics.


Globals

Global FlipHook=AllocHookId()

Flip Hook id

Use this id with AddHook to register a function that is called every Flip.


← BRL.GNetBRL.Hook →
  • Functions
    • Function SetGraphicsDriver( driver:TGraphicsDriver,defaultFlags=GRAPHICS_BACKBUFFER )
    • Function GetGraphicsDriver:TGraphicsDriver()
    • Function DefaultGraphicsFlags()
    • Function GraphicsModes:TGraphicsMode[]()
    • Function CountGraphicsModes()
    • Function GetGraphicsMode( index,width Var,height Var,depth Var,hertz Var )
    • Function GraphicsModeExists( width,height,depth=0,hertz=0 )
    • Function CreateGraphics:TGraphics( width,height,depth,hertz,flags,x,y )
    • Function CloseGraphics( g:TGraphics )
    • Function SetGraphics( g:TGraphics )
    • Function GraphicsResize( width:Int, height:Int )
    • Function GraphicsPosition( x:Int, y:Int )
    • Function GraphicsWidth()
    • Function GraphicsHeight()
    • Function GraphicsDepth()
    • Function GraphicsHertz()
    • Function GraphicsFlags()
    • Function Flip( sync=-1 )
    • Function Graphics:TGraphics( width,height,depth=0,hertz=60,flags=0,x=-1,y=-1 )
    • Function EndGraphics()
  • Globals
    • Global FlipHook=AllocHookId()
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson