BRL.Graphics: Globals Functions Source  


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.

Globals

FlipHookFlip Hook id

Functions

SetGraphicsDriverSet current graphics driver
GetGraphicsDriverGet current graphics driver
DefaultGraphicsFlagsGet current default graphics flags
GraphicsModesGet graphics modes available under the current graphics driver
CountGraphicsModesGet number of graphics modes available under the current graphics driver
GetGraphicsModeGet information about a graphics mode
GraphicsModeExistsDetermine if a graphics mode exists
CreateGraphicsCreate a graphics object
CloseGraphicsClose a graphics object
SetGraphicsSet current graphics object
GraphicsWidthGet width of current graphics object
GraphicsHeightGet height of current graphics object
GraphicsDepthGet depth of current graphics object
GraphicsHertzGet refresh rate of current graphics object
GraphicsFlagsGet flags of current graphics object
FlipFlip current graphics object
GraphicsBegin graphics
EndGraphicsEnd graphics

Global reference

Global FlipHook=AllocHookId()
DescriptionFlip Hook id
Information Use this id with AddHook to register a function that is called every Flip.

Function reference

Function SetGraphicsDriver( driver:TGraphicsDriver,defaultFlags=GRAPHICS_BACKBUFFER )
DescriptionSet current graphics driver
Information 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()
DescriptionGet current graphics driver
Information Returns the current graphics driver as selected by SetGraphicsDriver

Function DefaultGraphicsFlags()
DescriptionGet current default graphics flags

Function GraphicsModes:TGraphicsMode[]()
ReturnsAn array of TGraphicsMode objects
DescriptionGet graphics modes available under the current graphics driver
Information A TGraphicsMode object contains the following fields: width, height, depth and hertz
Example
Print "Available graphics modes:"

For mode:TGraphicsMode=EachIn GraphicsModes()

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

Next

Function CountGraphicsModes()
ReturnsNumber of available Graphics modes
DescriptionGet number of graphics modes available under the current graphics driver
Information Use GetGraphicsMode To obtain information about an individual Graphics mode

Function GetGraphicsMode( index,width Var,height Var,depth Var,hertz Var )
DescriptionGet information about a graphics mode
Information 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 )
ReturnsTrue if a matching graphics mode is found
DescriptionDetermine if a graphics mode exists
Information A value of 0 for any of width, height, depth or hertz will cause that parameter to be ignored.

Function CreateGraphics:TGraphics( width,height,depth,hertz,flags )
ReturnsA graphics object
DescriptionCreate a graphics object
Information 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.

Function CloseGraphics( g:TGraphics )
DescriptionClose a graphics object
Information Once closed, a graphics object can no longer be used.

Function SetGraphics( g:TGraphics )
DescriptionSet current graphics object
Information SetGraphics will also change the current graphics driver if g uses a different driver than the current driver.

Function GraphicsWidth()
ReturnsThe width, in pixels, of the current graphics object
DescriptionGet width of current graphics object
Information The current graphics object can be changed using SetGraphics.

Function GraphicsHeight()
ReturnsThe height, in pixels, of the current graphics object
DescriptionGet height of current graphics object
Information The current graphics object can be changed using SetGraphics.

Function GraphicsDepth()
ReturnsThe depth, in bits, of the current graphics object
DescriptionGet depth of current graphics object
Information The current graphics object can be changed using SetGraphics.

Function GraphicsHertz()
ReturnsThe refresh rate, in frames per second, of the current graphics object
DescriptionGet refresh rate of current graphics object
Information The current graphics object can be changed using SetGraphics.

Function GraphicsFlags()
ReturnsThe flags of the current graphics object
DescriptionGet flags of current graphics object
Information The current graphics object can be changed using SetGraphics.

Function Flip( sync=-1 )
DescriptionFlip current graphics object
Information 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, unelss 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 )
ReturnsA graphics object
DescriptionBegin graphics
Information 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.

Function EndGraphics()
DescriptionEnd graphics
Information EndGraphics closes the graphics object returned by Graphics.