summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-11-07 02:12:46 -0800
committerKenneth Graunke <kenneth@whitecape.org>2010-11-17 15:09:43 -0800
commit047491df37025f1a783241c4014ccb5e34b22b74 (patch)
treec7be754f7d46a2a2afe1cc8f877cfd1a7d6a0c7e
parent0bdb979431167b11189f0ba1f4eb87c243e5fa4d (diff)
Load the cube texture at startup.
-rwxr-xr-xsrc/main.cpp35
-rwxr-xr-xsrc/phong.frag2
2 files changed, 37 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b3378a7..666c300 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -27,6 +27,7 @@
#include "bezier.h"
#include "patch_set.h"
+#include "texture_load.h"
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
#define ELEMENTS_OF(x) (sizeof(x) / sizeof(x[0]))
@@ -101,6 +102,9 @@ static GLuint prog;
static GLint mvp_location;
static GLint mv_location;
static GLint s_location;
+static GLint sampler_location;
+
+static GLuint cubemap;
static patch_set_info *object = NULL;
@@ -137,6 +141,7 @@ Redisplay(const patch_set_info *info)
glUniform1f(s_location, specular_exponent[i]);
glUniformMatrix4fv(mvp_location, 1, false, (float *) &mvp);
glUniformMatrix4fv(mv_location, 1, false, (float *) &mv);
+ glUniform1i(sampler_location, 0);
glMultiDrawElements(info->mode, info->count, info->type,
(const GLvoid**) info->indices,
@@ -262,6 +267,7 @@ load_and_compile_program_code(const char *shader)
mvp_location = glGetUniformLocation(prog, "mvp");
mv_location = glGetUniformLocation(prog, "mv");
s_location = glGetUniformLocation(prog, "s");
+ sampler_location = glGetUniformLocation(prog, "sampler");
} else {
glDeleteProgram(prog);
prog = 0;
@@ -362,6 +368,14 @@ make_curves_C1(const bezier_curve &s0, const bezier_curve &s1,
d1 = bezier_curve(s1[0], moved_point, s1[2], s1[3]);
}
+static void
+load_cube_face(GLenum side, const char *filename)
+{
+ if (!texture_image(side, 0, GL_RGB, filename, true)) {
+ printf("Failed to load cube texture `%s'\n", filename);
+ exit(1);
+ }
+}
static void
Init(void)
@@ -376,6 +390,27 @@ Init(void)
exit(1);
}
+ /* Load the cube map textures */
+ glGenTextures(1, &cubemap);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
+
+ glTexParameteri(GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glEnable(GL_TEXTURE_CUBE_MAP);
+
+ load_cube_face(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, "map/posx.jpg");
+ load_cube_face(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, "map/posy.jpg");
+ load_cube_face(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, "map/posz.jpg");
+ load_cube_face(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, "map/negx.jpg");
+ load_cube_face(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, "map/negy.jpg");
+ load_cube_face(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, "map/negz.jpg");
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
diff --git a/src/phong.frag b/src/phong.frag
index 0d53e85..a21f8fa 100755
--- a/src/phong.frag
+++ b/src/phong.frag
@@ -1,3 +1,5 @@
+uniform samplerCube sampler;
+
varying vec3 light_ss;
varying vec3 eye_ss;
varying vec2 uv_coord;