EAGL.Examples.LearnOpenGL.GettingStarted.HelloTriangleExercise1 (eagl v0.5.0)

View Source

LearnOpenGL 2.3 - Hello Triangle Exercise 1 (Two Triangles Side by Side)

This example demonstrates drawing multiple triangles with a single draw call. It solves the first exercise from the Hello Triangle tutorial.

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.3.hello_triangle_exercise1

Framework Adaptation Notes

In the original LearnOpenGL C++ tutorial, this exercise asks you to draw 2 triangles next to each other using glDrawArrays by adding more vertices to your data.

EAGL's framework maintains the same approach:

  • Single VAO/VBO containing all vertex data
  • One glDrawArrays call renders both triangles
  • No indexing - each triangle uses 3 unique vertices

Original Tutorial Exercise

Exercise 1: Try to draw 2 triangles next to each other using glDrawArrays by adding more vertices to your data.

Solution Concepts Demonstrated

  1. Multiple Primitives: Drawing 2 triangles with one draw call
  2. Vertex Array Layout: 6 vertices arranged as 2 separate triangles
  3. Spatial Positioning: Placing triangles side by side in NDC space
  4. Draw Call Efficiency: Single glDrawArrays for multiple primitives
  5. Vertex Ordering: Understanding how vertices form triangles

Key Learning Points

  • How to structure vertex data for multiple primitives
  • The relationship between vertex count and triangle count
  • Positioning geometry in normalized device coordinates
  • When to use glDrawArrays vs glDrawElements
  • Understanding primitive assembly from vertex streams

Triangle Geometry

Two triangles positioned side by side:

Left Triangle:     Right Triangle:
    /\                 /\
   /  \               /  \
  /____\             /____\

6 vertices total: 3 for left triangle + 3 for right triangle No vertex sharing (unlike indexed rendering)

Difference from Previous Examples

  • 2.1 Hello Triangle: 1 triangle, 3 vertices
  • 2.2 Hello Triangle Indexed: 1 rectangle (2 triangles), 4 vertices + indices
  • 2.3 Exercise 1: 2 triangles, 6 vertices (no sharing)

Usage

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

Press ENTER to exit the example.

Summary

Functions

run_example()

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