summaryrefslogtreecommitdiffstats
path: root/src/video/skybox.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/video/skybox.c')
-rw-r--r--src/video/skybox.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/video/skybox.c b/src/video/skybox.c
new file mode 100644
index 0000000..ee01f38
--- /dev/null
+++ b/src/video/skybox.c
@@ -0,0 +1,62 @@
+#include "video/video.h"
+
+void enableSkyboxTexture(void) {
+ glEnable(GL_TEXTURE_2D);
+}
+
+void disableSkyboxTexture(void) {
+ glDisable(GL_TEXTURE_2D);
+}
+
+static void bindSkyboxTexture(int index) {
+ glBindTexture(GL_TEXTURE_2D, gScreen->textures[ TEX_SKYBOX + index ]);
+}
+
+void drawSkybox(int grid_size) {
+ /*
+ matrices are:
+ projection: perspective projection
+ modelview: identity
+ */
+
+ /* these are the values for y == up, x == front */
+ /*
+ float sides[6][4][3] = {
+ { { 1, -1, -1 }, { 1, -1, 1 }, { 1, 1, 1 }, { 1, 1, -1 } }, // front
+ { { 1, 1, -1 }, { 1, 1, 1 }, { -1, 1, 1 }, { -1, 1, -1 } }, // top
+ { { -1, -1, -1 }, { 1, -1, -1 }, { 1, 1, -1 }, { -1, 1, -1 } }, // left
+ { { 1, -1, 1 }, { -1, -1, 1 }, { -1, 1, 1 }, { 1, 1, 1 } }, // right
+ { { -1, -1, -1 }, { 1, -1, -1 }, { 1, -1, 1 }, { -1, -1, 1 } }, // bottom
+ { { -1, -1, 1 }, { -1, -1, -1 }, { -1, 1, -1 }, { -1, 1, a1 } } // back
+ };
+ */
+
+ /* these values are for z == up, x == front */
+ float sides[6][4][3] = {
+ { { 1, 1, -1 }, { 1, -1, -1 }, { 1, -1, 1 }, { 1, 1, 1 } }, /* front */
+ { { 1, 1, 1 }, { -1, 1, 1 }, { -1, -1, 1 }, { 1, -1, 1 } }, /* top */
+ { { -1, 1, -1 }, { 1, 1, -1 }, { 1, 1, 1 }, { -1, 1, 1 } }, /* left */
+ { { 1, -1, -1 }, { -1, -1, -1 }, { -1, -1, 1 }, { 1, -1, 1 } }, /* right */
+ { { -1, 1, -1 }, { -1, -1, -1 }, { 1, -1, -1 }, { 1, 1, -1 } }, /* bottom */
+ { { -1, -1, -1 }, { -1, 1, -1 }, { -1, 1, 1 }, { -1, -1, 1 } } /* back */
+ };
+
+ float uv[4][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
+ int i, j;
+ float d = grid_size * 3;
+
+ glEnable(GL_TEXTURE_2D);
+ glDepthMask(GL_FALSE);
+ glColor3f(1.0, 1.0, 1.0);
+ for(i = 0; i < 6; i++) {
+ bindSkyboxTexture(i);
+ glBegin(GL_QUADS);
+ for(j = 0; j < 4; j++) {
+ glTexCoord2fv( uv[j] );
+ glVertex3f( sides[i][j][0] * d, sides[i][j][1] * d, sides[i][j][2] * d );
+ }
+ glEnd();
+ }
+ glDisable(GL_TEXTURE_2D);
+ glDepthMask(GL_TRUE);
+}