From: Michel Pollet <buserror@gmail.com>
Date: Wed, 6 Jun 2012 06:59:35 +0000 (+0100)
Subject: libc3: remerged
X-Git-Tag: v1.0~93
X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=1b4c2367d6ee9a886949eaa64feec929cf8e387d;p=sx%2Fsimavr.git

libc3: remerged

Submodules are a bit sensitive, so I'm remerging this and will use
'git subtree' instead to split libc3 development

Signed-off-by: Michel Pollet <buserror@gmail.com>
---

diff --git a/examples/shared/libc3/Makefile b/examples/shared/libc3/Makefile
index 7f4320f..2c64f15 100644
--- a/examples/shared/libc3/Makefile
+++ b/examples/shared/libc3/Makefile
@@ -5,13 +5,18 @@ REVISION	= 1
 SHELL	 	:= ${shell which bash}
 
 IPATH 		+= src
+IPATH 		+= srcgl
 VPATH		+= src
+VPATH		+= srcgl
 
 OBJ 		= obj-${shell $(CC) -dumpmachine}
 
 C3SRC		= ${wildcard src/*.c}
 C3OBJ 		= ${patsubst src/%,${OBJ}/%,${C3SRC:.c=.lo}}
 
+C3GLSRC		= ${wildcard srcgl/*.c}
+C3GLOBJ 	= ${patsubst srcgl/%,${OBJ}/%,${C3GLSRC:.c=.lo}}
+
 CC 			= clang
 PKGCONFIG	= pkg-config
 INSTALL		= install
@@ -34,7 +39,7 @@ DESTDIR		= /usr/local
 
 -include ${wildcard .make.options*}
 
-all:	${OBJ} src/c3config.h ${OBJ}/libc3.la
+all:	${OBJ} src/c3config.h ${OBJ}/libc3.la ${OBJ}/libc3gl.la
 
 ${OBJ}:
 	mkdir -p ${OBJ}
@@ -63,6 +68,14 @@ ${OBJ}/libc3.la: ${C3OBJ}
 			-version-info 0:1:0 \
 			-rpath $(DESTDIR)/lib $(LDFLAGS)
 
+${OBJ}/libc3gl.la: ${C3GLOBJ}
+	@echo LINK $@
+	$(E)$(LIBTOOL) --mode=link --tag=CC \
+		$(CC) $(CPPFLAGS) $(CFLAGS) \
+			$^ -o $@ \
+			-version-info 0:1:0 \
+			-rpath $(DESTDIR)/lib $(LDFLAGS)
+
 ${OBJ}/%.lo: src/c3config.h
 ${OBJ}/%.lo: %.c
 	@echo CC $<
diff --git a/examples/shared/libc3/README.md b/examples/shared/libc3/README.md
index 31207ab..018ecb2 100644
--- a/examples/shared/libc3/README.md
+++ b/examples/shared/libc3/README.md
@@ -1,4 +1,4 @@
-libc3 - No frill 'scene' graph library in C
+**libc3** - No frill 'scene' graph library in C
 =====
 (C) 2012 Michel Pollet <buserror@gmail.com>
 
@@ -12,17 +12,48 @@ It's vaguely inspired by THREE.js funnily enough, because it allows you to
 hack around and quickly get stuff on screen with the minimal amount of 
 effort.
 
+Introduction
+-----------
+The general idea is that the library keeps track of geometry and stuff, but doesn't
+do *any* opengl or related calls. Instead, it uses callbacks into code that will
+take care of the rendering related tasks.
+
+So for example a c3pixels represents a texture, but a callback into the rendering
+layer will be responsible to push the pixels to OpenGL, and store the object back
+into the c3pixels for reference.
+
+Status
+-------
+The API is generally functional, but it's brand new. I try not to add bits that
+I aren't needed, and I also don't add stuff that isn't tested.
+
+There is an ASCII STL file loader that works, and a few other bit of geometry related
+helpers. 
+
+It's currently used in one 'serious' project and also in my [3D printer simulator](https://github.com/buserror-uk/simavr/tree/master/examples/board_reprap),
+as part of simavr. There you cal also find the "opengl renderer" set of callbacks, in the
+near future, this layer will be part of a *libc3-gl* companion library. 
+
+General Roadmap
+---------------
+There is a [PDF Flowchart](https://github.com/buserror-uk/libc3/raw/master/doc/libc3-flowchart.pdf) 
+of how things are mostly organized as far as data structure goes, but the following is a
+breakdown of the major components.
+
 The API has various bits:
 * c3algebra: C derivative of an old C++ piece of code I had lying around and that has
 been present in my toolset for a long time. It gives you *vectors* (c3vec2, c3vec3, c3vec4)
 and *matrices* (c3mat3, c3mat4) with various tools to manipulate them.
 * c3quaternion: Quaternion implementation using c3algebra
-* c3camera/c3arcball: camera manipulation, not perfect
+* c3camera/c3arcball: camera manipulation bits
 
 The basic data structure is as follow:
 * *c3context*:
-	Mostly placeholder for now, hosts a "root" object, can reproject the
-	objects & geometry, and call the callbacks to draw them.
+	Hosts a "root" object, and a list of 'viewpoints' (ie either cameras, or lights).
+	it can reproject the objects & geometries, and call the callbacks to draw them.
+	
+	The context also keeps a list of *c3pixels* and *c3program* that are referenced
+	by the geometries.
 * *c3object*: 
 	* Has a list of (sub) c3objects
 	* Has a list of c3transforms (ie matrices)
@@ -33,11 +64,12 @@ The basic data structure is as follow:
 * *c3geometry*:
 	* Has a 'type' (raw for simple vertices, texture, triangles etc)
 	* Has a 'subtype' (mostly can be used to draw GL types)
-	* Has a 'material' (ie color, texture... to be completed)
+	* Has a 'material' (ie color, texture, a GPU program... to be completed)
 	* Has a list of vertices
+	* Has a cached copy of a vertices when it has been 'projected'
 	* Has a list of texture coordinates (optional)
 	* Has a list of vertices colors (optional)
-	* Has a cached copy of a vertices when it has been 'projected'
+	* Had a list of vertices indexes (optional)
 * *c3transform*:
 	Is just a sugar coated matrix, with an optional name.
 
@@ -52,8 +84,6 @@ Also there are:
 * *c3cairo*:
 	Placeholder for now, inherits from *c3texture* and will contain a
 	cairo surface mapped to a GL texture.
-* *c3pango*:
-	A text label, inherits from *c3cairo*
 
 Draw Drivers "Inheritance"
 ------------
diff --git a/examples/shared/libc3/doc/libc3-flowchart.dot b/examples/shared/libc3/doc/libc3-flowchart.dot
new file mode 100644
index 0000000..4312255
--- /dev/null
+++ b/examples/shared/libc3/doc/libc3-flowchart.dot
@@ -0,0 +1,220 @@
+digraph g {
+//	label = "libc3\n - lightweight scene graph library - Data Structure Hierarchy";
+	label = <
+	<font point-size="18">libc3</font> - 
+	<font color="blue">http://github.com/buserror-uk/libc3</font>
+	 - Lightweight C Scene Graph Library - Data Structure Flowchart
+	>;
+	node [fontsize=24,shape=box];
+	// concentrate=true;
+
+	c3context [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3context</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Keeps track of a root c3object,<br/>
+		possible multiple views, and also stores <br/>
+		texture pixels and shader programs
+		</font></td></tr>
+		</table>
+	>];
+	c3context_view [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3context_view</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Keep tracks of a scene point of view.<br/>
+		used for the eye(s), and the light(s)
+		</font></td></tr>
+		</table>
+	>];
+	c3camera [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3camera</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Keeps an 'eye' point, a 'lookat'<br/>
+		point the related vectors, and a<br/>
+		transform matrix
+		</font></td></tr>
+		</table>
+	>];
+	c3object [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3object</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Anchor point that holds optional<br/>
+		transform matrices, other sub-c3objects<br/>
+		and c3geometries<br/>
+		</font></td></tr>
+		</table>
+	>];
+	c3transform [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3transform</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Holds a matrix to be applies to<br/>
+		a c3object and it's descendants
+		</font></td></tr>
+		</table>
+	>];
+	c3cairo [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4" color="gray">
+		<tr><td>c3cairo</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Maps a Cairo image surface<br/>
+		to a c3texture - Optional.
+		</font></td></tr>
+		</table>
+	>];
+	c3texture [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3texture</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Provides a geometry to render a<br/>
+		c3pixel (and anonymous texture)
+		</font></td></tr>
+		</table>
+	>];
+	c3geometry [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3geometry</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Contains the real drawing data, vertices,<br/>
+		tex coordinates, normals and a material.
+		</font></td></tr>
+		</table>
+	>];
+	c3pixels [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3pixels</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Basic description of a pixmap<br/>
+		to be loaded as a texture.
+		</font></td></tr>
+		</table>
+	>];
+	c3program [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3program</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Holds a vertex/fragment/... program,<br/>
+		also parses them for uniform/parameters
+		</font></td></tr>
+		</table>
+	>];
+	c3color [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3color</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Base RGBA float color
+		</font></td></tr>
+		</table>
+	>];
+	c3vertex [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3vertex</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Array of X,Y,Z coordinates,<br/>
+		with associated buffer object
+		</font></td></tr>
+		</table>
+	>];
+	c3normal [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3normal</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Array of normals with<br/>
+		associated buffer object
+		</font></td></tr>
+		</table>
+	>];
+	c3tex [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3tex</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Array of texture coordinates<br/>
+		with associated buffer object
+		</font></td></tr>
+		</table>
+	>];
+	c3indice [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3indice</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Array of indices into<br/>
+		the other arrays
+		</font></td></tr>
+		</table>
+	>];
+	c3mat [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3mat</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Geometry material related data<br/>
+		ie color, texture, program.
+		</font></td></tr>
+		</table>
+	>];
+	c3stl [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3stl</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Loads ASCII STL model files<br/>
+		and generates corresponding c3object.
+		</font></td></tr>
+		</table>
+	>];
+	c3lines [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3lines</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Converts segments into a textured<br/>
+		triangle mesh for wide, <br/>
+		antialiasied lines
+		</font></td></tr>
+		</table>
+	>];
+	c3sphere [shape=none, label=<
+		<table border="1" cellborder="0" cellpadding="4">
+		<tr><td>c3sphere</td></tr>
+		<tr><td color="gray" border="1" align="center"><font point-size="10">
+		Creares geometry for a sphere<br/>
+		with texture coordinaes&amp;normals
+		</font></td></tr>
+		</table>
+	>];
+	c3context -> c3context_view;
+	c3context -> c3object [style=bold];
+	c3context -> c3pixels [style=dashed];
+	c3context -> c3program [style=dashed];
+	
+	c3context_view -> c3camera;
+	
+	{ rank = same;  c3object; c3stl; }
+	{ rank = same;  c3geometry; c3lines; c3sphere; }
+	c3stl -> c3object [ weight=0.1, color="gray" ];
+	c3lines -> c3geometry [ weight=0.1, color="gray" ];
+	c3sphere -> c3geometry [ weight=0.1, color="gray" ];
+	
+	c3texture -> c3geometry;
+	{ node [style=dashed]; c3cairo; }
+	c3cairo -> c3texture;
+
+	c3object -> c3geometry [style=bold];
+	c3object -> c3texture;
+	c3object -> c3cairo;
+	c3object -> c3transform;
+	
+	c3object -> c3object;
+	
+	c3geometry -> c3vertex;
+	c3geometry -> c3normal	;
+	c3geometry -> c3tex;
+	c3geometry -> c3mat;
+	c3geometry -> c3indice;
+	
+	c3mat -> c3pixels;
+	c3mat -> c3program;
+	c3mat -> c3color;
+	
+	c3texture -> c3pixels;
+};
diff --git a/examples/shared/libc3/src/c3.c b/examples/shared/libc3/src/c3.c
index 38fcf83..4901765 100644
--- a/examples/shared/libc3/src/c3.c
+++ b/examples/shared/libc3/src/c3.c
@@ -3,22 +3,28 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
 #include "c3.h"
+#include "c3config.h"
 
+const char *
+c3version()
+{
+	return CONFIG_C3_VERSION;
+}
diff --git a/examples/shared/libc3/src/c3.h b/examples/shared/libc3/src/c3.h
index 190ba23..d6ca68f 100644
--- a/examples/shared/libc3/src/c3.h
+++ b/examples/shared/libc3/src/c3.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
@@ -29,4 +29,7 @@
 #include "c3transform.h"
 #include "c3texture.h"
 
+const char *
+c3version();
+
 #endif /* __C3_H___ */
diff --git a/examples/shared/libc3/src/c3algebra.c b/examples/shared/libc3/src/c3algebra.c
index b47525d..31406a5 100644
--- a/examples/shared/libc3/src/c3algebra.c
+++ b/examples/shared/libc3/src/c3algebra.c
@@ -6,20 +6,20 @@
 	Derivative and inspiration from original C++:
 	Paul Rademacher & Jean-Francois DOUEG,
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <math.h>
@@ -351,6 +351,14 @@ c3vec3 c3vec3_prod(const c3vec3 a, const c3vec3 b)
     return c3vec3f(a.n[VX]*b.n[VX], a.n[VY]*b.n[VY], a.n[VZ]*b.n[VZ]);
 }
 
