Graphics Commands

Top  Previous  Next

The 2D command set features many built in high speed graphic drawing functions specifically designed to take the most advantage of DirectX. These primitive drawing commands can be used along side the built in Emergence BASIC ones. When using an 8 bit screen with any of the drawing commands substitute a palette number for the RGB color in the examples.

Line drawing

Drawing a solid line is done with the DRAWLINE command. The line is always one pixel wide and can be any color. The line can be drawn on the back buffer (default), the front buffer or the sprite buffer set with the the SpriteToBuffer command. Examples:
 

DRAWLINE 0, 0, 100, 200, RGB(255,0,255)
DRAWLINE 0, 10, 100, 350, RGB(0, 0, 200), FrontBuffer

A line can be drawn alpha blended into the background using DRAWALPHALINE. The line is always one pixel wide and can be any color. The line can be drawn on either the back buffer (default) or the front buffer. Examples:
 

DRAWALPHALINE 0, 0, 100, 200, RGB(255,0,255), 128
DRAWALPHALINE 0, 10, 100, 350, RGB(0, 0, 200), 200, FrontBuffer

An anti-aliased line can be drawn with the DRAWAALINE command. Anti-aliasing  uses a software algorithm to remove the jagged edges normally seen on lines drawn at an angle.
 

DRAWAALINE 0, 0, 100, 200, RGB(255,0,255)
DRAWAALINE 0, 10, 100, 350, RGB(0, 0, 200), FrontBuffer

 

Rectangles

A rectangle outline is drawn with the DRAWRECT command. The interior of the rectangle is transparent and will show anything underneath.
 

DRAWRECT 0, 0, 180, 200, RGB(255,255,255)

Filled rectangles are drawn with the DRAWFILLEDRECT command.
 

DRAWFILLEDRECT 10,10, 100, 100, RGB(100,100,100)

 

Writing pixels

Writing a pixel in any color can be done with the WRITEPIXEL command.
 

WRITEPIXEL 0,100, RGB(77,255,255)

An alpha blended pixel can be written to a buffer with the WRITEALPHAPIXEL command
 

WRITEALPHAPIXEL 0, 230, RGB(20,200,20), 110

For high speed effects and advanced uses the WRITEPIXELFAST command uses hand optimized machine language to write the pixel to the buffer in the fastest time possible. WRITEPIXELFAST requires locking of the buffer ahead of time before use.
 

LOCKBUFFER
    FOR y=0 to 599
        FOR x=0 to 799
            WritePixelFast(x,y,c)
        NEXT x
    NEXT y
UNLOCKBUFFER

You must be very careful not to write outside of the screen dimensions. There are no boundary checks done with WRITEPIXELFAST. Writing outside of the buffer will result in an access violation.

 

Drawing text

Text can be drawn to a buffer using the WRITETEXT command. WRITETEXT is significantly faster than using PRINT.
 

WRITETEXT 0, 0, "Press any key to close"

The font, color and drawing mode of the text is set using the commands from Emergence BASIC which will be covered next.

 

Using Emergence BASIC's drawing commands.

All of the drawing commands and functions from the Emergence BASIC core command set can be used with your 2D screens. The built in variables FrontBuffer, BackBuffer and SpriteBuffer substitute for WINDOW variables in any of the drawing commands. For example:
 

'Change the text color, mode and font of the back buffer
FRONTPEN BackBuffer,RGB(255,255,255)
DRAWMODE BackBuffer,@TRANSPARENT
SETFONT BackBuffer,"Courier New",20,400
'Draw a circle to the back buffer
CIRCLE BackBuffer,110,125,50,RGB(255,0,0),RGB(0,0,255)
'Print some text
MOVE BackBuffer, 0, 0
PRINT BackBuffer, "Press any key to close ","FPS = ",speed

When using EBASIC's drawing commands with 8 bit screens the PALETTEINDEX function must be used to map a screens palette to the RGB color needed for the command. Example:
 

SETPALETTECOLOR 3,RGB(0,0,255)
SETPALETTECOLOR 4,RGB(255,0,255)
CIRCLE BackBuffer,110,125,50,PALETTEINDEX(3),PALETTEINDEX(4)