EAGL.Examples.LearnOpenGL.GettingStarted.HelloTriangle (eagl v0.6.0)

View Source

LearnOpenGL 2.1 - Hello Triangle

This example demonstrates your first triangle in OpenGL - the foundation of all 3D graphics. It corresponds to the Hello Triangle 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/2.1.hello_triangle

Framework Adaptation Notes

In the original LearnOpenGL C++ tutorial, this example introduces the core OpenGL rendering pipeline: vertex data → vertex shader → primitive assembly → fragment shader → framebuffer.

EAGL's framework simplifies the setup while preserving all educational concepts:

  • Shader compilation and linking are handled by EAGL.Shader helpers
  • VAO/VBO creation uses EAGL.Buffer convenience functions
  • Error checking and resource cleanup are automated
  • The core OpenGL concepts remain unchanged and visible

Original Tutorial Concepts Demonstrated

  1. Vertex Data: Defining triangle vertices in normalized device coordinates (-1 to 1)
  2. Vertex Buffer Objects (VBO): Storing vertex data in GPU memory
  3. Vertex Array Objects (VAO): Configuring how vertex data is interpreted
  4. Vertex Shaders: Processing each vertex (position transformation)
  5. Fragment Shaders: Determining pixel colors
  6. Rendering Pipeline: glDrawArrays() triggers the complete pipeline

Key Learning Points

  • Understanding normalized device coordinates (NDC)
  • The relationship between VBOs and VAOs
  • How shaders process vertices and fragments
  • The OpenGL rendering pipeline flow
  • Basic primitive rendering with glDrawArrays

Triangle Geometry

The triangle is defined by 3 vertices in normalized device coordinates:

    (0.0, 0.5)
       /\
      /  \
     /    \
    /______\
(-0.5,-0.5) (0.5,-0.5)

Difference from Previous Examples

  • 1.1 Hello Window: Just a black window (no geometry)
  • 1.2 Hello Window Clear: Custom clear color (no geometry)
  • 2.1 Hello Triangle: First actual geometry rendering with shaders

Usage

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

Press ENTER to exit the example.

Summary

Functions

run_example()

@spec run_example() :: :ok | {:error, term()}