+c3vec3 c3vec3_polar(const c3vec3 a)
+{
+	c3f l = c3vec3_length(a);
+	c3f phi = atan2(a.y, a.x);
+	c3f theta = acos(a.z / l);
+	return c3vec3f(phi, theta, l);
+}
+
 /****************************************************************
  *                                                              *
  *          c3vec4 Member functions                               *
diff --git a/examples/shared/libc3/src/c3algebra.h b/examples/shared/libc3/src/c3algebra.h
index d2b71a1..b959a06 100644
--- a/examples/shared/libc3/src/c3algebra.h
+++ b/examples/shared/libc3/src/c3algebra.h
@@ -6,20 +6,20 @@
 	Derivative and inspiration from original C++:
 	Paul Rademacher & Jean-Francois DOUEG,
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
@@ -87,7 +87,7 @@ c3vec2	c3vec2_max(const c3vec2 a, const c3vec2 b);
 c3vec2	c3vec2_prod(const c3vec2 a, const c3vec2 b);
 
 /*
- * c3vec4 related
+ * c3vec3 related
  */
 
 c3vec3	c3vec3_zero();
@@ -115,6 +115,7 @@ c3vec3	c3vec3_prod(const c3vec3 a, const c3vec3 b);
 
 c3vec3	c3vec3_cross(const c3vec3 a, const c3vec3 b);
 c3vec3	c3vec2_cross(const c3vec2 a, const c3vec2 b);
