EAGL.Examples.LearnOpenGL.GettingStarted.TexturesExercise1 (eagl v0.8.0)
View SourceLearnOpenGL 4.3 - Textures Exercise 1
This exercise demonstrates texture coordinate manipulation to show only part of a texture or flip its orientation. It's commonly used to show the center pixels of a texture or to flip textures horizontally/vertically.
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.3.textures_exercise1
Exercise Focus
Common texture coordinate exercises include:
- Center Cropping: Using texture coordinates like (0.25, 0.25) to (0.75, 0.75)
- Texture Flipping: Reversing texture coordinates to flip images
- Coordinate Scaling: Using coordinates > 1.0 to see texture wrapping effects
- Pixel Visibility: Using GL_NEAREST filtering to see individual pixels
EAGL Implementation
This implementation demonstrates center cropping - showing only the central portion of the texture by using texture coordinates that map to the center 50% of the image:
# Instead of full texture coordinates (0.0 to 1.0)
# Use center coordinates (0.25 to 0.75)
@vertices [
# positions # colors # texture coords (center crop)
0.5, 0.5, 0.0, 1.0, 0.0, 0.0, 0.75, 0.75, # top right
0.5, -0.5, 0.0, 0.0, 1.0, 0.0, 0.75, 0.25, # bottom right
-0.5, -0.5, 0.0, 0.0, 0.0, 1.0, 0.25, 0.25, # bottom left
-0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.25, 0.75 # top left
]
Key Learning Points
- Texture Coordinates: Don't have to span full 0.0 to 1.0 range
- Partial Sampling: Can show only portions of textures
- Coordinate Mapping: How vertex positions map to texture coordinates
- Filtering Effects: How GL_NEAREST vs GL_LINEAR affects small texture regions
- Creative Control: Texture coordinates provide artistic flexibility
Visual Effect
This exercise shows only the center portion of the texture, effectively cropping the image and scaling it to fill the rectangle. With GL_NEAREST filtering, individual pixels become more visible.
Usage
EAGL.Examples.LearnOpenGL.GettingStarted.TexturesExercise1.run_example()
Press ENTER to exit the example.