OpenGL 3.3 core rendering on top of SDL2. Builds on sdl2.obl for the window and context; this bundle is the GL side. Compile with -lib sdl2.
Layers, thinnest first: GLWindow (window and context), GL (state), Shader, Mesh, Texture2D, Light, RenderTarget, Material, Frustum, ShadowMap, PointShadow, Overlay, Transform, and Box/Scene. All public, so nothing is capped.
Targets the 3.3 core profile, forward-compatible: the highest common denominator across the desktop platforms Objeck ships, since macOS caps at 4.1 core. GLES-only hardware is out of scope by construction.
See docs/opengl.md for setup, a minimal program, why the calls are coarse-grained, and how to add one.
LightRig
Several lights at once, plus the ambient they all sit on top of.
One directional light is enough to see a scene; anything with a lamp, a fire, a torch or a window needs more, and this is how a forward renderer carries them -- as arrays with a count, written once per frame.
The limit is fixed, and low on purpose
GLSL needs a compile-time array size, so the maximum is a constant rather than whatever you add. Eight, because a forward renderer evaluates EVERY light for EVERY fragment -- the cost is lights times pixels, and this is the point where a deferred renderer would be the answer instead. Lights past the limit are ignored rather than silently replacing others.
The eye position
Specular highlights depend on where the viewer is, so SetViewPosition has to be told each frame if the camera moves. Forget it and the highlights sit still while the camera orbits, which looks like the material is wrong rather than like a missing call.
Example
rig := LightRig->New();
rig->Add(Light->Directional(Vector3->New(-0.3, 1.0, 0.4)));
rig->Add(Light->Point(Vector3->New(2.0, 1.5, 0.0), 8.0));
rig->SetAmbient(0.18, 0.19, 0.24);
# once a frame, before drawing
rig->SetViewPosition(camera->GetPosition());
rig->ApplyTo(shader);Operations
Add #
Add a light. Beyond GetMaxLights it is ignored.
method : public : Add(light:Light) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| light | Light | the light |
Return
| Type | Description |
|---|---|
| Bool | true when it was taken |
ApplyTo #
Write the whole rig into a shader.
Once a frame, not once per object: none of it varies between objects. Uniforms the shader does not declare are skipped, so an unlit program can be handed this without filing a diagnostic.
method : public : ApplyTo(shader:Shader) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| shader | Shader | the program about to draw |
Clear #
Remove every light. Ambient and the material settings are kept.
method : public : Clear() ~ NilGet #
method : public : Get(index:Int) ~ LightParameters
| Name | Type | Description |
|---|---|---|
| index | Int | which light |
Return
| Type | Description |
|---|---|
| Light | the light, or Nil when out of range |
GetMaxLights # function
How many lights a shader built by this bundle can take.
function : GetMaxLights() ~ IntReturn
| Type | Description |
|---|---|
| Int | the maximum |
GetShininess #
method : public : GetShininess() ~ FloatReturn
| Type | Description |
|---|---|
| Float | the scene-wide shininess, so a Material that overrode it can be put back rather than guessed at |
GetSpecular #
method : public : GetSpecular() ~ FloatReturn
| Type | Description |
|---|---|
| Float | the scene-wide specular strength |