+c3vec3 	c3vec3_polar(const c3vec3 a); // returns phi, theta, length
 
 /*
  * c3vec4 related
diff --git a/examples/shared/libc3/src/c3arcball.c b/examples/shared/libc3/src/c3arcball.c
index f801651..35fe442 100644
--- a/examples/shared/libc3/src/c3arcball.c
+++ b/examples/shared/libc3/src/c3arcball.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <math.h>
diff --git a/examples/shared/libc3/src/c3arcball.h b/examples/shared/libc3/src/c3arcball.h
index d61c815..d7309f1 100644
--- a/examples/shared/libc3/src/c3arcball.h
+++ b/examples/shared/libc3/src/c3arcball.h
@@ -6,20 +6,20 @@
     Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
     Oct 2003, Nigel Stewart - GLUI Code Cleaning
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
diff --git a/examples/shared/libc3/src/c3cairo.c b/examples/shared/libc3/src/c3cairo.c
index a2b1655..2ab449b 100644
--- a/examples/shared/libc3/src/c3cairo.c
+++ b/examples/shared/libc3/src/c3cairo.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3cairo.h b/examples/shared/libc3/src/c3cairo.h
index 75d64b6..04a53c8 100644
--- a/examples/shared/libc3/src/c3cairo.h
+++ b/examples/shared/libc3/src/c3cairo.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3camera.c b/examples/shared/libc3/src/c3camera.c
index 64abd60..be3070d 100644
--- a/examples/shared/libc3/src/c3camera.c
+++ b/examples/shared/libc3/src/c3camera.c
@@ -4,20 +4,20 @@
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 	Copyright (c) 1998 Paul Rademacher
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <string.h>
diff --git a/examples/shared/libc3/src/c3camera.h b/examples/shared/libc3/src/c3camera.h
index 9342e58..1a719db 100644
--- a/examples/shared/libc3/src/c3camera.h
+++ b/examples/shared/libc3/src/c3camera.h
@@ -4,20 +4,20 @@
  Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
  Copyright (c) 1998 Paul Rademacher
 
- This file is part of simavr.
+ This file is part of libc3.
 
- simavr is free software: you can redistribute it and/or modify
+ libc3 is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
 
- simavr is distributed in the hope that it will be useful,
+ libc3 is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 
  You should have received a copy of the GNU General Public License
- along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+ along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef __C3VIEW_H___
diff --git a/examples/shared/libc3/src/c3context.c b/examples/shared/libc3/src/c3context.c
index 351e631..79508e6 100644
--- a/examples/shared/libc3/src/c3context.c
+++ b/examples/shared/libc3/src/c3context.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <math.h>
diff --git a/examples/shared/libc3/src/c3context.h b/examples/shared/libc3/src/c3context.h
index 91ea4f1..93514cf 100644
--- a/examples/shared/libc3/src/c3context.h
+++ b/examples/shared/libc3/src/c3context.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3driver.h b/examples/shared/libc3/src/c3driver.h
index 901c32d..b48a4c7 100644
--- a/examples/shared/libc3/src/c3driver.h
+++ b/examples/shared/libc3/src/c3driver.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3driver_context.h b/examples/shared/libc3/src/c3driver_context.h
index c3cff59..64d2449 100644
--- a/examples/shared/libc3/src/c3driver_context.h
+++ b/examples/shared/libc3/src/c3driver_context.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3driver_geometry.h b/examples/shared/libc3/src/c3driver_geometry.h
index fa23eb5..f8edddc 100644
--- a/examples/shared/libc3/src/c3driver_geometry.h
+++ b/examples/shared/libc3/src/c3driver_geometry.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3driver_object.h b/examples/shared/libc3/src/c3driver_object.h
index a809439..ed1ea27 100644
--- a/examples/shared/libc3/src/c3driver_object.h
+++ b/examples/shared/libc3/src/c3driver_object.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3geometry.c b/examples/shared/libc3/src/c3geometry.c
index 8de3ead..a10eda5 100644
--- a/examples/shared/libc3/src/c3geometry.c
+++ b/examples/shared/libc3/src/c3geometry.c
@@ -3,23 +3,25 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
+#include <stdio.h>
+#include <math.h>
 #include "c3object.h"
 #include "c3context.h"
 #include "c3driver_geometry.h"
@@ -165,4 +167,84 @@ c3geometry_draw(
 	C3_DRIVER(g, draw);
 }
 
+void
+c3geometry_factor(
+		c3geometry_p g,
+		c3f tolerance,
+		c3f normaltolerance)
+{
+	printf("%s Start geometry has %d vertices and %d indexes\n", __func__,
+			g->vertice.count, g->indices.count);
+	printf("%s Start geometry has %d normals and %d tex\n", __func__,
+			g->normals.count, g->textures.count);
+
+	c3f tolerance2 = tolerance * tolerance;
+
+	int in_index = g->indices.count;
+	int vcount = in_index ? in_index : g->vertice.count;
+	int input = 0;
+	int output = 0;
+	g->indices.count = 0;
+	while (input < vcount) {
+		int current = in_index ? g->indices.e[input] : input;
+		c3vec3 v = g->vertice.e[current];
+		c3vec3 n = g->normals.count ? g->normals.e[current] : c3vec3f(0,0,0);
+		c3vec3 np = c3vec3_polar(n);	// normal in polar coord
+
+		int oi = -1;
+		for (int ci = 0; ci < output && oi == -1; ci++)
+			if (c3vec3_length2(c3vec3_sub(g->vertice.e[ci], v)) < tolerance2) {
+				if (g->normals.count) {
+					c3vec3 nc = g->normals.e[ci];
+					c3vec3 pc = c3vec3_polar(nc);
+
+					c3vec3 d = c3vec3_sub(np, pc);
+					while (d.n[0] <= -M_PI) d.n[0] += (2*M_PI);
+					while (d.n[1] <= -M_PI) d.n[1] += (2*M_PI);
+
+					if (fabs(d.n[0]) < normaltolerance &&
+							fabs(d.n[1]) < normaltolerance) {
+						oi = ci;
+						// replace the compared normal with the 'merged' one
+						// that should hopefully trim it to the right direction
+						// somehow. Not perfect obviously
+						g->normals.e[ci] = c3vec3_add(n, nc);
+					}
+				} else
+					oi = ci;
+			}
+		if (oi == -1) {
+			oi = output;
+			g->vertice.e[output] = g->vertice.e[current];
+			if (g->textures.count)
+				g->textures.e[output] = g->textures.e[current];
+			if (g->normals.count)
+				g->normals.e[output] = n;
+			if (g->colorf.count)
+				g->colorf.e[output] = g->colorf.e[current];
+			output++;
+		}
+		c3indices_array_add(&g->indices, oi);
+		input++;
+	}
+	g->vertice.count = output;
+	c3vertex_array_realloc(&g->vertice, output);
+	if (g->textures.count) {
+		g->textures.count = output;
+		c3tex_array_realloc(&g->textures, output);
+	}
+	if (g->normals.count) {
+		g->normals.count = output;
+		c3vertex_array_realloc(&g->normals, output);
+		for (int ni = 0; ni < output; ni++)
+			g->normals.e[ni] = c3vec3_normalize(g->normals.e[ni]);
+	}
+	if (g->colorf.count) {
+		g->colorf.count = output;
+		c3colorf_array_realloc(&g->colorf, output);
+	}
+	g->dirty = 1;
 
+	printf("%s end geometry has %d vertices and %d indexes\n",  __func__,
+			g->vertice.count, g->indices.count);
+}
diff --git a/examples/shared/libc3/src/c3geometry.h b/examples/shared/libc3/src/c3geometry.h
index 355654f..e7d0183 100644
--- a/examples/shared/libc3/src/c3geometry.h
+++ b/examples/shared/libc3/src/c3geometry.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
@@ -29,24 +29,22 @@
 #ifndef __C3GEOMETRY_H___
 #define __C3GEOMETRY_H___
 
-#include "c3algebra.h"
+#include "c3types.h"
 #include "c_utils.h"
 
-typedef c3vec3 c3vertex, *c3vertex_p;
-typedef c3vec4 c3colorf, *c3colorf_p;
-typedef c3vec2 c3tex, *c3tex_p;
 
 struct c3object_t;
 struct c3pixels_t;
 struct c3program_t;
 
-DECLARE_C_ARRAY(c3vertex, c3vertex_array, 16, uint32_t bid);
-DECLARE_C_ARRAY(c3tex, c3tex_array, 16, uint32_t bid);
-DECLARE_C_ARRAY(c3colorf, c3colorf_array, 16, uint32_t bid);
+DECLARE_C_ARRAY(c3vertex_t, c3vertex_array, 16, c3apiobject_t bid);
+DECLARE_C_ARRAY(c3tex_t, c3tex_array, 16, c3apiobject_t bid);
+DECLARE_C_ARRAY(c3colorf_t, c3colorf_array, 16, c3apiobject_t bid);
+DECLARE_C_ARRAY(c3index_t, c3indices_array, 16, c3apiobject_t bid);
 
-//! Geometry material. TODO: Beef up. Add vertex/fragment programs..
+//! Geometry material.
 typedef struct c3material_t {
-	c3colorf	color;
+	c3colorf_t	color;
 	struct c3pixels_t * texture;
 	struct c3program_t * program;
 	struct {
@@ -54,17 +52,13 @@ typedef struct c3material_t {
 	} blend;
 } c3material_t;
 
-//! Bounding box. TODO: Move to a separate file?
-typedef struct c3bbox_t {
-	c3vec3	min, max;
-} c3bbox_t;
+#define C3_TYPE(_a,_b,_c,_d) \
+	(((uint32_t)(_a)<<24)|((uint32_t)(_b)<<16)|((uint32_t)(_c)<<8)|(_d))
 
 //! Generic geometry type
 enum {
-	C3_RAW_TYPE = 0,
-	C3_LINES_TYPE,
-	C3_TRIANGLE_TYPE,
-	C3_TEXTURE_TYPE,
+	C3_RAW_TYPE = C3_TYPE('r','a','w','g'),
+	C3_TRIANGLE_TYPE = C3_TYPE('t','r','i','a'),
 };
 
 /*!
@@ -73,9 +67,9 @@ enum {
  * contains, like "texture", and the subtype can be used to store the
  * real format of the vertices. like GL_LINES etc
  */
