From 4ac9893545982f0de5c16e285a136118199a0a79 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 14 Jul 2008 13:20:39 +0000 Subject: better skysphere rendering --- src/render/camera.cc | 11 ------ src/render/camera.h | 3 ++ src/render/draw.cc | 99 ++++++++++++++++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/render/camera.cc b/src/render/camera.cc index 6c9a115..a55038d 100644 --- a/src/render/camera.cc +++ b/src/render/camera.cc @@ -302,18 +302,7 @@ void Camera::draw(float seconds) } } - // Change to the projection matrix and set our viewing volume. - gl::matrixmode(GL_PROJECTION); - gl::loadidentity(); - - const float frustum_size = 0.5f; - const float frustum_front = 1.0f; distance += frustum_front; - gl::frustum(-frustum_size*aspect(), frustum_size*aspect(), -frustum_size, frustum_size, frustum_front, 1024.0f); - - // model view - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); // map world coordinates to opengl coordinates gl::rotate(90.0f, 0, 1.0, 0); diff --git a/src/render/camera.h b/src/render/camera.h index 42bd835..52d2e13 100644 --- a/src/render/camera.h +++ b/src/render/camera.h @@ -11,6 +11,9 @@ namespace render { +const float frustum_size = 0.5f; +const float frustum_front = 1.0f; + /// camera functions class Camera { diff --git a/src/render/draw.cc b/src/render/draw.cc index 6aafcca..d1b06ea 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -412,25 +412,6 @@ void pass_prepare(float seconds) } } -/* Draw skybox */ -void draw_pass_skybox() -{ - - if (!(r_sky && r_sky->value())) - return; - - size_t flare_texture = Textures::load("textures/env/sky"); - Textures::bind(flare_texture); - - gl::enable(GL_TEXTURE_2D); - gl::push(); - - draw_sphere_inside(math::Color(), 512); - - gl::pop(); - gl::disable(GL_TEXTURE_2D); -} - /* Draw entities without model */ void draw_pass_default() { @@ -728,6 +709,26 @@ void draw_pass_model_corona() } + +/* Draw skysphere */ +void draw_pass_sky() +{ + if (!(r_sky && r_sky->value())) + return; + + size_t flare_texture = Textures::load("textures/env/sky"); + Textures::bind(flare_texture); + + gl::enable(GL_TEXTURE_2D); + gl::push(); + + gl::translate(Camera::eye()); + draw_sphere_inside(math::Color(), 16000); + + gl::pop(); + gl::disable(GL_TEXTURE_2D); +} + void draw_pass_spacegrid() { if (!(r_grid && r_grid->value())) @@ -778,50 +779,72 @@ void draw(float seconds) if( angle > 360.0f ) { angle -= 360.0f; } - + + // Change to the projection matrix and set our viewing volume large enough for the skysphere + gl::matrixmode(GL_PROJECTION); + gl::loadidentity(); + gl::frustum(-frustum_size*Camera::aspect(), frustum_size*Camera::aspect(), + -frustum_size, frustum_size, frustum_front, 16384.0f); + + gl::matrixmode(GL_MODELVIEW); + gl::loadidentity(); Camera::draw(seconds); // draw the current camera transformation + // calculate client state pass_prepare(seconds); - // enable vertex arrays + // enable wireframe mode if requested + if (r_wireframe && r_wireframe->value()) { + glPolygonMode(GL_FRONT, GL_LINE); + } else { + glPolygonMode(GL_FRONT, GL_FILL); + } + + // set vertex array pointers glVertexPointer(3, GL_FLOAT, 0, vertexarray->vertex()); glNormalPointer(GL_FLOAT, 0, vertexarray->normal()); glColorPointer(3, GL_FLOAT, 0, vertexarray->color()); glTexCoordPointer(3, GL_FLOAT, 0, vertexarray->texture()); + // enable vertex arrays glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); - draw_pass_skybox(); // draw the skybox - - gl::enable(GL_DEPTH_TEST); // enable depth buffer writing - gl::enable(GL_CULL_FACE); // enable culling - gl::enable(GL_COLOR_MATERIAL); // enable color tracking - gl::enable(GL_LIGHTING); - gl::disable(GL_BLEND); // disbable alpha blending for world polys + gl::disable(GL_BLEND); // disbable alpha blending gl::disable(GL_RESCALE_NORMAL); - if (r_wireframe && r_wireframe->value()) { - glPolygonMode(GL_FRONT, GL_LINE); - } else { - glPolygonMode(GL_FRONT, GL_FILL); - } - - draw_pass_model_vertex(); // draw entities with model + draw_pass_sky(); // draw the skysphere - glDisableClientState(GL_COLOR_ARRAY); + gl::enable(GL_DEPTH_TEST); // enable depth buffer writing + gl::enable(GL_CULL_FACE); // enable culling + gl::enable(GL_COLOR_MATERIAL); // enable color tracking + gl::enable(GL_LIGHTING); gl::enable(GL_RESCALE_NORMAL); // rescale normals by the transformation matrix scale factor draw_pass_default(); // draw entities without model gl::disable(GL_RESCALE_NORMAL); + // adjust the projection matrix for local world view + gl::matrixmode(GL_PROJECTION); + gl::loadidentity(); + gl::frustum(-frustum_size*Camera::aspect(), frustum_size*Camera::aspect(), + -frustum_size, frustum_size, frustum_front, 1024.0f); + gl::matrixmode(GL_MODELVIEW); + + glEnableClientState(GL_COLOR_ARRAY); + + draw_pass_model_vertex(); // draw entities with model + + glDisableClientState(GL_COLOR_ARRAY); + draw_pass_model_evertex(); // draw entities with model, vertices with entity color - gl::disable(GL_LIGHTING); gl::enable(GL_BLEND); + gl::disable(GL_LIGHTING); draw_pass_spacegrid(); // draw the blue spacegrid -- cgit v1.2.3