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.
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
````
Flags | Meaning |
GRAPHICS_BACKBUFFER | Create graphics with a back buffer |
GRAPHICS_ALPHABUFFER | Create graphics with an alpha buffer |
GRAPHICS_DEPTHBUFFER | Create graphics with a depth buffer |
GRAPHICS_STENCILBUFFER | Create graphics with a stencil buffer |
GRAPHICS_ACCUMBUFFER | Create 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
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
Print "Available graphics modes:"
For 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 )
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.
Function GraphicsResize( width:Int, height:Int )
Resize the current graphics object to width, height.
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
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
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
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
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.
Function Graphics:TGraphics( width,height,depth=0,hertz=60,flags=0 )
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
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.