-typedef union c3geometry_type_t {
-	struct  { uint32_t type : 16, subtype : 16; };
-	uint32_t value;
+typedef struct c3geometry_type_t {
+	uint32_t type;
+	c3apiobject_t subtype;
 } c3geometry_type_t;
 
 /*!
@@ -97,6 +91,7 @@ typedef struct c3geometry_t {
 	c3tex_array_t		textures;
 	c3colorf_array_t	colorf;
 	c3vertex_array_t 	normals;
+	c3indices_array_t	indices;
 
 	// projected version of the vertice
 	c3vertex_array_t 	projected;
@@ -152,6 +147,22 @@ void
 c3geometry_draw(
 		c3geometry_p g );
 
+/*
+ * if not present, create an index array, and collapses
+ * the vertex array by removing vertices that are within
+ * 'tolerance' (as a distance between vertices considered equals).
+ * If the normals exists, they are also compared
+ * to normaltolerance (in radian) and if both position and normals
+ * are within tolerance, the vertices are collapsed and the normals
+ * are averaged.
+ * This code allows smooth rendering of STL files generated by
+ * CAD programs that generate only triangle normals.
+ */
+void
+c3geometry_factor(
+		c3geometry_p g,
+		c3f tolerance,
+		c3f normaltolerance);
 
 //! allocate (if not there) and return a custom driver for this geometry
 /*!
@@ -170,12 +181,13 @@ IMPLEMENT_C_ARRAY(c3geometry_array);
 IMPLEMENT_C_ARRAY(c3vertex_array);
 IMPLEMENT_C_ARRAY(c3tex_array);
 IMPLEMENT_C_ARRAY(c3colorf_array);
+IMPLEMENT_C_ARRAY(c3indices_array);
 
 static inline c3geometry_type_t
-c3geometry_type(int type, int subtype)
+c3geometry_type(uint32_t type, int subtype)
 {
 	c3geometry_type_t r;// = { .type = type, .subtype = subtype }; // older gcc <4.6 doesn't like this
-	r.type = type; r.subtype = subtype;
+	r.type = type; r.subtype = (c3apiobject_t)subtype;
 	return r;
 }
 
diff --git a/examples/shared/libc3/src/c3lines.c b/examples/shared/libc3/src/c3lines.c
index 9db9047..a6b85ee 100644
--- a/examples/shared/libc3/src/c3lines.c
+++ b/examples/shared/libc3/src/c3lines.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3lines.h b/examples/shared/libc3/src/c3lines.h
index 7befe47..4ee8b34 100644
--- a/examples/shared/libc3/src/c3lines.h
+++ b/examples/shared/libc3/src/c3lines.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
@@ -25,11 +25,14 @@
 
 #include "c3geometry.h"
 
+enum {
+	C3_LINES_TYPE = C3_TYPE('l','i','n','e'),
+};
 /*
  * Takes an array of points A,B and split it into 'fat' lines around
  * lineWidth, generates an array of triangles and an array of corresponding
- * texture cordinates. Can also do a projection at the same time
- * TODO: Add array indexes
+ * texture coordinates. Can also do a projection at the same time
+ * TODO: Add array indices
  */
 void
 c3lines_prepare(
diff --git a/examples/shared/libc3/src/c3object.c b/examples/shared/libc3/src/c3object.c
index 52cbab3..04d17f1 100644
--- a/examples/shared/libc3/src/c3object.c
+++ b/examples/shared/libc3/src/c3object.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3object.h b/examples/shared/libc3/src/c3object.h
index 78122fa..57f16da 100644
--- a/examples/shared/libc3/src/c3object.h
+++ b/examples/shared/libc3/src/c3object.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3pixels.c b/examples/shared/libc3/src/c3pixels.c
index cdaef7e..63cf99e 100644
--- a/examples/shared/libc3/src/c3pixels.c
+++ b/examples/shared/libc3/src/c3pixels.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <stdlib.h>
diff --git a/examples/shared/libc3/src/c3pixels.h b/examples/shared/libc3/src/c3pixels.h
index 1952123..386f323 100644
--- a/examples/shared/libc3/src/c3pixels.h
+++ b/examples/shared/libc3/src/c3pixels.h
@@ -3,27 +3,27 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
 #ifndef __C3PIXELS_H___
 #define __C3PIXELS_H___
 
-#include <stdint.h>
+#include "c3types.h"
 #include "c_utils.h"
 
 //! for format hint
@@ -51,7 +51,7 @@ typedef struct c3pixels_t {
 		};
 		uint32_t flags;
 	};
-	uint32_t	texture;
+	c3apiobject_t	texture;
 	int			refCount;	// TODO: Implement reference counting ?
 } c3pixels_t, *c3pixels_p;
 
