diff options
author | Stijn Buys <ingar@osirion.org> | 2008-03-24 12:35:48 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-03-24 12:35:48 +0000 |
commit | b32c086a9b9deed4c34ade6e2447861a9c4bfc46 (patch) | |
tree | f3213a8f4b1ffd15df28aa6bd82b9fe6c1bb979d /src/render | |
parent | 80ad7e99b738f367eb045768d054cf74347ee1b4 (diff) |
moved the sphere into the vertex array
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/Makefile.am | 4 | ||||
-rw-r--r-- | src/render/draw.cc | 87 | ||||
-rw-r--r-- | src/render/draw.h | 2 | ||||
-rw-r--r-- | src/render/sphere.cc | 132 | ||||
-rw-r--r-- | src/render/sphere.h | 46 |
5 files changed, 60 insertions, 211 deletions
diff --git a/src/render/Makefile.am b/src/render/Makefile.am index d9a8301..87f3ba3 100644 --- a/src/render/Makefile.am +++ b/src/render/Makefile.am @@ -3,5 +3,5 @@ METASOURCES = AUTO noinst_LTLIBRARIES = librender.la librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@ librender_la_LIBADD = $(top_builddir)/src/math/libmath.la -librender_la_SOURCES = draw.cc gl.cc render.cc sphere.cc text.cc tga.cc -noinst_HEADERS = draw.h gl.h render.h sphere.h text.h tga.h +librender_la_SOURCES = draw.cc gl.cc render.cc text.cc tga.cc +noinst_HEADERS = draw.h gl.h render.h text.h tga.h 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 } } diff --git a/src/render/draw.h b/src/render/draw.h index f9f35f3..b423aad 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -20,7 +20,7 @@ public: static void clear(); static size_t tris; - static size_t spheres; + static size_t quads; }; } diff --git a/src/render/sphere.cc b/src/render/sphere.cc deleted file mode 100644 index d44c9e6..0000000 --- a/src/render/sphere.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - gl/sphere.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "render/sphere.h" -#include "render/render.h" -#include "math/mathlib.h" - -using math::Vector3f; -using math::Color; - -namespace render { - -const int segments = 33; - -Sphere::Sphere(float r) -{ - radius = r; - - // TODO make global sine-cosine lists - sintable = new float[segments]; - costable = new float[segments]; - float d = 2 * M_PI / (segments-1); - - for (int i=0; i < segments; i++) { - sintable[i] = sin( d * (float) i ); - costable[i] = cos ( d * (float) i ); - } -} - -Sphere::~Sphere() -{ - delete[] sintable; - delete[] costable; -} - -Sphere::Sphere(const Sphere &other) -{ - (*this) = other; -} - -Sphere& Sphere::operator=(const Sphere &other) -{ - sphere_color = other.sphere_color; - radius = other.radius; - return (*this); -} - -void Sphere::draw() -{ - using namespace gl; - - float r = radius*sintable[1]; - //float h = radius*costable[1]; - - gl::color(sphere_color); - - /* - // draw top - begin(Polygon); - normal(0, 1, 0); - for (int i = segments-1; i >= 0; i--) { - v = Vector3f(r*costable[i], h, r*sintable[i]); - n = v; - n.normalize(); - normal(n); - vertex(v); - } - end(); - - // draw bottom - begin(Polygon); - normal(0, -1, 0); - for (int i = 0; i< segments; i++) { - //for (int i = segments-1; i >= 0; i--) - v = Vector3f(r*costable[i], -h, r*sintable[i]); - n = v; - n.normalize(); - normal(n); - vertex(v); - } - end(); - */ - - Vector3f v; - Vector3f n; - - // draw body - for (int j=0; j < segments-1; j++) { - r = radius*sintable[j]; - float r1 = radius*sintable[j+1]; - // draw all vertexes - if (r_drawwireframe && r_drawwireframe->value()) { - gl::begin(gl::LineStrip); - } else { - gl::begin(gl::QuadStrip); - } - v = Vector3f(r, 0, radius*costable[j]); - n = v; - n.normalize(); - normal(n); - vertex(v); - - v = Vector3f(r1, 0, radius*costable[j+1]); - n = v; - n.normalize(); - normal(n); - vertex(v); - - for (int i = segments-1; i >= 0; i--) { - v = Vector3f(r*costable[i], r*sintable[i], radius*costable[j]); - n = v; - n.normalize(); - normal(n); - vertex(v); - - v = Vector3f(r1*costable[i], r1*sintable[i], radius*costable[j+1]); - n = v; - n.normalize(); - normal(n); - vertex(v); - } - end(); - - } -} - - -} - diff --git a/src/render/sphere.h b/src/render/sphere.h deleted file mode 100644 index 73a2169..0000000 --- a/src/render/sphere.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - gl/sphere.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_GL_SPHERE_H__ -#define __INCLUDED_GL_SPHERE_H__ - -#include "render/gl.h" - -namespace render { - -/// a drawable OpenGL block shape -class Sphere -{ -public: - /// create a new sphere - Sphere(float r = 1.0f); - - /// copy constructor - Sphere(const Sphere &other); - - /// destructor - ~Sphere(); - - /// assignment operator - Sphere& operator=(const Sphere &other); - - /// radius of the sphere - float radius; - - /// draw the sphere - void draw(); - - /// color - math::Color sphere_color; - -private: - float *sintable; - float *costable; -}; - -} // namespace gl - -#endif // __INCLUDED_GL_SPHERE_H__ |