1
\$\begingroup\$

I'm trying to render a "skybox" using Allegro 5, that 3D objects can move around "in front" of. I'm having trouble figuring out how to set up the projection transform and where to put the vertices for the quads that will have the background texture applied.

The plan is to use an orthographic transform the size of the skybox textures to place the quads, and only use rotation for the camera. Once the skybox is placed the depth buffer bit will be cleared and other objects perspective-transformed from their respective world-coordinates as normal.

The orthograpic transform API has the form

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

while the struct which holds the vertex data the transform will be applied to has the form

Fields:

x, y, z - Position of the vertex
color - ALLEGRO_COLOR structure, storing the color of the vertex
u, v - Texture coordinates measured in pixels

If my skybox textures have pixel widths and heights of say w and h, the same for all 6 sides, how should the vertices be created and transforms applied using the API to render it properly?

\$\endgroup\$
2
\$\begingroup\$

I've programmed with Allegro 4 and 5, but never done 3D with it. That said, I have done OpenGL with just plain Winmain and GLUT and it is all pretty much the same. All a skybox is, is a cube, each side has a 90 degree FOV (field of view), totaling 360 for all four north, south, east and west views, plus the top and bottom texture, which is also a 90 degree FOV. You basically just create a normal textured cube, except you reverse the winding to clockwise so the front face of each side faces inward, instead of out. When you render the skybox, you disable lighting and just give it a plain white colour. You can disable the depth buffer, fog etc... when drawing it. Also don't forget to clamp the texture edges so they are seamless. Then it's just a matter of rotating it, the center of the cube being the player's position. You do not translate it (move it) at all.

It's really not difficult at all to do. If you can create a textured cube, you can make a skybox.

Note: there are newer ways to do Skybox's with modern OpenGL and more optimal ways to render it with depth testing turned on believe it or not. There's some more modern information on how to do cubemaps and skyboxes at the following URL which could be coupled with Allegro or any other framework you use.

https://learnopengl.com/#!Advanced-OpenGL/Cubemaps

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.