From a010f94390422eefa366a5f390c1f9e3ccc66fd5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 24 May 2008 10:10:37 +0000 Subject: text_length functions, improved lighting, r_bbox draws bounding boxes --- src/render/draw.cc | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index 9292460..8db77c1 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -235,6 +235,9 @@ void draw_model_shield(core::EntityControlable *entity) /* calculate entity visibility */ void pass_prepare(float seconds) { + // reset light state + gl::disable(GL_LIGHT1); + std::map::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -286,11 +289,22 @@ void pass_prepare(float seconds) // bright globes set level light GLfloat light_position[4]; - for (size_t i=0; i <3; i++) + GLfloat diffuse_light[4]; + GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + + for (size_t i=0; i <3; i++) { light_position[i] = entity->location()[i]; + diffuse_light[i] = entity->color()[i] * 0.4; + } light_position[3] = 1.0f; - - glLightfv(GL_LIGHT0, GL_POSITION, light_position); + diffuse_light[3] = 1.0f; + + glLightfv(GL_LIGHT1, GL_POSITION, light_position); + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light); + glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light); + gl::enable(GL_LIGHT1); } } @@ -337,6 +351,44 @@ void draw_pass_default() } gl::pop(); + } else if (r_bbox->value()) { + // draw bounding box if requested + model::Model *model = entity->model(); + gl::color(entity->color()); + + gl::push(); + gl::translate(entity->state()->location()); + gl::multmatrix(entity->state()->axis()); + + // top + gl::begin(gl::LineLoop); + gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_maxbbox.z); + gl::end(); + + // bottom + gl::begin(gl::LineLoop); + gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_minbbox.z); + gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_minbbox.z); + gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_minbbox.z); + gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_minbbox.z); + gl::end(); + + gl::begin(gl::Lines); + gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_minbbox.z); + gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_minbbox.x, model->model_maxbbox.y, model->model_minbbox.z); + gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_minbbox.z); + gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_maxbbox.z); + gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_minbbox.z); + gl::end(); + + gl::pop(); + } } } -- cgit v1.2.3