NeHe Legacy Tutorials on SDL_GPU

Re-implementations of the venerable NeHe legacy OpenGL lessons with SDL3's modern GPU API. Lessons 1-10 are currently available in several different languages (C99, Rust, and Swift)

Lessons 01 - 05

Lesson 01: Creating An OpenGL SDL_GPU Window

The simplest lesson, covers creating just enough render pass to clear the screen.

Lesson 02: Creating Your First Polygon & Quad

The real polygonal "Hello world". Instead of old-school glBegin/glEnd calls we store the shapes in static vertex & index buffers, which are much more efficient. We also introduce our first shader program, which simply applies our combined model-view-projection matrix to the model in the vertex shader and shades the fragments white.

Lesson 03: Flat and Smooth Colors

In place of glColor3f calls; we add RGBA components to our vertex structure and modify our shader program to interpolate colours between vertices and output the result to each fragment.

Lesson 04: Rotating A Polygon

We have already been using a tiny matrix maths library in place of legacy GL's gl* matrix stack manipulation calls, we're now using Mtx_Rotate in place of glRotatef to apply a little animation to our previously static shapes.

Lesson 05: Solid Objects

Like the original, we modify our shapes to fully bring them into the 3rd dimension, turning our triangle into a pyramid and our quad into a cube.

Lessons 06 - 10

Lesson 06: Texture Mapping

Finally, we get to texture mapping. The original lesson is split between an older version based around auxDIBImageLoad from the long-deprecated Microsoft-only GLaux library, and an updated addendum demonstrating replacing its usage with SOIL. Because the textures are in BMP format we can use the SDL built-in SDL_LoadBMP, which lets us take advantage of the vast Surfaces API to flip the image into the orientation the original program expects, as well as handle pixel format conversion for us.

We modify our pipeline and shader program to replace vertex colours with a texture sampler, we can now bind our texture to the render pass and draw a beautiful textured cube.

Lesson 07: Texture Filters, Basic Lighting & Keyboard Control

This lesson introduces multiple texture filtering styles, keyboard control for rotating the cube, and togglable lighting.

Lighting introduces a new shader which implements just enough legacy-style Gouraud shading to visually match the original, which required adding a few magic constants to the lighting maths. As lighting is a separate shader program; we create a second pipeline state for it.

OpenGL filtering & wrap modes are properties of a texture, NeHe chose to implement switching filtering modes by uploading the same texture multiple times and switching them at runtime. In modern graphics APIs; texture buffers and samplers are separate constructs, so we only need to upload one static texture and cycle samplers instead.

The last sampler enables mip-mapping. The original lesson uses GLU's gluBuild2DMipmaps call (which can more or less be substituted with glGenerateMipmap in later versions of OpenGL) to programmatically generate mip-map levels at startup. In SDL_GPU we can use SDL_GenerateMipmapsForGPUTexture with layer_count_or_depth set to floor(\log_2\max(width,height))+1 to replicate OpenGL's behaviour.

Lesson 08: Blending

Lesson 09: Animated Scenes With Blended Textures

Lesson 10: Loading And Moving Through A 3D World

Description
NeHe Productions legacy (OpenGL) lessons in SDL_GPU (C99, Rust, Swift)
Readme 431 KiB
Languages
Rust 32.5%
Swift 31.1%
C 29.4%
Python 2.7%
HLSL 1.6%
Other 2.7%