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

View Source

LearnOpenGL 4.6 - Textures Exercise 4

This exercise demonstrates dynamic texture mixing with animated mix ratios. Instead of a fixed mix value, the blend between textures changes over time, creating an animated transition effect.

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.6.textures_exercise4

Exercise Focus

This exercise demonstrates:

  • Dynamic Uniforms: Updating uniform values each frame
  • Time-based Animation: Using time to create smooth transitions
  • Interactive Effects: Creating animated visual effects with textures
  • Mix Function Control: Real-time control of texture blending

EAGL Implementation

This implementation uses time-based animation to cycle the mix ratio between two textures, creating a smooth transition effect:

# In the fragment shader:
mix_factor = sin(time * 2.0) * 0.5 + 0.5  # Oscillates between 0.0 and 1.0
FragColor = mix(texture1, texture2, mix_factor)

Key Learning Points

  • Dynamic Uniforms: How to update shader uniforms each frame
  • Time Animation: Using time to create smooth, cyclic animations
  • Visual Effects: Creating engaging animated transitions
  • Interactive Graphics: Real-time parameter control in shaders

Visual Effect

The example shows two textures that smoothly blend back and forth over time. The mix ratio oscillates between 0.0 (first texture only) and 1.0 (second texture only), creating a rhythmic fade effect.

Usage

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

Press ENTER to exit the example.

Summary

Functions

run_example(opts \\ [])