Chapter 3. Graphics output

There are 2 kinds of graphics: 2D and 3D. And there are 3 layers defined to represent both kinds of graphics: viewport, camera and scene. Seems familiar, I suppose.

Viewport is about representation on the screen (window or full screen). It has dimensions (X, Y, Width, Height) on screen. It consists of buffers: color, depth and stencil. Buffers may be cleared before each rendering. Color to clear color buffer can be defined. To render something viewport must be attached to camera and camera itself must be attached to scene. Otherwise viewport won't render anything. It can also be hidden or shown back.

Camera is well known object in 3D world. It has translation and rotation. It has FOV and near and far clip distances. And it's quite good idea to set clip distances very carefully and wisely. It's normal if there are many viewports attached to single camera, but each of them will be rendered separately. Even if they have same width and height. In 2D graphics camera parameters doesn't matter and shouldn't be set.

Scene can be 3D and 2D. 3D scene is quite familiar for 3D programmers. It uses to contain models, light sources, particles, skeletons, etc. So before each frame it should be updated if needed. Only active scene can be modified. To set scene active through Lua-environment scene.activate (id) must be called. 2D is more like QPainter in Qt. On the contra there's handler function for every frame repaint. It must be specified like gui.set_draw_hanlder ("draw_function") where "draw_function" is name of global function to be called every viewport repaint. Drawing function contains drawing instructions like gui.draw_fill_rect (). Note that generally this function shouldn't be used to update internal state, because it can be called more then once per frame or never called because of some accident. To update state one should use system.set_begin_frame_handler ("end_frame_handler") and system.set_end_frame_handler ("end_frame_handler").