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>2008-03-24 12:35:48 +0000
committerStijn Buys <ingar@osirion.org>2008-03-24 12:35:48 +0000
commitb32c086a9b9deed4c34ade6e2447861a9c4bfc46 (patch)
treef3213a8f4b1ffd15df28aa6bd82b9fe6c1bb979d /src/render/draw.cc
parent80ad7e99b738f367eb045768d054cf74347ee1b4 (diff)
moved the sphere into the vertex array
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r--src/render/draw.cc87
1 files changed, 57 insertions, 30 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 590cddd..55f173c 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -8,22 +8,19 @@
#include "core/model.h"
#include "render/render.h"
#include "render/draw.h"
-#include "render/sphere.h"
namespace render
{
-size_t Stats::tris;
-size_t Stats::spheres;
+size_t Stats::tris = 0;
+size_t Stats::quads = 0;
void Stats::clear()
{
tris = 0;
- spheres = 0;
+ quads = 0;
}
-Sphere sphere(1);
-
math::Vector3f v0(1, -1, 1);
math::Vector3f v1(1, 1, 1);
math::Vector3f v2(-1, 1, 1);
@@ -42,12 +39,32 @@ float angle = 0;
/* ----- Default Entity shapes ------------------------------------- */
+void draw_sphere(math::Color const & color, float radius)
+{
+ //gl::push();
+ gl::scale(radius, radius, radius);
+ gl::color(color);
+
+ size_t index = 0;
+ size_t count = (core::SPHERESEGMENTS+1)*2;
+
+ // draw body
+ for (int j=0; j < core::SPHERESEGMENTS-1; j++) {
+ if (r_drawwireframe && r_drawwireframe->value()) {
+ glDrawArrays(gl::LineLoop, index, count);
+ } else {
+ glDrawArrays(gl::QuadStrip, index, count);
+ }
+ index += count;
+ Stats::quads += count/2-1;
+ }
+
+ //gl::pop();
+}
+
void draw_entity_sphere(core::Entity *entity)
{
- sphere.sphere_color = entity->color();
- sphere.radius = entity->radius();
- sphere.draw();
- Stats::spheres += 1;
+ draw_sphere(entity->color(), entity->radius());
}
void draw_entity_cube(core::Entity *entity)
@@ -198,16 +215,17 @@ void draw_model_engines(core::EntityControlable *entity)
void draw_model_radius(core::Entity *entity)
{
- sphere.sphere_color = entity->color();
- sphere.sphere_color.a = 0.25f;
- sphere.radius = entity->model()->radius();
- sphere.draw();
- Stats::spheres += 1;
+
+ math::Color color = entity->color();
+ color.a = 0.25f;
+
+ draw_sphere(color, entity->model()->radius());
}
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());
@@ -237,7 +255,7 @@ void draw_model_shield(core::EntityControlable *entity)
gl::end();
- gl::rotate(-angle, 0.0f, 0.0f, 1.0f );
+ //gl::pop();
}
/* ----- Render passes --------------------------------------------- */
@@ -266,14 +284,6 @@ void draw_pass_default()
for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
core::Entity *entity = (*it).second;
- // load entity models if necessary
- if (!entity->model() && entity->modelname().size()) {
- entity->entity_model = core::Model::get(entity->modelname());
-
- if (!entity->model())
- entity->entity_modelname.clear();
- }
-
// draw entities without model
if (!entity->model()) {
gl::push();
@@ -316,6 +326,15 @@ void draw_pass_model_vertex()
core::Entity *entity = (*it).second;
+ // load entity models if necessary
+ if (!entity->model() && entity->modelname().size()) {
+ entity->entity_model = core::Model::get(entity->modelname());
+
+ if (!entity->model())
+ entity->entity_modelname.clear();
+ }
+
+
if (test_draw_distance(entity)) {
gl::push();
gl::translate(entity->location());
@@ -448,8 +467,7 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
gl::enable(GL_LIGHTING);
gl::disable(GL_BLEND); // disbable alpha blending for world polys
-
- draw_pass_default(); // draw entities without model
+ gl::disable(GL_RESCALE_NORMAL);
glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::vertex);
glNormalPointer(GL_FLOAT, 0, core::VertexArray::vertex_normal);
@@ -458,25 +476,32 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
-
+
draw_pass_model_vertex(); // draw entities with model
glDisableClientState(GL_COLOR_ARRAY);
+ gl::enable(GL_RESCALE_NORMAL); // rescale normals by the transformation matrix scale factor
+
+ draw_pass_default(); // draw entities without model
+
+ gl::disable(GL_RESCALE_NORMAL);
draw_pass_model_evertex(); // draw entities with model, vertices with entity color
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
-
gl::disable(GL_LIGHTING);
gl::enable(GL_BLEND);
draw_pass_model_fx(); // draw entity lights and engines
gl::enable(GL_LIGHTING);
+ gl::enable(GL_RESCALE_NORMAL);
draw_pass_model_radius(); //draw entity radius
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ gl::disable(GL_RESCALE_NORMAL);
gl::disable(GL_LIGHTING);
gl::disable(GL_COLOR_MATERIAL); // disable color tracking
gl::disable(GL_CULL_FACE); // disable culling
@@ -484,6 +509,8 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds
draw_pass_spacegrid(); // draw the blue spacegrid
gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
+
+ // GL_BLEND must be enabled for the GUI
}
}