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-05 18:21:39 +0000
committerStijn Buys <ingar@osirion.org>2008-03-05 18:21:39 +0000
commit4f6b27b58bfae9ce860a005edf890d8f1136a85f (patch)
treea3b4f7b108173d8cba0df0c66768d0a9ebf61047 /src/render
parentc326c5d31e710cd22f4d5047252da2bfc77da1f1 (diff)
OpenGL lighting
Diffstat (limited to 'src/render')
-rw-r--r--src/render/face.cc1
-rw-r--r--src/render/gl.cc14
-rw-r--r--src/render/gl.h11
-rw-r--r--src/render/model.cc17
4 files changed, 25 insertions, 18 deletions
diff --git a/src/render/face.cc b/src/render/face.cc
index 764c452..31b7fcc 100644
--- a/src/render/face.cc
+++ b/src/render/face.cc
@@ -43,6 +43,7 @@ void Face::draw()
{
//gl::begin(gl::LineLoop);
gl::begin(gl::Polygon);
+ gl::normal(face_normal); // face_normal already has unit lenght
for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
gl::vertex(*(*it));
}
diff --git a/src/render/gl.cc b/src/render/gl.cc
index 6eb91b1..682bfc8 100644
--- a/src/render/gl.cc
+++ b/src/render/gl.cc
@@ -4,12 +4,10 @@
the terms of the GNU General Public License version 2
*/
-// project includes
-#include "render/gl.h"
-
-// system includes
#include "GL/gl.h"
+#include "render/gl.h"
+
using math::Vector3f;
using math::Color;
@@ -130,6 +128,14 @@ void vertex(const float x, const float y, const float z) {
glVertex3f(x, y, z);
}
+void normal(const Vector3f & vector) {
+ glNormal3fv(vector.coord);
+}
+
+void normal(const float x, const float y, const float z) {
+ glNormal3f(x, y, z);
+}
+
void push() {
glPushMatrix();
}
diff --git a/src/render/gl.h b/src/render/gl.h
index 0513410..d5d6418 100644
--- a/src/render/gl.h
+++ b/src/render/gl.h
@@ -7,13 +7,11 @@
#ifndef __INCLUDED_RENDER_GL_H__
#define __INCLUDED_RENDER_GL_H__
-// project headers
+#include <GL/gl.h>
+
#include "math/vector3f.h"
#include "math/color.h"
-// OpenGL headers
-#include <GL/gl.h>
-
namespace render {
/// wrapper namespace for OpenGL operations
@@ -99,6 +97,11 @@ namespace gl
void vertex(const math::Vector3f& vector);
void vertex(const float x, const float y, const float z);
+
+ /// glNormal
+ void normal(const math::Vector3f & vector);
+
+ void normal(const float x, const float y, const float z);
/// multiply the current matrix by a general rotation matrix
/** @param angle The angle of the rotation, in degrees [0-360]
diff --git a/src/render/model.cc b/src/render/model.cc
index 70b5f18..848bc49 100644
--- a/src/render/model.cc
+++ b/src/render/model.cc
@@ -414,9 +414,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
color = 0;
}
- Vector3f n = face->normal();
- n.normalize();
- Face *mf = new Face(n, color);
+ Face *mf = new Face(face->normal()*-1, color);
if (color) delete color;
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
@@ -459,16 +457,16 @@ void Model::draw(core::Entity const * entity, math::Vector3f const & eye)
for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
// poor man's lighting
// set the face color depending on the viewing direction
- float d = fabsf(math::dotproduct(n, (*fit)->normal()));
+ //float d = fabsf(math::dotproduct(n, (*fit)->normal()));
- if (d > 1)
- d = 1;
- d = 0.5f + d/2;
+ //if (d > 1)
+ // d = 1;
+ //d = 0.5f + d/2;
if ((*fit)->color()) {
- render::gl::color(*(*fit)->color() * d);
+ render::gl::color(*(*fit)->color());
} else {
- render::gl::color(entity->color() * d);
+ render::gl::color(entity->color());
}
(*fit)->draw();
}
@@ -482,7 +480,6 @@ void Model::draw(core::EntityControlable const * entity, math::Vector3f const &
// draw engines
// all engines are assumed to point to the rear
if (model_engine.size() && entity->thrust()) {
-
gl::color(1.0f,0 ,0);
gl::begin(gl::Lines);