EAGL.Examples.LearnOpenGL.GettingStarted.ShadersClass (eagl v0.9.0)

View Source

LearnOpenGL 3.3 - Shaders Class

This example demonstrates the same vertex colour interpolation as 3.2, but emphasises the importance of shader abstraction and organisation. It shows how to structure shader management in a clean, reusable way. It corresponds to the Shaders Class tutorial in the LearnOpenGL series.

Original C++ Source

This example is based on the original LearnOpenGL C++ tutorial: https://github.com/JoeyDeVries/LearnOpenGL/tree/master/src/1.getting_started/3.3.shaders_class

Framework Adaptation Notes

In the original LearnOpenGL C++ tutorial, this example introduces shader class abstraction:

  • How to encapsulate shader compilation, linking, and error handling
  • How to create reusable shader management utilities
  • How to provide clean APIs for setting uniforms and using shaders
  • The importance of proper resource management and cleanup

EAGL's framework already provides this abstraction through EAGL.Shader:

  • create_shader/2 handles compilation with automatic error reporting
  • create_attach_link/1 handles linking with error checking
  • set_uniform/3 provides type-safe uniform setting
  • All following the same patterns as the original tutorial's Shader class

Key Concept: Shader Abstraction

Why shader classes/modules are important:

  • Encapsulate complex OpenGL shader operations
  • Provide error handling and debugging information
  • Enable code reuse across multiple examples
  • Simplify shader management in larger applications
  • Abstract away low-level OpenGL details

EAGL.Shader Module Features:

  • Automatic shader compilation with error reporting
  • File-based shader loading from priv/shaders/
  • Type-safe uniform setting with automatic type detection
  • Resource cleanup and management
  • Consistent error handling patterns

Visual Result

Identical to 3.2 Shaders Interpolation:

  • Bottom-right corner: Red (1.0, 0.0, 0.0)
  • Bottom-left corner: Green (0.0, 1.0, 0.0)
  • Top center: Blue (0.0, 0.0, 1.0)
  • Interior pixels: Smooth interpolation between these colors

Difference from Previous Examples

  • 3.2 Shaders Interpolation: Focus on interpolation concept
  • 3.3 Shaders Class: Same visual result, emphasis on clean shader abstraction

Usage

EAGL.Examples.LearnOpenGL.GettingStarted.ShadersClass.run_example()

Press ENTER to exit the example.

Summary

Functions

run_example(opts \\ [])