Introduction to Graphics
This section covers the basics of opening a window and drawing to the screen with RCBasic.
Opening a Window
Use OpenWindow() to create a graphics window before doing any drawing:
fullscreen = false
vsync = true
OpenWindow("My Graphics Window", 640, 480, fullscreen, vsync)
The window opens at 640 × 480 pixels. If the window could not be created
OpenWindow returns false.
The Render Loop
A window opened without a render loop will close immediately. The following skeleton keeps the window alive until the user presses Escape:
While NOT Key(K_ESCAPE)
Update() ' MUST be called every frame
Wend
Update() is the most important call in any graphical program. Every
frame it:
Renders all visible canvases to the window.
Polls keyboard, mouse, joystick, and window events.
Steps the physics simulation (2D and 3D).
Canvas System
RCBasic renders everything through virtual render targets called canvases. There are three types:
Type |
Description |
|---|---|
2D Paint Canvas |
For drawing commands: |
Sprite Layer |
Renders sprites. Has infinite 2D space; only the viewport area is shown. |
3D Canvas |
A 3D viewport with its own camera. Multiple 3D canvases re-render the scene each frame, so use sparingly. |
Drawing with a Paint Canvas
Open a canvas with OpenCanvas(), set it as active with Canvas(),
then issue drawing commands inside the render loop:
fullscreen = false
vsync = true
OpenWindow("My Graphics Window", 640, 480, fullscreen, vsync)
paint_canvas = OpenCanvas(640, 480, 0, 0, 640, 480, 1)
Canvas(paint_canvas) ' make this canvas active
While NOT Key(K_ESCAPE)
ClearCanvas() ' clear each frame
SetColor( RGB(200, 0, 0) ) ' draw color → red
RectFill(20, 20, 50, 50) ' filled rectangle
Update()
Wend
OpenCanvas(w, h, vp_x, vp_y, vp_w, vp_h, mode)— the last parameter:0= solid background,1= transparent background.ClearCanvas()resets the drawing surface each frame. Omit it only when you want the previous frame to persist (e.g. a paint application).
Key Drawing Functions
Function |
Description |
|---|---|
Draw a filled rectangle. |
|
Draw a rectangle outline. |
|
Draw a filled circle. |
|
Draw a line between two points. |
|
Blit a loaded image onto the canvas. |
|
Render text using a loaded font. |
See also
GFX Primitives — Complete primitives reference.
Images — Loading and drawing images.
Canvas — Full canvas API.