From 36e52bc178b2ba25ecc1b3fc13e03f2aee1e8efa Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 25 May 2008 15:06:09 +0000 Subject: planet updates --- src/render/draw.cc | 155 ++++++++++++++++++----------------------------------- 1 file changed, 53 insertions(+), 102 deletions(-) (limited to 'src/render') diff --git a/src/render/draw.cc b/src/render/draw.cc index 4295330..f84abe7 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -58,10 +58,10 @@ void draw_sphere(math::Color const & color, float radius) gl::color(color); size_t index = 0; - size_t count = (model::SPHERESEGMENTS+1)*2; + size_t count = (model::SPHERESEGMENTS)*2; // draw body - for (int j=0; j < model::SPHERESEGMENTS-1; j++) { + for (int j=0; j < (model::SPHERESEGMENTS-1)/2; j++) { glDrawArrays(gl::QuadStrip, index, count); index += count; Stats::quads += count/2-1; @@ -72,11 +72,23 @@ void draw_sphere(math::Color const & color, float radius) void draw_entity_sphere(core::Entity *entity) { - if (entity->type() == core::Entity::Globe) { - gl::disable(GL_LIGHT0); + if ((entity->type() == core::Entity::Globe) && !flag_is_set(entity->flags(), core::Entity::Bright)) { + gl::disable(GL_LIGHT0); // disable camera light, level light only + + core::EntityGlobe *globe = (core::EntityGlobe *)entity; + if (globe->render_texture) { + Textures::bind(globe->render_texture); + gl::enable(GL_TEXTURE_2D); + } } + draw_sphere(entity->color(), entity->radius()); - if (entity->type() == core::Entity::Globe) { + + if ((entity->type() == core::Entity::Globe) && !flag_is_set(entity->flags(), core::Entity::Bright)) { + core::EntityGlobe *globe = (core::EntityGlobe *)entity; + if (globe->render_texture) { + gl::disable(GL_TEXTURE_2D); + } gl::enable(GL_LIGHT0); } } @@ -197,61 +209,6 @@ void draw_model_evertex(core::Entity *entity) } } -/* -void draw_model_engines(core::EntityControlable *entity) -{ - model::Model *model = entity->model(); - - if (model->model_engine.size() && entity->thrust()) { - gl::color(1.0f, 0.0f ,0.0f, 1.0f); - gl::begin(gl::Lines); - - for (std::list::iterator eit = model->model_engine.begin(); eit != model->model_engine.end(); eit++) { - math::Vector3f const & v = (*eit)->location(); - gl::vertex(v); - gl::vertex(v.x - 0.0625f*entity->thrust(), v.y, v.z); - } - gl::end(); - } - -} - -void draw_model_shield(core::EntityControlable *entity) -{ - // shield rotation - //gl::push(); - gl::rotate(angle, 0.0f, 0.0f, 1.0f ); - gl::scale(entity->model()->radius(), entity->model()->radius(), entity->model()->radius()); - - // draw the shield - gl::color(math::Color(0.0f, 1.0f ,0.0f)); - - gl::begin(gl::LineLoop); -// gl::normal(0, 0.5, 0.5); - gl::vertex(v1); -// gl::normal(0, -0.5, 0.5); - gl::vertex(v0); -// gl::normal(0, -0.5, -0.5); - gl::vertex(v4); -// gl::normal(0, 0.5, -0.5); - gl::vertex(v5); - gl::end(); - - gl::begin(gl::LineLoop); -// gl::normal(0, -0.5, 0.5); - gl::vertex(v3); -// gl::normal(0, 0.5, 0.5); - gl::vertex(v2); -// gl::normal(0, 0.5, -0.5); - gl::vertex(v6); -// gl::normal(0, -0.5, -0.5); - gl::vertex(v7); - - gl::end(); - - //gl::pop(); -} -*/ /* ----- Render passes --------------------------------------------- */ @@ -277,6 +234,7 @@ void pass_prepare(float seconds) model::Light *light = (*lit); // load flare texture + // FIXME optimize std::stringstream flarename; flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare(); light->render_texture = Textures::load(flarename.str()); @@ -308,26 +266,39 @@ void pass_prepare(float seconds) } } else { - if ((entity->type() == core::Entity::Globe) && flag_is_set(entity->flags(), core::Entity::Bright)) { + if (entity->type() == core::Entity::Globe) { + core::EntityGlobe *globe = (core::EntityGlobe *) entity; - // bright globes set level light - GLfloat light_position[4]; - 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 }; + if (flag_is_set(globe->flags(), core::Entity::Bright)) { - for (size_t i=0; i <3; i++) { - light_position[i] = entity->location()[i]; - diffuse_light[i] = entity->color()[i] * 0.4; + // bright globes set level light + GLfloat light_position[4]; + 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] = globe->location()[i]; + diffuse_light[i] = globe->color()[i] * 0.4; + } + light_position[3] = 1.0f; + 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); + } else { + + // load globe textures + // FIXME optimize + if (globe->texture().size()) { + std::stringstream texname; + texname << "textures/" << globe->texture(); + globe->render_texture = Textures::load(texname.str()); + } } - light_position[3] = 1.0f; - 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); } } @@ -374,7 +345,9 @@ 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()); @@ -456,31 +429,6 @@ void draw_pass_model_evertex() } } -/* Draw model shields */ -/* -void draw_pass_model_shields() { - - for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { - - core::Entity *entity = (*it).second; - - if (entity->model() && entity->state()->detailvisible()) { - - - if (entity->type() == core::Entity::Controlable) { - gl::push(); - gl::translate(entity->state()->location()); - gl::multmatrix(entity->state()->axis()); - - draw_model_shield((core::EntityControlable *)entity); - gl::pop(); - } - - } - } -} -*/ - /* draw model lights and engines */ void draw_pass_model_fx() { @@ -667,10 +615,12 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons 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()); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (r_wireframe && r_wireframe->value()) { glPolygonMode(GL_FRONT, GL_LINE); @@ -703,6 +653,7 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); gl::disable(GL_RESCALE_NORMAL); gl::disable(GL_LIGHTING); -- cgit v1.2.3