EAGL.Examples.LearnOpenGL.GettingStarted.TexturesExercise2 (eagl v0.8.0)

View Source

LearnOpenGL 4.4 - Textures Exercise 2

This exercise demonstrates texture wrapping modes by using texture coordinates outside the 0.0 to 1.0 range. It shows how different wrapping modes (repeat, mirrored repeat, clamp to edge, clamp to border) affect texture appearance.

Original C++ Source

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

Exercise Focus

This exercise demonstrates:

  • Texture Coordinates > 1.0: Using coordinates like 0.0 to 2.0 instead of 0.0 to 1.0
  • Texture Wrapping Modes: Different ways OpenGL handles out-of-range coordinates
  • Visual Patterns: How wrapping creates repeating or clamped patterns
  • Border Colors: Setting custom colors for border clamping mode

Texture Wrapping Modes

  • GL_REPEAT: Default - texture repeats infinitely (tiles)
  • GL_MIRRORED_REPEAT: Texture repeats but alternates mirrored
  • GL_CLAMP_TO_EDGE: Coordinates clamped to 0.0-1.0, edges stretched
  • GL_CLAMP_TO_BORDER: Out-of-range areas filled with border color

EAGL Implementation

This implementation uses texture coordinates from 0.0 to 2.0, causing the texture to repeat twice in each direction with GL_REPEAT mode:

@vertices [
  # positions      # colors       # texture coords (0.0 to 2.0)
   0.5,  0.5, 0.0, 1.0, 0.0, 0.0, 2.0, 2.0,  # top right
   0.5, -0.5, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0,  # bottom right
  -0.5, -0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,  # bottom left
  -0.5,  0.5, 0.0, 1.0, 1.0, 0.0, 0.0, 2.0   # top left
]

Key Learning Points

  • Texture Wrapping: How OpenGL handles coordinates outside 0.0-1.0
  • Tiling Effects: Creating repeating patterns with textures
  • Border Control: Using custom border colors for specific effects
  • Pattern Variety: Different wrapping modes create different visual patterns

Visual Effect

With GL_REPEAT mode and 2.0 coordinates, you'll see the texture repeated 4 times (2x2 grid). This demonstrates how texture wrapping enables tiling patterns for surfaces like floors, walls, or repeating backgrounds.

Usage

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

Press ENTER to exit the example.

Summary

Functions

run_example(opts \\ [])