aboutsummaryrefslogtreecommitdiff
path: root/src/render.c
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-28 22:36:26 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-28 22:36:26 +0000
commit0013c4e06b805e07359188cb0bd06ffb9e33dd8f (patch)
treebb98a41681e21e6cc8c8e5c9b056876eb8608070 /src/render.c
parent68e8e73c5a795ac0530bed547b2249333fdd7146 (diff)
Reflection stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@51 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/render.c')
-rw-r--r--src/render.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/render.c b/src/render.c
index 2f4d05c..6d86ac3 100644
--- a/src/render.c
+++ b/src/render.c
@@ -129,6 +129,8 @@ static void render_delete_shaders(RenderContext *r) {
r->hemisphere_n[3*i + 0] = xv; \
r->hemisphere_n[3*i + 1] = yv; \
r->hemisphere_n[3*i + 2] = zv; \
+ r->hemisphere_t[2*i + 0] = tx; \
+ r->hemisphere_t[2*i + 1] = ty; \
i++;
/* OpenGL initial setup */
@@ -164,12 +166,12 @@ RenderContext *render_setup(int width, int height) {
glBindTexture(GL_TEXTURE_2D, r->fbotex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r->fbotex, 0);
/* Add a depth buffer to the FBO */
glGenRenderbuffersEXT(1, &r->fbodepth);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, r->fbodepth);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, 256, 256);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, 128, 128);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, r->fbodepth);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, r->fbodepth);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
@@ -182,13 +184,14 @@ RenderContext *render_setup(int width, int height) {
glBindTexture(GL_TEXTURE_2D, r->swirly_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, r->swirly_texture, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
/* Create coordinates for a hemisphere to reuse later */
r->hemisphere_v = malloc(3*HEMI_NUM_VERTICES*sizeof(GLfloat));
r->hemisphere_n = malloc(3*HEMI_NUM_VERTICES*sizeof(GLfloat));
+ r->hemisphere_t = malloc(2*HEMI_NUM_VERTICES*sizeof(GLfloat));
double step_up = M_PI_2/(double)HEMI_UP_BITS;
double step_round = 2*M_PI/(double)HEMI_ROUND_BITS;
int is, js;
@@ -197,23 +200,32 @@ RenderContext *render_setup(int width, int height) {
for ( js=0; js<HEMI_UP_BITS; js++ ) {
double theta, phi;
GLfloat xv, yv, zv;
+ GLfloat tx, ty;
theta = (2*M_PI/(double)HEMI_ROUND_BITS) * (double)is;
phi = (M_PI_2/(double)HEMI_UP_BITS) * (double)js;
xv = cos(theta)*cos(phi);
yv = sin(theta)*cos(phi);
zv = sin(phi);
+ tx = 0.5 + 0.5*tan(phi)*cos(theta);
+ ty = 0.5 + 0.5*tan(phi)*sin(theta);
ADD_VERTEX
xv = cos(theta+step_round)*cos(phi);
yv = sin(theta+step_round)*cos(phi);
zv = sin(phi);
+ tx = 0.5 + 0.5*tan(phi)*cos(theta+step_round);
+ ty = 0.5 + 0.5*tan(phi)*sin(theta+step_round);
ADD_VERTEX
xv = cos(theta+step_round)*cos(phi+step_up);
yv = sin(theta+step_round)*cos(phi+step_up);
zv = sin(phi+step_up);
+ tx = 0.5 + 0.5*tan(phi+step_round)*cos(theta+step_round);
+ ty = 0.5 + 0.5*tan(phi+step_round)*sin(theta+step_round);
ADD_VERTEX
xv = cos(theta)*cos(phi+step_up);
yv = sin(theta)*cos(phi+step_up);
zv = sin(phi+step_up);
+ tx = 0.5 + 0.5*tan(phi+step_up)*cos(theta);
+ ty = 0.5 + 0.5*tan(phi+step_up)*sin(theta);
ADD_VERTEX
}
}
@@ -318,13 +330,10 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
glBindBufferARB(GL_ARRAY_BUFFER, p->vertices_buffer);
glVertexPointer(3, GL_FLOAT, 0, NULL);
- //glVertexPointer(3, GL_FLOAT, 0, p->vertices);
glBindBufferARB(GL_ARRAY_BUFFER, p->normals_buffer);
glNormalPointer(GL_FLOAT, 0, NULL);
- //glNormalPointer(GL_FLOAT, 0, p->normals);
glBindBufferARB(GL_ARRAY_BUFFER, p->texcoords_buffer);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
- //glTexCoordPointer(2, GL_FLOAT, 0, p->texcoords);
glDrawArrays(render_gltype(p->type), 0, p->num_vertices);
*nvert += p->num_vertices;
glBindBufferARB(GL_ARRAY_BUFFER, 0);
@@ -348,25 +357,20 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
glVertexPointer(3, GL_FLOAT, 0, r->hemisphere_v);
glNormalPointer(GL_FLOAT, 0, r->hemisphere_n);
-
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+ glTexCoordPointer(2, GL_FLOAT, 0, r->hemisphere_t);
glBindTexture(GL_TEXTURE_2D, r->fbotex);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_enabled"), 0);
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_enabled"), 1);
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_emits"), 1);
glDrawArrays(GL_QUADS, 0, HEMI_NUM_VERTICES);
*nvert += HEMI_NUM_VERTICES;
+ glUniform1iARB(glGetUniformLocationARB(r->lighting_program, "texture_emits"), 0);
glDisable(GL_TEXTURE_2D);
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
-
glDisable(GL_RESCALE_NORMAL);
glPopMatrix();
@@ -586,29 +590,27 @@ void render_draw(Game *game, Uint32 t) {
r = game->render;
-#if 0
/* First pass: Looking upwards */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, r->fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 256, 256);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(70.0, 1.0, 0.1, 180.0);
+ gluPerspective(70.0, 1.0, 0.1, 80.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(game->lander->x, game->lander->y, game->lander->z,
game->lander->x, game->lander->y, game->lander->z+10.0,
sqrtf(2.0)*sinf(game->lander->yaw), sqrtf(2.0)*cosf(game->lander->yaw), 0.0);
render_setup_lighting(game);
- GLfloat amb[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat amb[] = { 0.1, 0.1, 0.1, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
render_draw_stuff(game, t);
-#endif
-
+
/* Render some swirlyness */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, r->swirly_fbo);
glClear(GL_COLOR_BUFFER_BIT);
- glViewport(0, 0, 256, 256);
+ glViewport(0, 0, 128, 128);
glUseProgramObjectARB(r->swirly_program);
glUniform1fARB(glGetUniformLocationARB(game->render->swirly_program, "time"), t);
glMatrixMode(GL_PROJECTION);
@@ -656,6 +658,7 @@ void render_draw(Game *game, Uint32 t) {
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
render_model_instance_draw(game->lander, t, r, NULL);
glPopClientAttrib();
glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "texture_enabled"), 0);