Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-02-13 21:47:48 +0000
committerStijn Buys <ingar@osirion.org>2012-02-13 21:47:48 +0000
commit81922a29eaff6f7183a728d16906eca26caf885a (patch)
treea1ff32a5928d8bbd14a8c199b20886594c447bf5 /src/render
parent130a23f483fe2e486e6d9d804b9d998c159fbcb0 (diff)
Rearranged render::draw_pas_globes(), removed render::draw_globe(), added render::draw_globe_corona().
Diffstat (limited to 'src/render')
-rw-r--r--src/render/draw.cc166
-rw-r--r--src/render/draw.h3
2 files changed, 87 insertions, 82 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index de08d1d..2efa411 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -260,45 +260,11 @@ void draw_sphere(math::Color const & color, float radius)
}
}
-void draw_globe(const core::EntityGlobe* globe)
+void draw_globe_corona(const math::Vector3f location, const math::Color & color, const float radius, const size_t corona_id)
{
- /*
- Globes have to be rendered distance sorted, closest last.
- Globes behind farplane are rescaled and repositioned.
- */
- math::Vector3f location(globe->location());
- float radius = globe->radius();
-
- GLfloat globe_specular[] = { 0.25f, 0.25f, 0.25f, 1.0f };
- glMaterialfv(GL_FRONT, GL_SPECULAR, globe_specular);
-
- if (globe->flag_is_set(core::Entity::Bright)) {
- // bright globe, render fullbright
- gl::disable(GL_LIGHTING);
- }
-
- if (ext_render(globe)->distance() > (FARPLANE - globe->radius())) {
- // globe is behind the far plane, make a fake size calculation
- location = Camera::eye() + (location - Camera::eye()) * ((FARPLANE - globe->radius()) / ext_render(globe)->distance());
- radius *= (FARPLANE - globe->radius()) / (ext_render(globe)->distance());
-
- gl::depthmask(GL_FALSE);
-
- if (has_zone_light) {
- // move zone light
- float fake_light[4];
- for (size_t i = 0; i < 3; i++) {
- fake_light[i] = zone_light[i] + location[i] - globe->location()[i];
- }
- fake_light[3] = 1.0f;
- glLightfv(zone_gllight, GL_POSITION, fake_light);
- }
- }
-
// draw the globe's corona
- if (globe->flag_is_set(core::Entity::Bright) && globe->corona_id()) {
-
- math::Vector3f v = globe->location() - Camera::eye();
+ if (corona_id) {
+ math::Vector3f v = location - Camera::eye();
v.normalize();
float a = dotproduct(v, Camera::axis().forward());
if (a > 0.1f) {
@@ -306,22 +272,22 @@ void draw_globe(const core::EntityGlobe* globe)
gl::disable(GL_DEPTH_TEST);
gl::enable(GL_TEXTURE_2D);
- Textures::bind(globe->corona_id());
+ Textures::bind(corona_id);
- math::Color color(globe->color());
- color.a = a - 0.1f;
+ math::Color drawcolor(color);
+ drawcolor.a = a - 0.1f;
- gl::color(color);
+ gl::color(drawcolor);
gl::begin(gl::Quads);
glTexCoord2f(0, 1);
- gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
+ gl::vertex((Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
glTexCoord2f(0, 0);
- gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * radius * 4.0f);
+ gl::vertex((Camera::axis().up() + Camera::axis().left()) * radius * 4.0f);
glTexCoord2f(1, 0);
- gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * radius * 4.0f);
+ gl::vertex((Camera::axis().up() * -1 + Camera::axis().left()) * radius * 4.0f);
glTexCoord2f(1, 1);
- gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
+ gl::vertex((Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
gl::end();
Stats::quads++;
@@ -330,51 +296,87 @@ void draw_globe(const core::EntityGlobe* globe)
gl::enable(GL_DEPTH_TEST);
gl::disable(GL_BLEND);
}
- }
-
- if (globe->texture_id()) {
- // textured globe
- Textures::bind(globe->texture_id());
- gl::enable(GL_TEXTURE_2D);
- }
-
- // draw the globe and apply rotation if required
- gl::push();
- gl::translate(location);
- gl::multmatrix(globe->axis());
-
- if (globe->rotationspeed()) {
- float angle = math::degrees360f(core::application()->time() * globe->rotationspeed());
- gl::rotate(angle, math::Vector3f::Zaxis());
- }
+ }
+}
- draw_sphere(globe->color(), radius);
- gl::pop();
+void draw_pass_globes()
+{
+ // FIXME is this ever reset ?
+ GLfloat globe_specular[] = { 0.25f, 0.25f, 0.25f, 1.0f };
+ glMaterialfv(GL_FRONT, GL_SPECULAR, globe_specular);
- if (ext_render(globe)->distance() > (FARPLANE - globe->radius())) {
+ // Globes have to be rendered distance sorted, closest last.
+ // Globes behind farplane are rescaled and repositioned.
+ for (Globes::reverse_iterator rit = globes_list.rbegin(); rit != globes_list.rend(); rit++) {
+ const core::EntityGlobe *globe = (*rit).second;
+
+ math::Vector3f location(globe->location());
+ float radius = globe->radius();
+
+ if (ext_render(globe)->distance() > (FARPLANE - globe->radius())) {
+ // globe is behind the far plane, make a fake size calculation
+ location = Camera::eye() + (location - Camera::eye()) * ((FARPLANE - globe->radius()) / ext_render(globe)->distance());
+ radius *= (FARPLANE - globe->radius()) / (ext_render(globe)->distance());
- gl::depthmask(GL_TRUE);
+ gl::depthmask(GL_FALSE);
- if (has_zone_light) {
- // restore zone light
- glLightfv(zone_gllight, GL_POSITION, zone_light);
+ if (has_zone_light) {
+ // move zone light
+ float fake_light[4];
+ for (size_t i = 0; i < 3; i++) {
+ fake_light[i] = zone_light[i] + location[i] - globe->location()[i];
+ }
+ fake_light[3] = 1.0f;
+ glLightfv(zone_gllight, GL_POSITION, fake_light);
+ }
}
- }
+
+ gl::push();
+ gl::translate(location);
+
+ if (globe->flag_is_set(core::Entity::Bright)) {
+ gl::disable(GL_LIGHTING);
+ if (globe->corona_id()) {
+ // draw globe corona
+ // corona is rendered in camera space
+ draw_globe_corona(location, globe->color(), radius, globe->corona_id());
+ }
+ }
+
+ if (globe->texture_id()) {
+ // textured globe
+ Textures::bind(globe->texture_id());
+ gl::enable(GL_TEXTURE_2D);
+ }
+
+ gl::multmatrix(globe->axis());
+
+ if (globe->rotationspeed()) {
+ float angle = math::degrees360f(core::application()->time() * globe->rotationspeed());
+ gl::rotate(angle, math::Vector3f::Zaxis());
+ }
+
+ draw_sphere(globe->color(), radius);
- if (globe->flag_is_set(core::Entity::Bright)) {
- gl::enable(GL_LIGHTING);
- }
+ gl::pop();
+
+ if (globe->texture_id()) {
+ gl::disable(GL_TEXTURE_2D);
+ }
+
+ if (globe->flag_is_set(core::Entity::Bright)) {
+ gl::enable(GL_LIGHTING);
+ }
+
+ if (ext_render(globe)->distance() > (FARPLANE - globe->radius())) {
- if (globe->texture_id()) {
- gl::disable(GL_TEXTURE_2D);
- }
-}
+ gl::depthmask(GL_TRUE);
-void draw_pass_globes()
-{
- // draw globes first, closest last
- for (Globes::reverse_iterator rit = globes_list.rbegin(); rit != globes_list.rend(); rit++) {
- draw_globe((*rit).second);
+ if (has_zone_light) {
+ // restore zone light
+ glLightfv(zone_gllight, GL_POSITION, zone_light);
+ }
+ }
}
}
diff --git a/src/render/draw.h b/src/render/draw.h
index 4a758b1..bc02bf5 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -29,6 +29,9 @@ void reset();
/// draw a sphere
void draw_sphere(math::Color const & color, float radius);
+/// draw a corona
+void draw_globe_corona(const math::Vector3f location, const math::Color & color, const float radius, const size_t corona_id);
+
/// draw mode lights and flares
void draw_model_lights(model::Model *model, const float scale,
const math::Vector3f & entity_location, const math::Axis & entity_axis,