
Building a skybox using orthographic transfom 
bitrex
Member #16,587
November 2016

Hi again folks, I didn't had a chance to work on my Allegro project for a while, but I'm back at it. I'm trying to construct a skybox that 3D objects can move around "in front" of by first rendering via an orthographic transform, and clearing the "depth bit." This works okay for a simple single background image if the camera isn't rotated, at least. I'm having trouble figuring out the math for where to put the vertices using ALLEGRO_VERTEX such that the al_orothographic_transform on the set followed by al_use_projection transform makes it display correctly. If I wish to make a box in orthographic mode and my skybox textures have widths and heights of w and h pixels respectively, with the camera located at the center, how should the coordinate math work out? 
SiegeLord
Member #7,827
October 2006

Check out the ex_camera example, it has a skybox. It uses a perspective transformation, but the principle should be the same. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."Ecclesiastes 1:18 
Edgar Reynaldo
Major Reynaldo
May 2007

Orthographic projection means that everything with the same width and height will display at the same size no matter how far away it is. So render it just larger than your screen. 
bitrex
Member #16,587
November 2016

Thanks, I checked out ex_camera.c but I didn't quite understand what's going on there  it looks like they're constructing the quad out of two triangles, while I'm trying to use al_draw_prim with an ALLEGRO_PRIM_TRIANGLE_FAN argument and feeding it a set vertexes. That is to say I have a set of six arrays of ALLEGRO_VERTEX vert[4] of the form: 1 {x1, y1, z1, bw, 0.0, {bkg}},
2 {x2, y2, z2, bw, bh, {bkg}},
3 {x3, y3, z3, 0.0, bh, {bkg}},
4 {x4, y4, z4, 0.0, 0.0, {bkg}}
where bw and bh are the textures width and heights, respectively, and bkg is the ALLEGRO_COLOR for the primitive. The I have an orthographic transform I have to feed some coordinates to: 2al_orthographic_transform(projection, dw/2, dh/2, something?, dw/2, dh/2, something?)
Where I guess I have to use the current window size for the dimensions, and something? for the near and far distances, relative to the camera at the center. I'm a hardware guy by trade and still very new at this, so if either of you have a chance and could "explain it to me like I'm eight" I'd really appreciate it. 
Edgar Reynaldo
Major Reynaldo
May 2007

If you're only using the orthographic transform for the skybox, it doesn't really matter what you use for the near and far clipping planes as long as your skybox is rendered between them and far is greater than near. 
