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 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/render/render.cc | 7 ++++++- src/render/render.h | 1 + 3 files changed, 62 insertions(+), 4 deletions(-) (limited to 'src/render') 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(); + } } } diff --git a/src/render/render.cc b/src/render/render.cc index e602673..87ff64a 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -13,6 +13,7 @@ #include "render/textures.h" #include "render/tga.h" #include "render/render.h" +#include "model/model.h" #include "core/core.h" #include "filesystem/filesystem.h" @@ -24,7 +25,8 @@ GLuint textures[32]; core::Cvar *r_radius = 0; core::Cvar *r_wireframe = 0; -core::Cvar * r_arraysize = 0; +core::Cvar *r_arraysize = 0; +core::Cvar *r_bbox = 0; using model::VertexArray; @@ -80,6 +82,9 @@ void init() r_wireframe = core::Cvar::get("r_wireframe", "0", core::Cvar::Archive); r_wireframe->set_info("[bool] render wireframe"); + r_bbox = core::Cvar::get("r_bbox", "0", core::Cvar::Archive); + r_bbox->set_info("[bool] render model bounding box"); + Textures::init(); Text::init(); diff --git a/src/render/render.h b/src/render/render.h index d1f79a7..68952f1 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -23,6 +23,7 @@ namespace render { /// shutdown the render subsystem void shutdown(); + extern core::Cvar *r_bbox; extern core::Cvar *r_radius; extern core::Cvar *r_wireframe; extern core::Cvar *r_arraysize; -- cgit v1.2.3