Latest version:
Tramway SDK 0.0.9
Github
Quick links
Home
Get Started

Render


Probably one of the most useful systems in the framework. Performs all of the graphics stuff.

Key concepts


View

Virtual camera perspective. Can be set using a position vector and a rotation quaternion, or by directly feeding in a view and perspective matrices.

Layer

Objects can be assigned to a layer. Curently there are 7 layers. Objects in higher layers will be drawn on top of the objects in lower layers.

Graphics Primitive

A geometric shape that can be rasterized. The framework currently supports the rasterization of triangles and straight line segments.

Draw List Entry

A record in the draw list. The draw list is list of all of the objects, consisting of graphics primitives, that compose the rendered scene. To be eligble for being rendered to the screen, the object must be added to the draw list.

Vertex

A point consisting of some kind of a coordinate and possibly some other data. Used to construct graphics primitives. A triangle consists of 3 vertices, a line segment of 2. Can be arranged in a buffer in list form.

Index

Reference to a vertex. Can be arranged in a buffer in list form. Invented as a digital computer memory saving measure sometime in the late 20th century.

Texture

Raster image that can be applied to the surface of a graphics primitive during rendering.

Material

Set of surface properties, possibly including a reference to a texture. Determines how the surface of a graphics primitive will be rendered.

Light

If there was no light we could just clear the screen with a black color instead of rendering anything and you wouldn't even know.

Lightmap

Precomputed surface illumination for static objects. Allows the usage of some rather slow algorithms for lighting computations, i.e. ray tracing, path tracing, radiosity.

Armature

Consists of bones. Allows deformation of a 3D model via the transfors of the bones. Can be animated.

Backends


OpenGL

Written in a subset of OpenGL 4.0 and WebGL, this is the main rendering backend of the framework.

Direct3D

This backend uses the Direct3D9 fixed function pipeline. Not tested, but should work with Direct3D7 level hardware. Curently only supports static model, dynamic model and line rendering.

Software

This backend does all of the rendering on the CPU. Curently only supports static model, dynamic model and line rendering.

Lighting Types


Dynamic light

Can either be configured to act as a point light, or a spotlight.

No real limit on the ammount of lights in the scene, but each object can be illuminated by only 4 lights at the same time.

Directional light

Light which is originating from a light source infinitely far away. Useful for modelling sunlight.

The framework allows a single directional light to be used in the scene.

Ambient light

Adds some base lighting to every object in the scene. Has no direction.

Lightmap

Pre-computed lighting for a 3D model. Stored as a texture image. Only available to static models.

Programming in C++


#include <render/render.h>
API documentation page.

Initialization the same as with other systems.

// UI system needs to be initialized first
UI::Init();

// now we initialize Render
Render::Init();

// main loop
while (true) {
    Render::Render();
}

There's too many functions in the system to list, but here's some more useful ones.


// the system defines some color constants
color_t cyan = Render::COLOR_CYAN;
color_t pink = Render::COLOR_PINK;

// this draws a debug line. all of the debug
// drawing functions need to be called once
// per frame, since after rendering a frame
// the debug line buffer is emptied
const vec3 from = {0, 0, 0};
const vec3 to = {1, 1, 1};

Render::AddLine(from, to, cyan);

// this draws a cross
Render::AddLineMarker(from, pink);

// sphere
const float radius = 1.0f;
Render::AddSphere(from, radius, pink);

// this is how to set the directional light
Render::SetSunDirection(DIRECTION_FORWARD);
Render::SetSunColor(COLOR_CYAN * 1.0f);
Render::SetAmbientColor(COLOR_CYAN * 0.1f);

// setting the FOV, in degrees
Render::SetViewFov(90.0f);

// setting it to zero changes it to
// orthographic projection.
Render::SetViewFov(90.0f);