dEngine: OpenGL ES Rendering Engine for iPhone, Source Code Available
Fabien Sanglard, a canadian coder (I must say I like his website, simple and neat!), has released the source code of an OpenGL ES rendering engine he wrote back in 2009. This engine called dEngine (again a simple choice!) can be seen as a good introduction of OpenGL ES programming for iPhone. The engine is written in pure C.
Most of the OpenGL ES and shader management code is localized in the renderer_prog.c file. dEngine uses an uber-shader to reduce branching in the fragment shader. The uber-shader contains the code for different kind of materials delimited by some #idef. Final shaders for rendering are generated during the execution and are cached.
Here is a code snippet of the uber-shader used in
#ifdef BUMP_MAPPING bump = texture2D(s_bumpMap, v_texcoord).rgb * 2.0 - 1.0; lamberFactor = max(0.0,dot(lightVec, bump) ); specularFactor = max(0.0,pow(dot(halfVec,bump),materialShininess)) ; #else lamberFactor = max(0.0,dot(lightVec, v_normal) ); specularFactor = max(0.0,pow(dot(halfVec,v_normal),materialShininess)) ; #endif #ifdef SPEC_MAPPING vec3 matTextColor = texture2D(s_specularMap, v_texcoord).rgb; #else vec3 matTextColor = matColorSpecular; #endif
And don’t forget id Software version of Wolf3D for iPhone. You can download Wolf3D for iPhone HERE.