diff --git a/examples/shared/libc3/src/c3program.c b/examples/shared/libc3/src/c3program.c
index e7c7998..5e2edf4 100644
--- a/examples/shared/libc3/src/c3program.c
+++ b/examples/shared/libc3/src/c3program.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <sys/types.h>
@@ -66,6 +66,17 @@ c3program_purge(
 	c3shader_array_free(&p->shaders);
 }
 
+c3program_param_p
+c3program_locate_param(
+		c3program_p p,
+		const char * name )
+{
+	for (int pi = 0; pi < p->params.count; pi++)
+		if (!strcmp(p->params.e[pi].name->str, name))
+			return &p->params.e[pi];
+	return NULL;
+}
+
 int
 c3program_load_shader(
 		c3program_p p,
@@ -138,6 +149,7 @@ c3program_load_shader(
 							.program = p,
 					};
 					c3program_param_array_add(&p->params, pa);
+					if (p->verbose)
 					printf("%s %s: new parameter '%s' '%s'\n", __func__,
 							p->name->str, unitype, uniname);
 				} else
diff --git a/examples/shared/libc3/src/c3program.h b/examples/shared/libc3/src/c3program.h
index dfc6060..626d12b 100644
--- a/examples/shared/libc3/src/c3program.h
+++ b/examples/shared/libc3/src/c3program.h
@@ -3,30 +3,31 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
 #ifndef __C3PROGRAM_H___
 #define __C3PROGRAM_H___
 
