EAGL.Examples.LearnOpenGL.GettingStarted.CoordinateSystems (eagl v0.8.0)
View SourceLearnOpenGL 6.1 - Coordinate Systems
This example demonstrates the three coordinate systems in OpenGL - model, world, view, and clip space - by using model, view, and projection matrices to render a 3D cube.
IMPORTANT: This example intentionally does NOT enable depth testing, which causes visual confusion where cube faces render in the wrong order. This demonstrates why depth testing is crucial for 3D rendering. See example 6.2 for the corrected version.
Original C++ Source
This example is based on the original LearnOpenGL C++ tutorial: https://github.com/JoeyDeVries/LearnOpenGL/tree/master/src/1.getting_started/6.1.coordinate_systems
Framework Adaptation Notes
In the original LearnOpenGL C++ tutorial, this example introduces:
- The OpenGL coordinate system transformation pipeline
- Model matrix: local to world space transformation
- View matrix: world to view space transformation (camera positioning)
- Projection matrix: view to clip space transformation (perspective projection)
- Understanding the complete transformation: projection view model * vertex
EAGL's framework preserves all these concepts while providing enhanced functionality:
- Comprehensive Math Library: Uses EAGL.Math with GLM-compatible matrix functions
- Simplified Matrix Setup: Enhanced matrix creation and uniform setting
- 3D Rendering Issues: Depth testing disabled to show visual problems without Z-buffer
- Camera Positioning: Proper view matrix setup for 3D scene viewing
- Error Handling: Comprehensive error checking throughout setup and rendering
EAGL vs Original Implementation
Original LearnOpenGL approach: Manual GLM matrix creation:
glm::mat4 model = glm::mat4(1.0f);
model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f));
glm::mat4 view = glm::mat4(1.0f);
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
glm::mat4 projection = glm::mat4(1.0f);
projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
EAGL approach: Streamlined matrix operations:
model = mat4_identity()
|> mat4_mul(mat4_rotate(vec3(0.5, 1.0, 0.0), time * radians(50.0)))
view = mat4_identity()
|> mat4_mul(mat4_translate(vec3(0.0, 0.0, -3.0)))
projection = mat4_perspective(radians(45.0), aspect_ratio, 0.1, 100.0)
Key Learning Points
- Coordinate Systems: Understanding local, world, view, and clip space
- Matrix Transformation Pipeline: How vertices are transformed through the pipeline
- Model Matrix: Positioning, rotating, and scaling objects in world space
- View Matrix: Positioning and orienting the camera in the scene
- Projection Matrix: Converting 3D coordinates to 2D screen coordinates
- Visual Artifacts: See what happens WITHOUT depth testing (faces render incorrectly)
Mathematical Background
This example demonstrates the complete 3D rendering pipeline:
- Local Space: Object's vertex positions relative to its origin
- World Space: Positioning objects in the global 3D world using model matrix
- View Space: Camera's perspective of the world using view matrix
- Clip Space: Projection to screen coordinates using projection matrix
- Screen Space: Final 2D coordinates for rasterization
Visual Effect
The example shows a textured 3D cube that:
- Rotates: Around a diagonal axis using the model matrix
- Positioned: At the world origin, viewed from a distance
- Projected: Using perspective projection for realistic 3D appearance
- Visually Confusing: Faces render in wrong order without depth testing.
Usage
EAGL.Examples.LearnOpenGL.GettingStarted.CoordinateSystems.run_example()
Press ENTER to exit the example.