/* Draw a tile */ void draw_tile( int index ) { if ( index > get_tile_count() ) return; /* Enable textures */ glEnable( GL_TEXTURE_2D ); /* Bind the tilebay texture */ glBindTexture( GL_TEXTURE_2D, tilebay[index].gl_index ); /* Send the vertex/texture coordinates */ glBegin( GL_QUADS ); /* Top Left */ glTexCoord2f( 0.0f, 1.0f ); glVertex3f( 0.0f, 0.0f, 0.0f ); /* Top Right */ glTexCoord2f( 1.0f, 1.0f ); glVertex3f( TILE_SIZE, 0.0f, 0.0f ); /* Bottom Right */ glTexCoord2f( 1.0f, 0.0f ); glVertex3f( TILE_SIZE, TILE_SIZE, 0.0f ); /* Bottom Left */ glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, TILE_SIZE, 0.0f ); glEnd(); /* Disable textures */ glDisable( GL_TEXTURE_2D ); }
static void draw_camera(int i, int j, int f, float a) { struct camera *c = get_camera(i); init_camera(i); if (c->frame) { /* Apply a basic projection for offscreen rendering. */ glMatrixMode(GL_PROJECTION); { glPushMatrix(); glLoadIdentity(); if (c->type == CAMERA_ORTHO) glOrtho (c->l, c->r, c->b, c->t, c->n, c->f); else glFrustum(c->l, c->r, c->b, c->t, c->n, c->f); } glMatrixMode(GL_MODELVIEW); { glPushMatrix(); glLoadIdentity(); } /* Render the scene to the offscreen buffer. */ glPushAttrib(GL_VIEWPORT_BIT | GL_SCISSOR_BIT); { int w = get_image_w(c->image); int h = get_image_h(c->image); glViewport(0, 0, w, h); glScissor (0, 0, w, h); opengl_push_framebuffer(c->frame); { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_scene(j, f, a); } opengl_pop_framebuffer(); } glPopAttrib(); /* Revert the projection. */ glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } else { int eye; int tile; int pass; /* Iterate over all tiles of this host. */ for (tile = 0; tile < (int) get_tile_count(); ++tile) { float d[2][3]; /* Iterate over the eyes. */ get_eye_pos(d[0], c, 0, tile); get_eye_pos(d[1], c, 1, tile); for (eye = 0; eye < (c->mode ? 2 : 1); ++eye) { camera_eye = eye; if (draw_tile(c, eye, tile, d[eye])) { pass = 0; /* Iterate over all passes of this eye and tile. */ while ((pass = draw_pass(c->mode, eye, tile, pass, d))) { if (get_tile_flags(tile) & TILE_TEST_COLOR) draw_color(j, eye); else if (get_tile_flags(tile) & TILE_TEST_GHOST) draw_ghost(j, eye); else draw_scene(j, f, a); } } } } /* HACK */ if (c->mode != STEREO_VARRIER_00) opengl_set_fence(); } }