+#include "c3types.h"
 #include "c_utils.h"
 
 typedef struct c3shader_t {
-	uint32_t sid;	// shader id
+	c3apiobject_t sid;	// shader id
 	uint32_t type;
 	str_p	name;
 	str_p	shader;
@@ -36,7 +37,7 @@ DECLARE_C_ARRAY(c3shader_t, c3shader_array, 4);
 
 typedef struct c3program_param_t {
 	struct c3program_t * program;
-	int32_t pid;	// parameter id
+	c3apiobject_t pid;	// parameter id
 	str_p	type;
 	str_p	name;
 } c3program_param_t, *c3program_param_p;
@@ -44,11 +45,12 @@ typedef struct c3program_param_t {
 DECLARE_C_ARRAY(c3program_param_t, c3program_param_array, 4);
 
 typedef struct c3program_t {
-	uint32_t pid;	// program id
+	c3apiobject_t pid;	// program id
+	int						verbose : 1;
 	str_p name;
 	c3shader_array_t	shaders;
 	c3program_param_array_t params;
-	str_p	log;
+	str_p					log;	// if an error occurs
 } c3program_t, *c3program_p;
 
 DECLARE_C_ARRAY(c3program_p, c3program_array, 4);
@@ -80,6 +82,11 @@ c3program_load_shader(
 		const char * filename,
 		uint16_t flags);
 
+c3program_param_p
+c3program_locate_param(
+		c3program_p p,
+		const char * name );
+
 IMPLEMENT_C_ARRAY(c3program_param_array);
 IMPLEMENT_C_ARRAY(c3shader_array);
 IMPLEMENT_C_ARRAY(c3program_array);
diff --git a/examples/shared/libc3/src/c3quaternion.c b/examples/shared/libc3/src/c3quaternion.c
index 10dd468..894604e 100644
--- a/examples/shared/libc3/src/c3quaternion.c
+++ b/examples/shared/libc3/src/c3quaternion.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <math.h>
diff --git a/examples/shared/libc3/src/c3quaternion.h b/examples/shared/libc3/src/c3quaternion.h
index 92bf35d..89020ea 100644
--- a/examples/shared/libc3/src/c3quaternion.h
+++ b/examples/shared/libc3/src/c3quaternion.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3sphere.c b/examples/shared/libc3/src/c3sphere.c
new file mode 100644
index 0000000..5a8db4c
--- /dev/null
+++ b/examples/shared/libc3/src/c3sphere.c
@@ -0,0 +1,67 @@
+/*
+	c3sphere.c
+
+	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+ 	This file is part of libc3.
+
+	libc3 is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 3 of the License, or
+	(at your option) any later version.
+
+	libc3 is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <math.h>
+#include "c3geometry.h"
+#include "c3sphere.h"
+
+c3geometry_p
+c3sphere_uv(
+		struct c3object_t * parent,
+		c3vec3 center,
+		c3f radius,
+		int rings,
+		int sectors )
+{
+	float const R = 1. / (float) (rings - 1);
+	float const S = 1. / (float) (sectors - 1);
+
+	c3geometry_p g = c3geometry_new(c3geometry_type(C3_SPHERE_TYPE, 0), parent);
+
+	c3vertex_array_realloc(&g->vertice, rings * sectors);
+	c3vertex_array_realloc(&g->normals, rings * sectors);
+	c3tex_array_realloc(&g->textures, rings * sectors);
+	c3indices_array_realloc(&g->indices, rings * sectors * 6);
+
+	for (int r = 0; r < rings; r++)
+		for (int s = 0; s < sectors; s++) {
+			float const y = sin(-M_PI_2 + M_PI * r * R);
+			float const x = cos(2 * M_PI * s * S) * sin(M_PI * r * R);
+			float const z = sin(2 * M_PI * s * S) * sin(M_PI * r * R);
+
+			c3tex_array_add(&g->textures, c3vec2f(s * S, r * R));
+			c3vertex_array_add(&g->vertice,
+					c3vec3_add(center, c3vec3f(x * radius, y * radius, z * radius)));
+			c3vertex_array_add(&g->normals, c3vec3_normalize(c3vec3f(x, y, z)));
+		}
+
+	for (int r = 0; r < rings - 1; r++)
+		for (int s = 0; s < sectors - 1; s++) {
+			uint16_t i[6] = {
+				r * sectors + (s + 1), r * sectors + s, (r + 1) * sectors + (s + 1),
+				(r + 1) * sectors + (s + 1), r * sectors + s, (r + 1) * sectors + s,
+			};
+			c3indices_array_insert(&g->indices, g->indices.count, i, 6);
+		}
+	return g;
+}
+
diff --git a/examples/shared/libc3/src/c3sphere.h b/examples/shared/libc3/src/c3sphere.h
new file mode 100644
index 0000000..84c1811
--- /dev/null
+++ b/examples/shared/libc3/src/c3sphere.h
@@ -0,0 +1,40 @@
+/*
+	c3sphere.h
+
+	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+ 	This file is part of libc3.
+
+	libc3 is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 3 of the License, or
+	(at your option) any later version.
+
+	libc3 is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __C3SPHERE_H___
+#define __C3SPHERE_H___
+
+#include "c3algebra.h"
+
+enum {
+	C3_SPHERE_TYPE = C3_TYPE('s','p','h','e'),
+};
+
+struct c3geometry_t *
+c3sphere_uv(
+		struct c3object_t * parent,
+		c3vec3 center,
+		c3f radius,
+		int rings,
+		int sectors );
+
+#endif /* __C3SPHERE_H___ */
diff --git a/examples/shared/libc3/src/c3stl.c b/examples/shared/libc3/src/c3stl.c
index c42709b..9183f6d 100644
--- a/examples/shared/libc3/src/c3stl.c
+++ b/examples/shared/libc3/src/c3stl.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <stdio.h>
@@ -97,6 +97,7 @@ c3stl_load(
 				if (!strncmp(keyword, "facet ", 6)) {
 					c3vec3 normal;
 					_c3stl_read_vertex(keyword + 6, &normal);
+					normal = c3vec3_normalize(normal);
 					c3vertex_array_add(&current_g->normals, normal);
 					c3vertex_array_add(&current_g->normals, normal);
 					c3vertex_array_add(&current_g->normals, normal);
diff --git a/examples/shared/libc3/src/c3stl.h b/examples/shared/libc3/src/c3stl.h
index d8bd250..8f562cd 100644
--- a/examples/shared/libc3/src/c3stl.h
+++ b/examples/shared/libc3/src/c3stl.h
@@ -3,26 +3,30 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
 #ifndef __C3STL_H___
 #define __C3STL_H___
 
+/*
+ * Loads an ASCII (TODO: Load STL Binary?) STL file as a c3object with
+ * a set of c3geometries with the triangles
+ */
 struct c3object_t *
 c3stl_load(
 		const char * filename,
diff --git a/examples/shared/libc3/src/c3texture.c b/examples/shared/libc3/src/c3texture.c
index 78a8d20..27ae649 100644
--- a/examples/shared/libc3/src/c3texture.c
+++ b/examples/shared/libc3/src/c3texture.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3texture.h b/examples/shared/libc3/src/c3texture.h
index 1a3af62..ecaae3e 100644
--- a/examples/shared/libc3/src/c3texture.h
+++ b/examples/shared/libc3/src/c3texture.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
@@ -26,10 +26,12 @@
 #include "c3geometry.h"
 #include "c3pixels.h"
 
+enum {
+	C3_TEXTURE_TYPE = C3_TYPE('t','e','x','u'),
+};
+
 typedef struct c3texture_t {
 	c3geometry_t	geometry;
-//	c3pixels_t		pixels;
-//	int normalized : 1;	// use 0.. 1 texture coordinates
 	c3vec2 size;	// quad size
 } c3texture_t, *c3texture_p;
 
diff --git a/examples/shared/libc3/src/c3transform.c b/examples/shared/libc3/src/c3transform.c
index a453ad7..de442aa 100644
--- a/examples/shared/libc3/src/c3transform.c
+++ b/examples/shared/libc3/src/c3transform.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3transform.h b/examples/shared/libc3/src/c3transform.h
index 63e8f38..b6b4289 100644
--- a/examples/shared/libc3/src/c3transform.h
+++ b/examples/shared/libc3/src/c3transform.h
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/src/c3types.h b/examples/shared/libc3/src/c3types.h
new file mode 100644
index 0000000..0c0c8ca
--- /dev/null
+++ b/examples/shared/libc3/src/c3types.h
@@ -0,0 +1,45 @@
+/*
+	c3types.h
+
+	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+ 	This file is part of libc3.
+
+	libc3 is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 3 of the License, or
+	(at your option) any later version.
+
+	libc3 is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __C3TYPES_H___
+#define __C3TYPES_H___
+
+#include <stdint.h>
+#include "c3algebra.h"
+
+typedef c3vec3 c3vertex_t, *c3vertex_p;
+typedef c3vec4 c3colorf_t, *c3colorf_p;
+typedef c3vec2 c3tex_t, *c3tex_p;
+typedef uint16_t	c3index_t, *c3index_p;
+
+/* this type is used to store an API object (texture id etc
+ * it is made to force a cast in most cases as OpenGL uses integers
+ * for object ids
+ */
+typedef void * c3apiobject_t;
+
+//! Bounding box
+typedef struct c3bbox_t {
+	c3vec3	min, max;
+} c3bbox_t;
+
+#endif /* __C3TYPES_H___ */
diff --git a/examples/shared/libc3/src/c_utils.c b/examples/shared/libc3/src/c_utils.c
index e3bb673..0a086de 100644
--- a/examples/shared/libc3/src/c_utils.c
+++ b/examples/shared/libc3/src/c_utils.c
@@ -3,20 +3,20 @@
 
 	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
 
- 	This file is part of simavr.
+ 	This file is part of libc3.
 
-	simavr is free software: you can redistribute it and/or modify
+	libc3 is free software: you can redistribute it and/or modify
 	it under the terms of the GNU General Public License as published by
 	the Free Software Foundation, either version 3 of the License, or
 	(at your option) any later version.
 
-	simavr is distributed in the hope that it will be useful,
+	libc3 is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 	GNU General Public License for more details.
 
 	You should have received a copy of the GNU General Public License
-	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+	along with libc3.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 
diff --git a/examples/shared/libc3/srcgl/c3gl.c b/examples/shared/libc3/srcgl/c3gl.c
new file mode 100644
index 0000000..889633f
--- /dev/null
+++ b/examples/shared/libc3/srcgl/c3gl.c
@@ -0,0 +1,296 @@
+/*
+	c3gl.c
+
+	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+ 	This file is part of simavr.
+
+	simavr is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 3 of the License, or
+	(at your option) any later version.
+
+	simavr is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if __APPLE__
+#define GL_GLEXT_PROTOTYPES
+#include <GLUT/glut.h>
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#else
+#define GL_GLEXT_PROTOTYPES
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#endif
+#include <stdio.h>
+
+
+#include "c3.h"
+#include "c3lines.h"
+#include "c3sphere.h"
+#include "c3program.h"
+
+#include "c3driver_context.h"
+
+#include "c3gl.h"
+
+#define GLCHECK(_w) {_w; dumpError(#_w);}
+
+static int dumpError(const char * what)
+{
+	GLenum e;
+	int count = 0;
+	while ((e = glGetError()) != GL_NO_ERROR) {
+		printf("%s: %s\n", what, gluErrorString(e));
+		count++;
+	}
+	return count;
+}
+
+static void
+_c3_load_program(
+		c3program_p p)
+{
+	if (!p || p->pid || p->log)
+		return;
+
+	if (p->verbose)
+		printf("%s loading %s\n", __func__, p->name->str);
+	for (int si = 0; si < p->shaders.count && !p->log; si++) {
+		c3shader_p s = &p->shaders.e[si];
+
+		if (p->verbose)
+			printf("%s compiling shader %s\n", __func__, s->name->str);
+
+		s->sid = (c3apiobject_t)glCreateShader(s->type);
+		const GLchar * pgm = s->shader->str;
+		glShaderSource((GLuint)s->sid, 1, &pgm, NULL);
+
+		glCompileShader((GLuint)s->sid);
+
+		GLint status;
+		glGetShaderiv((GLuint)s->sid, GL_COMPILE_STATUS, &status);
+
+		if (status != GL_FALSE)
+			continue;
+
+		GLint infoLogLength;
+		glGetShaderiv((GLuint)s->sid, GL_INFO_LOG_LENGTH, &infoLogLength);
+
+		p->log = str_alloc(infoLogLength);
+		glGetShaderInfoLog((GLuint)s->sid, infoLogLength, NULL, p->log->str);
+
+		fprintf(stderr, "%s compile %s: %s\n", __func__, s->name->str, p->log->str);
+		break;
+	}
+	if (p->log)
+		return;
+    p->pid = (c3apiobject_t)glCreateProgram();
+
+	for (int si = 0; si < p->shaders.count && !p->log; si++) {
+		c3shader_p s = &p->shaders.e[si];
+
+    	glAttachShader((GLuint)p->pid, (GLuint)s->sid);
+	}
+    glLinkProgram((GLuint)p->pid);
+
+    GLint status;
+    glGetProgramiv((GLuint)p->pid, GL_LINK_STATUS, &status);
+
+	for (int si = 0; si < p->shaders.count && !p->log; si++) {
+		c3shader_p s = &p->shaders.e[si];
+
+		glDetachShader((GLuint)p->pid, (GLuint)s->sid);
+		glDeleteShader((GLuint)s->sid);
+    	s->sid = 0;
+	}
+
+    if (status == GL_FALSE) {
+        GLint infoLogLength;
+        glGetProgramiv((GLuint)p->pid, GL_INFO_LOG_LENGTH, &infoLogLength);
+
+		p->log = str_alloc(infoLogLength);
+
+        glGetProgramInfoLog((GLuint)p->pid, infoLogLength, NULL, p->log->str);
+		fprintf(stderr, "%s link %s: %s\n", __func__, p->name->str, p->log->str);
+
+		goto error;
+    }
+    for (int pi = 0; pi < p->params.count; pi++) {
+    	c3program_param_p pa = &p->params.e[pi];
+    	pa->pid = (c3apiobject_t)glGetUniformLocation((GLuint)p->pid, pa->name->str);
+    	if (p->verbose)
+    		printf("%s %s load parameter '%s'\n", __func__, p->name->str, pa->name->str);
+    	if (pa->pid == (c3apiobject_t)-1) {
+    		fprintf(stderr, "%s %s: parameter '%s' not found\n",
+    				__func__, p->name->str, pa->name->str);
+    	}
+    }
+
+    c3program_purge(p);
+    return;
+error:
+	c3program_purge(p);
+	if (p->pid)
+		glDeleteProgram((GLuint)p->pid);
+	p->pid = 0;
+}
+
+static void
+_c3_load_pixels(
+		c3pixels_p pix)
+{
+	GLuint mode = pix->normalize ? GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE_ARB;
+	if (!pix->texture) {
+		if (pix->trace)
+			printf("%s Creating texture %s %dx%d\n",
+				__func__, pix->name ? pix->name->str : "", pix->w, pix->h);
+		pix->dirty = 1;
+		GLuint texID = 0;
+		GLCHECK(glEnable(mode));
+
+		glGenTextures(1, &texID);
+//		glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
+//				GL_MODULATE); //set texture environment parameters
+//		dumpError("glTexEnvf");
+
+		glPixelStorei(GL_UNPACK_ROW_LENGTH, pix->row / pix->psize);
+		GLCHECK(glTexParameteri(mode, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
+		GLCHECK(glTexParameteri(mode, GL_TEXTURE_MIN_FILTER,
+				pix->normalize ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
+		GLCHECK(glTexParameteri(mode, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER));
+		GLCHECK(glTexParameteri(mode, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER));
+		if (pix->normalize)
+			GLCHECK(glTexParameteri(mode, GL_GENERATE_MIPMAP, GL_TRUE));
+	#if 1
+		GLfloat fLargest;
+		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
+		//printf("fLargest = %f\n", fLargest);
+		GLCHECK(glTexParameterf(mode, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest));
+	#endif
+		if (pix->normalize)
+			GLCHECK(glGenerateMipmap(mode));
+
+		pix->texture = (c3apiobject_t)texID;
+		pix->dirty = 1;
+	}
+	if (pix->dirty) {
+		pix->dirty = 0;
+		GLCHECK(glBindTexture(mode, (GLuint)pix->texture));
+		glTexImage2D(mode, 0,
+				pix->format == C3PIXEL_A ? GL_ALPHA16 : GL_RGBA8,
+				pix->w, pix->h, 0,
+				pix->format == C3PIXEL_A ? GL_ALPHA : GL_BGRA,
+				GL_UNSIGNED_BYTE,
+				pix->base);
+		dumpError("glTexImage2D");
+		if (pix->normalize)
+			GLCHECK(glGenerateMipmap(mode));
+	}
+}
+
+static void
+_c3_geometry_project(
+		c3context_p c,
+		const struct c3driver_context_t * d,
+		c3geometry_p g,
+		c3mat4p m)
+{
+	if (g->mat.texture)
+		_c3_load_pixels(g->mat.texture);
+	if (g->mat.program)
+		_c3_load_program(g->mat.program);
+
+	switch(g->type.type) {
+		case C3_SPHERE_TYPE:
+		case C3_TRIANGLE_TYPE:
+		case C3_LINES_TYPE:
+			g->type.subtype = (c3apiobject_t)GL_TRIANGLES;
+			break;
+		case C3_TEXTURE_TYPE: {
+			if (g->mat.texture)
+				g->type.subtype = (c3apiobject_t)GL_TRIANGLE_FAN;
+		}	break;
+		default:
+		    break;
+	}
+}
+
+/*
+ * Thid id the meta function that draws a c3geometry. It looks for normals,
+ * indices, textures and so on and call the glDrawArrays
+ */
+static void
+_c3_geometry_draw(
+		c3context_p c,
+		const struct c3driver_context_t *d,
+		c3geometry_p g )
+{
+	glColor4fv(g->mat.color.n);
+	dumpError("glColor");
+//	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, g->mat.color.n);
+	glVertexPointer(3, GL_FLOAT, 0,
+			g->projected.count ? g->projected.e : g->vertice.e);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	dumpError("GL_VERTEX_ARRAY");
+	glDisable(GL_TEXTURE_2D);
+	if (g->mat.texture) {
+		GLuint mode = g->mat.texture->normalize ?
+				GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE_ARB;
+		glEnable(mode);
+		if (g->mat.texture->trace)
+			printf("%s uses texture %s (%d tex)\n",
+					__func__, g->mat.texture->name->str, g->textures.count);
+	//	printf("tex mode %d texture %d\n", g->mat.mode, g->mat.texture);
+		dumpError("glEnable texture");
+		glBindTexture(mode, (GLuint)g->mat.texture->texture);
+		dumpError("glBindTexture");
+		glTexCoordPointer(2, GL_FLOAT, 0, g->textures.e);
+		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+		dumpError("GL_TEXTURE_COORD_ARRAY");
+	}
+	if (g->mat.program) {
+		GLCHECK(glUseProgram((GLuint)g->mat.program->pid));
+	}
+	if (g->normals.count) {
+		GLCHECK(glNormalPointer(GL_FLOAT, 0, g->normals.e));
+		glEnableClientState(GL_NORMAL_ARRAY);
+	}
+	if (g->indices.count) {
+	//	GLCHECK(glIndexPointer(GL_UNSIGNED_SHORT, 0, g->indices.e));
+	//	glEnableClientState(GL_INDEX_ARRAY);
+		GLCHECK(glDrawElements((GLuint)g->type.subtype,
+				g->indices.count, GL_UNSIGNED_SHORT,
+				g->indices.e));
+	//	glDisableClientState(GL_INDEX_ARRAY);
+	} else {
+		glDrawArrays((GLuint)g->type.subtype, 0,
+			g->projected.count ? g->projected.count : g->vertice.count);
+	}
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+	glDisableClientState(GL_NORMAL_ARRAY);
+	if (g->mat.texture)
+		glDisable(g->mat.texture->normalize ? GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE_ARB);
+	if (g->mat.program)
+		glUseProgram(0);
+}
+
+const c3driver_context_t c3context_driver = {
+		.geometry_project = _c3_geometry_project,
+		.geometry_draw = _c3_geometry_draw,
+};
+
+const struct c3driver_context_t *
+c3gl_getdriver()
+{
+	return &c3context_driver;
+}
diff --git a/examples/shared/libc3/srcgl/c3gl.h b/examples/shared/libc3/srcgl/c3gl.h
new file mode 100644
index 0000000..9d999c9
--- /dev/null
+++ b/examples/shared/libc3/srcgl/c3gl.h
@@ -0,0 +1,29 @@
+/*
+	c3gl.h
+
+	Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
+
+ 	This file is part of simavr.
+
+	simavr is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 3 of the License, or
+	(at your option) any later version.
+
+	simavr is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with simavr.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __C3GL_H___
+#define __C3GL_H___
+
+const struct c3driver_context_t *
+c3gl_getdriver();
+
+#endif /* __C3GL_H___ */