aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-16 00:16:57 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-16 00:16:57 +0000
commit0ff31a9a69e4b1bd781202b9cdcde8a9a7c4e7f5 (patch)
treeefdf84b75a320f3ed9a5ff40b8b4d6b19410843a
parent17a153e21767fcc7a67186dd7ef8cdd0a7e26ed2 (diff)
Revert postprocess stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@17 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--data/Makefile.am2
-rw-r--r--data/shaders/postprocess.frag19
-rw-r--r--src/render.c176
-rw-r--r--src/types.h9
4 files changed, 100 insertions, 106 deletions
diff --git a/data/Makefile.am b/data/Makefile.am
index d65bb52..beb1463 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,7 +3,7 @@ models_DATA = models/floor models/lander.obj models/randombox models/walle model
models/ceiling models/tiledfloor
shadersdir = $(datadir)/thrust3d/shaders
-shaders_DATA = shaders/lighting.vert shaders/lighting.frag shaders/postprocess.frag
+shaders_DATA = shaders/lighting.vert shaders/lighting.frag
texturesdir = $(datadir)/thrust3d/textures
textures_DATA = textures/floor1.png textures/tiledwall.png
diff --git a/data/shaders/postprocess.frag b/data/shaders/postprocess.frag
deleted file mode 100644
index c475ae9..0000000
--- a/data/shaders/postprocess.frag
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * postprocess.frag
- *
- * Display post-processing
- *
- * (c) 2007-2008 Thomas White <taw27@cam.ac.uk>
- *
- * thrust3d - a silly game
- *
- */
-
-uniform sampler2D texture;
-
-void main() {
-
- gl_FragColor = texture2D(texture, gl_TexCoord[0].st) * 0.9;
-
-}
-
diff --git a/src/render.c b/src/render.c
index ac79fc5..ed28be2 100644
--- a/src/render.c
+++ b/src/render.c
@@ -65,13 +65,6 @@ static void render_load_shaders(RenderContext *ctx) {
glAttachObjectARB(ctx->lighting_program, ctx->lighting_vert);
glAttachObjectARB(ctx->lighting_program, ctx->lighting_frag);
glLinkProgramARB(ctx->lighting_program);
-
- ctx->postprocess_frag = render_load_shader(DATADIR"/shaders/postprocess.frag", GL_FRAGMENT_SHADER_ARB);
- ctx->postprocess_program = glCreateProgramObjectARB();
- glAttachObjectARB(ctx->postprocess_program, ctx->postprocess_frag);
- glLinkProgramARB(ctx->postprocess_program);
-
- glUniform1iARB(glGetUniformLocationARB(ctx->postprocess_program, "texture"), 0);
}
@@ -83,10 +76,6 @@ static void render_delete_shaders(RenderContext *ctx) {
glDeleteObjectARB(ctx->lighting_frag);
glDeleteObjectARB(ctx->lighting_program);
- glDetachObjectARB(ctx->postprocess_program, ctx->postprocess_frag);
- glDeleteObjectARB(ctx->postprocess_frag);
- glDeleteObjectARB(ctx->postprocess_program);
-
}
/* OpenGL initial setup */
@@ -98,9 +87,11 @@ RenderContext *render_setup(width, height) {
if ( ctx == NULL ) return NULL;
glClearColor(0.0, 0.0, 0.0, 1.0);
- ctx->aspect = (GLfloat)width/(GLfloat)height;
- ctx->width = width;
- ctx->height = height;
+ glViewport(0, 0, width, height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(50.0, (GLfloat)width/(GLfloat)height, 0.1, 100.0); /* Depth buffer 10cm to 100m */
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
@@ -113,23 +104,9 @@ RenderContext *render_setup(width, height) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- /* Generate FBO */
- glGenFramebuffersEXT(1, &ctx->fbo);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ctx->fbo);
- /* Add a (texture) colour buffer to the FBO */
- glGenTextures(1, &ctx->fbotex);
- glBindTexture(GL_TEXTURE_2D, ctx->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, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, ctx->fbotex, 0);
- /* Add a depth buffer to the FBO */
- glGenRenderbuffersEXT(1, &ctx->fbodepth);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ctx->fbodepth);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, 1024, 1024);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, ctx->fbodepth);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, ctx->fbodepth);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
render_load_shaders(ctx);
@@ -215,6 +192,82 @@ static int render_model_instance_draw(ModelInstance *instance, Uint32 t, RenderC
}
+#if 0
+static void render_configure_light(int *ilightp, Light light, Room *room, Game *game) {
+
+ GLfloat x, y, z;
+ int ilight;
+
+ GLfloat pos[4];
+ GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
+
+ ilight = *ilightp;
+
+ x = room->rx - game->cur_room_x;
+ y = room->ry - game->cur_room_y;
+ z = room->rz - game->cur_room_z;
+ glPushMatrix();
+ glTranslatef(10.0*x, 10.0*y, 10.0*z);
+
+ pos[0] = light.x;
+ pos[1] = light.y;
+ pos[2] = light.z;
+ pos[3] = 1.0;
+
+ if ( ilight < GL_MAX_LIGHTS ) {
+ glLightfv(GL_LIGHT0+ilight, GL_POSITION, pos);
+ glLightfv(GL_LIGHT0+ilight, GL_DIFFUSE, diffuse);
+ glLightfv(GL_LIGHT0+ilight, GL_SPECULAR, specular);
+ glLightf(GL_LIGHT0+ilight, GL_LINEAR_ATTENUATION, 0.01);
+ glEnable(GL_LIGHT0+ilight);
+ ilight++;
+ }
+
+ glPopMatrix();
+
+ *ilightp = ilight;
+
+}
+
+static void render_setup_lighting(Game *game, Room *room_current) {
+
+ int i, ilight;
+ GLfloat ambient[4];
+
+ /* Start with a blackout */
+ for ( ilight=0; ilight<GL_MAX_LIGHTS; ilight++ ) {
+ glDisable(GL_LIGHT0+ilight);
+ }
+ ilight = 0;
+
+ /* Lights within this room */
+ for ( i=0; i<room_current->num_lights; i++ ) {
+ render_configure_light(&ilight, room_current->lights[i], room_current, game);
+ }
+
+ /* Lights in rooms connected to this one */
+ for ( i=0; i<room_current->num_connected; i++ ) {
+
+ Room *room;
+ int j;
+
+ room = game_find_room(game, room_current->connected[i].rx, room_current->connected[i].ry, room_current->connected[i].rz);
+ if ( room == NULL ) continue; /* Shouldn't happen... */
+
+ for ( j=0; j<room->num_lights; j++ ) {
+ render_configure_light(&ilight, room->lights[j], room, game);
+ }
+
+ }
+
+ ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3; ambient[3] = 1.0;
+ //ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 1.0; ambient[3] = 1.0;
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
+
+}
+#endif
+
static void render_draw_line(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2) {
GLfloat red[] = {1.0, 0.0, 0.0, 1.0};
@@ -236,9 +289,7 @@ void render_draw(Game *game) {
t = SDL_GetTicks();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(50.0, game->render->aspect, 0.1, 100.0); /* Depth buffer 10cm to 100m */
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -248,6 +299,13 @@ void render_draw(Game *game) {
game->lander->x, game->lander->y, game->lander->z,
sqrtf(2.0)*sinf(game->lander->yaw)*sinf(game->view_angle),
sqrtf(2.0)*cosf(game->lander->yaw)*sinf(game->view_angle), sqrtf(2.0)*cosf(game->view_angle));
+ //gluLookAt(game->lander->x-(1.5*sinf(game->lander->yaw)),
+ // game->lander->y-(1.5*cosf(game->lander->yaw)), 1.5+game->lander->z,
+ // game->lander->x, game->lander->y, game->lander->z,
+ // sqrt(2.0)*sinf(game->lander->yaw), sqrtf(2.0)*cosf(game->lander->yaw), sqrtf(2.0));
+ //gluLookAt(0.0, -250.0, -495.0+250.0,
+ // 0.0, 0.0, -495.0,
+ // 0.0, sqrtf(2.0), sqrtf(2.0));
GLfloat pos[] = {-1.0, -0.8, 1.3, 0.0};
GLfloat ambient[4];
@@ -260,17 +318,9 @@ void render_draw(Game *game) {
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glEnable(GL_LIGHT0);
- /* Render to FBO */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, game->render->fbo);
- glViewport(0, 0, 1024, 1024);
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-// glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "texture"), 0);
-// glUseProgramObjectARB(game->render->lighting_program);
- glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ /* Draw the objects */
+ //glUniform1iARB(glGetUniformLocationARB(game->render->lighting_program, "texture"), 0);
+ //glUseProgramObjectARB(game->render->lighting_program);
for ( i=0; i<game->num_rooms; i++ ) {
Room *room;
@@ -279,6 +329,8 @@ void render_draw(Game *game) {
room = game->rooms[i];
if ( room == NULL ) return;
+ //render_setup_lighting(game, room);
+
for ( j=0; j<room->num_objects; j++ ) {
GLfloat x, y, z;
if ( room->objects[j] == NULL ) continue;
@@ -295,42 +347,12 @@ void render_draw(Game *game) {
/* Finally, the lander */
render_model_instance_draw(game->lander, t, game->render);
render_draw_line(game->lander->x, game->lander->y, game->lander->z, game->lander->x, game->lander->y, game->lander->z-200.0);
- glPopClientAttrib();
-// glUseProgramObjectARB(0);
+ //glUseProgramObjectARB(0);
- /* Final render to screen */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glViewport(0, 0, game->render->width, game->render->height);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -20.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-game->render->aspect*3.0, game->render->aspect*3.0, -3.0, 3.0, 0.001, 21.0);
- glDisable(GL_LIGHTING);
- glBindTexture(GL_TEXTURE_2D, game->render->fbotex);
- glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glEnable(GL_TEXTURE_2D);
- glColor3f(1.0, 1.0, 1.0);
-// glUseProgramObjectARB(game->render->postprocess_program);
- glBegin(GL_QUADS);
- glTexCoord2f(0.0, 0.0);
- glVertex3f(-3.0*game->render->aspect, -3.0*game->render->aspect, 0.0);
- glTexCoord2f(1.0, 0.0);
- glVertex3f(+3.0*game->render->aspect, -3.0*game->render->aspect, 0.0);
- glTexCoord2f(1.0, 1.0);
- glVertex3f(+3.0*game->render->aspect, +3.0*game->render->aspect, 0.0);
- glTexCoord2f(0.0, 1.0);
- glVertex3f(-3.0*game->render->aspect, +3.0*game->render->aspect, 0.0);
- glEnd();
-// glUseProgramObjectARB(0);
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_LIGHTING);
SDL_GL_SwapBuffers();
- /* Calculate FPS (every half a second) */
game->render->frames++;
+ /* Calculate FPS every half a second */
if ( t - game->render->t_fps > 500 ) {
game->render->fps = (500*game->render->frames) / (t - game->render->t_fps);
game->render->t_fps = t;
diff --git a/src/types.h b/src/types.h
index d072331..5c1ba53 100644
--- a/src/types.h
+++ b/src/types.h
@@ -101,8 +101,6 @@ typedef struct {
GLhandleARB lighting_vert;
GLhandleARB lighting_frag;
GLhandleARB lighting_program;
- GLhandleARB postprocess_frag;
- GLhandleARB postprocess_program;
/* Textures */
Texture textures[MAX_TEXTURES];
@@ -112,13 +110,6 @@ typedef struct {
Uint32 t_fps;
int fps;
- GLuint fbo;
- GLuint fbotex;
- GLuint fbodepth;
- GLfloat aspect;
- int width;
- int height;
-
} RenderContext;
typedef struct {