Ultra-compact sprite rendering code with example frame animation logic. This release contains tech bits from the upcoming SuperNeo™ 2D game engine and includes rotation, anchor/pivot point, color filtering, alpha blending and built-in antialiased point sampling. As usual: complete, runnable single-function app. ~150 LOC. No modern C++, OOP or (other) obscuring cruft.
Sprites are rendered back-to-front (AKA "painter's algorithm") in the order they are submitted, as one draw call. The provided setup employs a single texture atlas containing all the sprite graphics.
The renderer is "im
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
| { | |
| vec2 uv = fragCoord/iResolution.yy; | |
| vec3 col; | |
| float iter = 10.; | |
| float step = 1./iter; | |
| for (float i=1.; i<=iter; i++) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io; | |
| pub fn closest_factors(n: i32) -> (i32, i32) { | |
| let (mut a, mut b, mut c, mut d): (i32, i32, i32, i32); | |
| a = (n as f64).sqrt() as i32; | |
| b = a; | |
| c = n - a * a; | |
| if a != 0 { | |
| d = c / a; | |
| b += d; |
