al_orthographic_transform(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ al_orthographic_transform(3alleg5) ✨

okay bestie, welcome to the Allegro 5 API page for al_orthographic_transform, section 3alleg5 πŸ’– this one is short but it's highkey important, so grab your matcha and let's go πŸ“


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

void al_orthographic_transform(ALLEGRO_TRANSFORM *trans,
   float left, float top, float n,
   float right, float bottom, float f)

πŸ¦‹ DESCRIPTION πŸ¦‹

So what this does is it takes the transformation you hand it and combines it with an orthographic transformation β€” one that maps the screen rectangle onto the left/top and right/bottom coordinates you gave it. Slay πŸ’…

n/f is the z range, and here's the tea: anything outside that range gets clipped. Normally -1/1 is totally fine, because all your 2D graphics are gonna have a z coordinate of 0 anyway. No thoughts, head empty, z = 0 ✨

BUT β€” and this is the part where you need to pay attention, bestie β€” if you for example do al_draw_rectangle(0, 0, 100, 100) and then rotate around the x axis (aka "towards the screen"), you gotta make sure your z range allows values from -100 to 100, or that rotated rectangle is gonna get clipped. 😭 Don't let it happen to you.

Also, if you're using a depth buffer, the z range is literally what decides your depth resolution. Example time: if you have a 16 bit depth buffer, there are only 65536 discrete depth values. So if your near/far is set to -1000000/1000000, most of the z positions wouldn't result in separate depth values, which could lead to artifacts. It's giving cursed render ngl πŸ’€

The result of applying this transformation to coordinates is that your visible coordinates get normalized into the cube from -1/-1/-1 to 1/1/1. Such a transformation is mostly useful for passing it to al_use_projection_transform(3alleg5) β€” go check that function for an example use, iykyk πŸ‘‘

lowkey a whole vibe, but also: get your z range right or your pretty shapes get chopped. that's the warning, fr fr πŸ™ˆ

⭐ SINCE ⭐

5.1.3


🫢 SEE ALSO 🫢


and that's the whole page, bestie! πŸŽ€ this came straight out of the Allegro reference manual β€” al_orthographic_transform(3alleg5) β€” so if you cite it, that's who to thank. go forth and project responsibly πŸ’œπŸŒˆ

πŸ“¦ where this page comes from