examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

commit ca9406c1b018edf610a767c77a0d22bec8ce2bac
parent 97bf4e4f5c2f09ee6f2e843aed1b27aed306bcb0
Author: Henry Wilson <henry@henryandlizzy.uk>
Date:   Sun,  3 Apr 2022 14:17:43 +0100

gl-asteroids: Draw everything 5 times to avoid popping

Diffstat:
Msrc/gl-asteroids.cpp | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/gl-asteroids.cpp b/src/gl-asteroids.cpp @@ -139,16 +139,20 @@ bool is_colliding(physics const& a, physics const& b) void draw(visual const& v, physics const& p) { - glBegin(v.mode); - - for (unsigned i = 0; i < v.v.size(); ++i) + static coord const offsets[] = {{0,0}, {2,0}, {0,2}, {-2,0}, {0,-2}}; + for (auto offset : offsets) { - if (i < v.c.size()) - glColor(v.c[i]); - glCoord(rotate(v.v[i] * p.scale, p.rot) + p.pos); - } + glBegin(v.mode); + + for (unsigned i = 0; i < v.v.size(); ++i) + { + if (i < v.c.size()) + glColor(v.c[i]); + glCoord(rotate(v.v[i] * p.scale, p.rot) + p.pos + offset); + } - glEnd(); + glEnd(); + } } struct entity