This tutorial will teach you how to get primitives rendering on the screen.
Set up the Development Environment, download zenilib, and learn how to build everything if you haven't already.
zenilib/jni/application/bootstrap.cpp
.class Play_State
is currently using the default render() function, as defined in Gamestate_Base
. To override it, we can simply add the following code to Play_State:
void render() { }I recommend making
render()
private
until you have a reason to make it more publically available. The basic maxim is to restrict possible code execution paths whenever possible.Video
and Color
singletons as follows, at the beginning of render()
:
Video &vr = get_Video(); Colors &cr = get_Colors();
Vertex2f_Color
to form a triangle. We declare them in counter-clockwise order, assuming that the x-axis is pointing right and the y-axis is pointing down:
Vertex2f_Color p0(Point2f(0.0f, 0.0f), cr["red"]); Vertex2f_Color p1(Point2f(0.0f, 300.0f), cr["green"]); Vertex2f_Color p2(Point2f(400.0f, 0.0f), cr["blue"]);This triangle will have vertices that are red, green, and blue (as defined in 'zenilib/config/color.xml'). Between those vertices, colors will be interpolated.
Triangle
using these vertices. Triangle is a C++ template, so we need to tell it what type of Vertex
to expect:
Triangle<Vertex2f_Color> triangle(p0, p1, p2);
Video
device to render our Triangle
:
vr.render(triangle);
If you build and run this, you should have a colored triangle rendering on the screen. Now try to render a colored Quadrilateral
.