From f5266b403c50cb2b6d712e6d8f41b62ad2433efb Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 1 May 2008 12:41:31 +0000 Subject: lights --- src/render/draw.cc | 100 +++++++++++++++++++++++++++++++-------------------- src/render/draw.h | 2 +- src/render/render.cc | 5 +++ 3 files changed, 68 insertions(+), 39 deletions(-) (limited to 'src/render') diff --git a/src/render/draw.cc b/src/render/draw.cc index 4b42596..5697cae 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -36,6 +36,7 @@ const float drawfxdistance = 32.0f; math::Vector3f camera_target; math::Vector3f camera_eye; +math::Axis camera_axis; float angle = 0; @@ -181,27 +182,6 @@ void draw_model_evertex(core::Entity *entity) } } -void draw_model_lights(core::Entity *entity) -{ - core::Model *model = entity->model(); - - if (model->model_light.size()) { - glPointSize(10); - gl::begin(gl::Points); - - for (std::list::iterator lit = model->model_light.begin(); lit != model->model_light.end(); lit++) { - if (!(*lit)->strobe() || (( core::application()->time() - floorf(core::application()->time()) ) < 0.5f)) { - math::Vector3f location = (*lit)->location(); - gl::color((*lit)->color()); - gl::vertex(location); - } - } - - gl::end(); - glPointSize(1); - } -} - void draw_model_engines(core::EntityControlable *entity) { core::Model *model = entity->model(); @@ -364,7 +344,7 @@ void draw_pass_model_evertex() } } -/* Draw model lights, engines */ +/* Draw model shields and engines */ void draw_pass_model_fx() { for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -373,23 +353,68 @@ void draw_pass_model_fx() { if (test_drawfx_distance(entity)) { - gl::push(); - gl::translate(entity->location()); - // FIXME - //gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - gl::multmatrix(entity->axis()); - - draw_model_lights(entity); - + if (entity->type() == core::Entity::Controlable) { + gl::push(); + gl::translate(entity->location()); + gl::multmatrix(entity->axis()); + draw_model_engines((core::EntityControlable *)entity); draw_model_shield((core::EntityControlable *)entity); + gl::pop(); } - gl::pop(); + } } } +/* draw model lights */ + +void draw_pass_model_lights() +{ + //glPointSize(10); + glBindTexture(GL_TEXTURE_2D, render::textures[3]); // bitmaps/fx/flare01.tga + gl::enable(GL_TEXTURE_2D); + + gl::begin(gl::Quads); + + const float light_size = 0.0625; + + for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; + + if ( test_drawfx_distance(entity) && (entity->model()->model_light.size())) { + + for (std::list::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) { + if (!(*lit)->strobe() || (( core::application()->time() - floorf(core::application()->time()) ) < 0.5f)) { + math::Vector3f location = entity->location() + (entity->axis() * (*lit)->location()); + float n = dotproduct(camera_axis.forward(), (camera_eye-location)); + + if (n < 0) { + math::Color color((*lit)->color()); + color.a = fabs(-atanf(n) * 2 / M_PI); + gl::color(color); + + glTexCoord2f(0,1); + gl::vertex(location + (camera_axis.up() - camera_axis.left()) * light_size); + glTexCoord2f(0,0); + gl::vertex(location + (camera_axis.up() + camera_axis.left()) * light_size); + glTexCoord2f(-1,0); + gl::vertex(location + (camera_axis.up() * -1 + camera_axis.left()) * light_size); + glTexCoord2f(-1,1); + gl::vertex(location + (camera_axis.up() * -1 - camera_axis.left()) * light_size); + } + } + } + } + } + + gl::end(); + gl::disable(GL_TEXTURE_2D); + //glPointSize(1); + +} + void draw_pass_model_radius() { if (!(r_radius && r_radius->value())) @@ -485,7 +510,7 @@ void draw_local_axis() } /* ----- Main draw routine ----------------------------------------- */ -void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds) +void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f const &target, float seconds) { Stats::clear(); @@ -497,6 +522,7 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds camera_target.assign(target); camera_eye.assign(eye); + camera_axis.assign(axis); gl::enable(GL_DEPTH_TEST); // enable depth buffer writing gl::enable(GL_CULL_FACE); // enable culling @@ -533,7 +559,10 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::disable(GL_LIGHTING); gl::enable(GL_BLEND); - draw_pass_model_fx(); // draw entity lights and engines + draw_pass_spacegrid(); // draw the blue spacegrid + + draw_pass_model_fx(); // draw entity shield and engines + draw_pass_model_lights(); // draw entity lights gl::enable(GL_LIGHTING); gl::enable(GL_RESCALE_NORMAL); @@ -547,11 +576,6 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling - - // draw_local_axis(); - - draw_pass_spacegrid(); // draw the blue spacegrid - gl::disable(GL_DEPTH_TEST); // disable depth buffer // GL_BLEND must be enabled for the GUI diff --git a/src/render/draw.h b/src/render/draw.h index b423aad..65e15ee 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -13,7 +13,7 @@ namespace render { /// draw the world -void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds); +void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f const &target, float seconds); class Stats { public: diff --git a/src/render/render.cc b/src/render/render.cc index 7f79a85..6755e08 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -75,6 +75,11 @@ void init() core::application()->shutdown(); } + if (!texture("bitmaps/fx/flare01.tga", 3)) { + con_error << "Essential file bitmaps/fx/flare01.tga missing" << std::endl; + core::application()->shutdown(); + } + // size of the vertex array in megabytes r_arraysize = core::Cvar::get("r_arraysize", 0.0f , core::Cvar::Archive); r_arraysize->set_info("[int] size of the vertex array in Mb"); -- cgit v1.2.3