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/client
parentc326c5d31e710cd22f4d5047252da2bfc77da1f1 (diff)
OpenGL lighting
Diffstat (limited to 'src/client')
-rw-r--r--src/client/draw.cc38
-rw-r--r--src/client/view.cc59
2 files changed, 68 insertions, 29 deletions
diff --git a/src/client/draw.cc b/src/client/draw.cc
index 1ea315b..87be92c 100644
--- a/src/client/draw.cc
+++ b/src/client/draw.cc
@@ -139,17 +139,22 @@ void draw_ship(core::EntityControlable *entity)
// draw an entity of entity_type core::Entity::Default
void draw_entity_default(core::Entity *entity)
{
- render::Model *model = 0;
+ using namespace render;
+
+ Model *model = 0;
if (entity->modelname().size())
- model = render::Model::get(entity->modelname());
+ model = Model::get(entity->modelname());
- render::gl::push();
- render::gl::translate(entity->location());
- render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
+ gl::push();
+ gl::translate(entity->location());
+ gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
if (model) {
model->draw(entity, camera::eye);
} else {
+ gl::disable(GL_LIGHTING);
+ gl::disable(GL_LIGHT0);
+
switch(entity->shape()) {
case core::Entity::Sphere:
draw_entity_sphere(entity);
@@ -165,9 +170,12 @@ void draw_entity_default(core::Entity *entity)
draw_entity_cube(entity);
break;
}
+
+ gl::enable(GL_LIGHTING);
+ gl::enable(GL_LIGHT0); // disable camera light
}
- render::gl::pop();
+ gl::pop();
}
// draw an entity of entity_type core::Entity::Controlable
@@ -205,6 +213,8 @@ void draw_spacegrid()
float dy = camera::target.y - floorf(camera::target.y);
color(0,0, 1.0f);
+ normal(0, 0, 1.0f);
+
begin(Lines);
for (int i=-gridsize; i <= gridsize; i++) {
color(0,0, 0, 0);
@@ -235,6 +245,14 @@ void draw_world(float seconds)
// draw entities
using namespace render;
+
+ gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
+ gl::enable(GL_CULL_FACE); // enable culling
+ gl::enable(GL_COLOR_MATERIAL); // enable color tracking
+ gl::enable(GL_LIGHTING);
+ gl::enable(GL_LIGHT0); // enable camera light
+ //gl::enable(GL_NORMALIZE);
+
std::map<unsigned int, core::Entity *>::iterator it;
for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
switch ((*it).second->type()) {
@@ -249,8 +267,16 @@ void draw_world(float seconds)
}
}
+ gl::disable(GL_CULL_FACE); // disable culling
+ gl::disable(GL_COLOR_MATERIAL); // disable color tracking
+ gl::disable(GL_LIGHTING);
+ gl::disable(GL_LIGHT0); // disable camera light
+ //gl::disable(GL_NORMALIZE);
+
// draw the background grid
draw_spacegrid();
+
+ gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
}
}
diff --git a/src/client/view.cc b/src/client/view.cc
index 8ddd33c..1863d00 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -4,6 +4,13 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include <GL/gl.h>
+
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
+
#include "client/client.h"
#include "client/camera.h"
#include "client/chat.h"
@@ -15,11 +22,6 @@
#include "math/mathlib.h"
#include "sys/sys.h"
-#include <iostream>
-#include <string>
-#include <sstream>
-#include <iomanip>
-
namespace client
{
@@ -45,21 +47,42 @@ void reset()
// set clear color
gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f);
- // shading model: Gouraud (smooth).
+ // shading model: Gouraud (smooth, the default)
gl::shademodel(GL_SMOOTH);
+ //gl::shademodel(GL_FLAT);
+
+ // lighting
+ GLfloat ambient_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ GLfloat diffuse_light[] = { 0.6f, 0.6f, 0.6f, 1.0f };
+ GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ GLfloat specular_reflectance[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+
+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light);
+
+ // color tracking
+ glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+
+ glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance);
+ glMateriali(GL_FRONT, GL_SHININESS, 16); // shininess 1-128
+ gl::disable(GL_LIGHTING);
+ gl::disable(GL_LIGHT0);
+ gl::disable(GL_COLOR_MATERIAL);
+
// culling
gl::cullface(GL_BACK);
gl::frontface(GL_CCW);
-
- // alpha-blending
- gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- gl::disable(GL_BLEND);
+ gl::disable(GL_CULL_FACE);
// depth
gl::depthmask(GL_TRUE);
- gl::disable(GL_DEPTH_TEST);
- gl::disable(GL_CULL_FACE);
+ gl::disable(GL_DEPTH_TEST);
+
+ // alpha-blending
+ gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ gl::enable(GL_BLEND);
}
void draw_loader()
@@ -169,6 +192,7 @@ void frame(float seconds)
gl::matrixmode(GL_PROJECTION);
gl::loadidentity();
+ // FIXME width must always be one
const float frustumsize = 0.5f;
gl::frustum(-frustumsize*video::aspect, frustumsize*video::aspect, -frustumsize, frustumsize, 1.0f, 1024.0f);
@@ -177,14 +201,7 @@ void frame(float seconds)
camera::draw(seconds); // draw the current camera transformation
- gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
- gl::enable(GL_CULL_FACE); // enable culling
- gl::enable(GL_BLEND); // enable alpha blending
-
draw_world(seconds); // draw the world
-
- gl::disable(GL_CULL_FACE); // disable culling
- gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
}
// switch to ortographic projection to draw the GUI
@@ -198,7 +215,6 @@ void frame(float seconds)
if (!core::application()->connected()) {
// draw the loader bitmap
draw_loader();
- gl::enable(GL_BLEND); // enable alpha blending
}
// draw the console
@@ -207,9 +223,6 @@ void frame(float seconds)
// draw the status line
draw_status();
-
- gl::disable(GL_BLEND);
-
}
} //namespace view