VASEr: better stroke rendering

VASEr getting started

The role of a renderer

To use VASEr properly, you need to understand what role does VASEr play in the rendering pipeline. Suppose your application has a 2D rendering pipeline like:

transformation
clipping
primitives generation
glDrawArrays(); or glBegin(); glEnd();
composition

VASEr is not a render engine, but merely takes care the primitives generation part (redlighted). Call renderer::before() and renderer::after() before and after rendering. VASEr API is namespaced VASEr.

Example: hide
How to correctly set gl states for VASEr..

Suppose you have a helloworld application that only renders a line segment in draw():

void draw()
{
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
		glLoadIdentity();
		glOrtho( 0,context_width,context_height,0,0.0f,100.0f);
		glLineWidth(2.0);
		glBegin(GL_LINES);
			glColor4f(1,0,0.5, 1);
			glVertex2f(10,100);
			glColor4f(0.5,0,1, 1);
			glVertex2f(100,300);
		glEnd();
		//other drawings
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
}
then change to:
void draw()
{
	using namespace VASEr;
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
		glLoadIdentity();
		glOrtho( 0,context_width,context_height,0,0.0f,100.0f);
		renderer::before();
			{	Vec2  P1 = {10,100};
				Vec2  P2 = {100,300};
				Color C1 = {1,0,0.5, 1};
				Color C2 = {0.5,0,1, 1};
				double W1= 2.0;
				double W2= W1;
				segment(P1,P2, C1,C2, W1,W2, 0);
			}
			//other VASEr renderings
		renderer::after();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
}

include and compile

Provide these structs to VASEr before include by:

namespace VASEr
{
	struct Vec2 { double x,y;};
	struct Color { float r,g,b,a;};
} 
or
namespace VASEr
{
	typedef your_vec2 Vec2;
	typedef your_color Color;
} 

then #include "vaser.h". There is only one file to compile, vaser.cpp. It is a unity build; no make file, no hassle. Alternatively, #include "vaser.cpp" just works, because implementation is namespaced in VASErin to prevent collision.

defining a Vec2 with float precision may work but may lead to undesirable precision lost, because internally VASEr use double for floating point operations.

comments powered by Disqus