Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/camera.cc225
-rw-r--r--src/render/camera.h29
-rw-r--r--src/render/draw.cc369
-rw-r--r--src/render/draw.h13
-rw-r--r--src/render/dust.cc18
-rw-r--r--src/render/gl.cc111
-rw-r--r--src/render/gl.h312
-rw-r--r--src/render/image.cc28
-rw-r--r--src/render/image.h38
-rw-r--r--src/render/jpgfile.cc29
-rw-r--r--src/render/jpgfile.h5
-rw-r--r--src/render/particles.cc163
-rw-r--r--src/render/particles.h106
-rw-r--r--src/render/pngfile.cc79
-rw-r--r--src/render/pngfile.h5
-rw-r--r--src/render/render.cc15
-rw-r--r--src/render/render.h80
-rw-r--r--src/render/renderext.cc14
-rw-r--r--src/render/renderext.h31
-rw-r--r--src/render/screenshot.cc53
-rw-r--r--src/render/screenshot.h12
-rw-r--r--src/render/state.cc23
-rw-r--r--src/render/state.h26
-rw-r--r--src/render/text.cc36
-rw-r--r--src/render/text.h12
-rw-r--r--src/render/textures.cc32
-rw-r--r--src/render/tgafile.cc222
-rw-r--r--src/render/tgafile.h5
28 files changed, 1120 insertions, 971 deletions
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 913adfb..329ab36 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -1,7 +1,7 @@
-/*
+/*
render/camera.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <cmath>
@@ -50,10 +50,10 @@ float Camera::camera_zoom;
void Camera::init()
{
direction_current = 0;
- direction_target = 0;
+ direction_target = 0;
- pitch_current = pitch_track * 2;
- pitch_target = pitch_track;
+ pitch_current = pitch_track * 2;
+ pitch_target = pitch_track;
target_pitch = 0.0f;
target_direction = 0.0f;
@@ -68,15 +68,16 @@ void Camera::init()
camera_axis.clear();
camera_eye.clear();
camera_target.clear();
-
+
}
void Camera::shutdown()
{
}
-void Camera::set_mode(Mode newmode) {
-
+void Camera::set_mode(Mode newmode)
+{
+
direction_target = 0;
direction_current = direction_target;
pitch_target = pitch_track;
@@ -91,103 +92,103 @@ void Camera::set_mode(Mode newmode) {
if (camera_mode != Overview)
camera_previous_mode = camera_mode;
- switch(newmode) {
- case Track:
- // switch camera to Track mode
- camera_mode = Track;
- if (core::localcontrol()) {
- camera_axis.assign(core::localcontrol()->axis());
- }
- break;
+ switch (newmode) {
+ case Track:
+ // switch camera to Track mode
+ camera_mode = Track;
+ if (core::localcontrol()) {
+ camera_axis.assign(core::localcontrol()->axis());
+ }
+ break;
- case Free:
- // switch camera to Free mode
- camera_mode = Free;
- pitch_target = pitch_free;
- pitch_current = pitch_target;
- break;
+ case Free:
+ // switch camera to Free mode
+ camera_mode = Free;
+ pitch_target = pitch_free;
+ pitch_current = pitch_target;
+ break;
- case Cockpit:
- camera_mode = Cockpit;
- break;
+ case Cockpit:
+ camera_mode = Cockpit;
+ break;
- case Overview:
- // switch camera to Overview mode
- camera_mode = Overview;
+ case Overview:
+ // switch camera to Overview mode
+ camera_mode = Overview;
- default:
- break;
+ default:
+ break;
}
}
void Camera::view_next()
{
-
- if (!core::localcontrol()) {
+
+ if (!core::localcontrol()) {
set_mode(Overview);
return;
}
- switch(camera_mode) {
- case Free:
- // switch camera to Track mode
- set_mode(Track);
- //con_print << "view: track" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: track"));
- break;
-
- case Track:
- // switch camera to Cockpit mode
- set_mode(Cockpit);
- //con_print << "view: cockpit" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
- break;
-
- case Cockpit:
- // switch camera to Free mode
- set_mode(Free);
- //con_print << "view: free" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: free"));
- break;
-
- default:
- break;
+ switch (camera_mode) {
+ case Free:
+ // switch camera to Track mode
+ set_mode(Track);
+ //con_print << "view: track" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: track"));
+ break;
+
+ case Track:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ //con_print << "view: cockpit" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
+ break;
+
+ case Cockpit:
+ // switch camera to Free mode
+ set_mode(Free);
+ //con_print << "view: free" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: free"));
+ break;
+
+ default:
+ break;
}
}
void Camera::view_previous()
{
-
- if (!core::localcontrol()) {
+
+ if (!core::localcontrol()) {
set_mode(Overview);
return;
}
- switch(camera_mode) {
- case Cockpit:
- // switch camera to Track mode
- set_mode(Track);
- //con_print << "view: track" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: track"));
- break;
-
- case Free:
- // switch camera to Cockpit mode
- set_mode(Cockpit);
- //con_print << "view: cockpit" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
- break;
-
- case Track:
- // switch camera to Free mode
- set_mode(Free);
- //con_print << "view: free" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: free"));
- break;
-
- default:
- break;
+ switch (camera_mode) {
+ case Cockpit:
+ // switch camera to Track mode
+ set_mode(Track);
+ //con_print << "view: track" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: track"));
+ break;
+
+ case Free:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ //con_print << "view: cockpit" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
+ break;
+
+ case Track:
+ // switch camera to Free mode
+ set_mode(Free);
+ //con_print << "view: free" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: free"));
+ break;
+
+ default:
+ break;
}
}
@@ -197,8 +198,8 @@ void Camera::set_zoom(float zoom)
math::clamp(camera_zoom, 1.0f, 10.0f);
}
-void Camera::frame(float seconds)
-{
+void Camera::frame(float seconds)
+{
math::Axis target_axis;
float d = 0;
@@ -218,10 +219,10 @@ void Camera::frame(float seconds)
if (mode() == Overview) {
camera_eye.clear();
-
+
if (core::localplayer()->view()) {
// player view entity
-
+
camera_axis.assign(core::localplayer()->view()->axis());
if (core::localplayer()->view() == core::localcontrol()) {
camera_axis.change_pitch(pitch_free);
@@ -230,17 +231,17 @@ void Camera::frame(float seconds)
} else {
distance = math::max(core::localplayer()->view()->radius(), 1.0f) * 3.0f;
camera_axis.change_direction(180.0f);
- camera_target.assign(core::localplayer()->view()->location() - core::localplayer()->view()->axis().left()* (math::max(core::localplayer()->view()->radius(), 1.0f)*0.5f) );
+ camera_target.assign(core::localplayer()->view()->location() - core::localplayer()->view()->axis().left()*(math::max(core::localplayer()->view()->radius(), 1.0f)*0.5f));
}
-
-/*
- } else if (core::localplayer()->zone()->default_view()) {
- // default zone view entity
- camera_target.assign(core::localplayer()->zone()->default_view()->location());
- camera_axis.assign(core::localplayer()->zone()->default_view()->axis());
- camera_axis.change_direction(180.0f);
- distance = math::max(core::localplayer()->zone()->default_view()->radius(), 1.0f) * 2.0f;
-*/
+
+ /*
+ } else if (core::localplayer()->zone()->default_view()) {
+ // default zone view entity
+ camera_target.assign(core::localplayer()->zone()->default_view()->location());
+ camera_axis.assign(core::localplayer()->zone()->default_view()->axis());
+ camera_axis.change_direction(180.0f);
+ distance = math::max(core::localplayer()->zone()->default_view()->radius(), 1.0f) * 2.0f;
+ */
} else {
// default location (0,0,0)
camera_target.clear();
@@ -258,7 +259,7 @@ void Camera::frame(float seconds)
if (mode() == Track) {
float cosangle; // cosine of an angle
- float angle; // angle in radians
+ float angle; // angle in radians
math::Vector3f n; // normal of a plane
n.assign(math::crossproduct(camera_axis.forward(), target_axis.forward()));
@@ -286,36 +287,36 @@ void Camera::frame(float seconds)
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
camera_axis.rotate(n, -angle);
- }
+ }
if (core::localcontrol()->model()) {
camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().x());
camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().z() * 2.0f);
} else {
- camera_target -= camera_axis.forward() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
- camera_target += camera_axis.up() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
}
- distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
+ distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Free) {
camera_axis.assign(target_axis);
-
+
direction_target = direction_current - 90 * target_direction;
pitch_target = pitch_current - 90 * target_pitch;
// adjust direction
d = degrees180f(direction_current - direction_target);
- direction_current = degrees360f( direction_current - d * seconds);
+ direction_current = degrees360f(direction_current - d * seconds);
camera_axis.change_direction(direction_current);
- // adjust pitch
+ // adjust pitch
d = degrees180f(pitch_current - pitch_target);
pitch_current = degrees360f(pitch_current - d * seconds);
camera_axis.change_pitch(pitch_current);
- distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
+ distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Cockpit) {
@@ -323,10 +324,10 @@ void Camera::frame(float seconds)
if (core::localcontrol()->model()) {
camera_target += (core::localcontrol()->model()->maxbbox().x()) *
- core::localcontrol()->axis().forward();
+ core::localcontrol()->axis().forward();
} else {
camera_target += (core::localcontrol()->radius()) *
- core::localcontrol()->axis().forward();
+ core::localcontrol()->axis().forward();
}
distance = (FRUSTUMFRONT / WORLDSCALE) - 0.001f;
}
@@ -342,7 +343,7 @@ void Camera::frustum()
gl::matrixmode(GL_PROJECTION);
gl::loadidentity();
- gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE);
+ gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE / State::aspect(), FRUSTUMSIZE / State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -369,9 +370,9 @@ void Camera::frustum_default(float distance, float cx, float cy)
// move eye to (cx, cy)
// note: the factor 2.0f probably has to be 1.0f/frustum_size
- gl::translate(2.0f*(-State::width() * 0.5f + cx)/State::width() , 2.0f*(State::height() * 0.5f - cy)/State::height(), 0.0f);
+ gl::translate(2.0f*(-State::width() * 0.5f + cx) / State::width() , 2.0f*(State::height() * 0.5f - cy) / State::height(), 0.0f);
- gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, 1023.0f);
+ gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE / State::aspect(), FRUSTUMSIZE / State::aspect(), FRUSTUMFRONT, 1023.0f);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -380,7 +381,7 @@ void Camera::frustum_default(float distance, float cx, float cy)
gl::rotate(90.0f, 0.0f, 1.0f, 0.0f);
gl::rotate(-90.0f, 1.0f , 0.0f, 0.0f);
- gl::translate(distance+1.0f, 0.0f, 0.0f);
+ gl::translate(distance + 1.0f, 0.0f, 0.0f);
// extra model rotation
gl::rotate(-core::application()->time() / 8.0f *360.0f , 0.0f, 0.0f, 1.0f);
diff --git a/src/render/camera.h b/src/render/camera.h
index 49cba74..80fdb36 100644
--- a/src/render/camera.h
+++ b/src/render/camera.h
@@ -1,7 +1,7 @@
-/*
+/*
render/camera.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_CAMERA_H__
@@ -10,7 +10,8 @@
#include "math/mathlib.h"
#include "core/range.h"
-namespace render {
+namespace render
+{
const float WORLDSCALE = 4.0f;
const float FARPLANE = core::range::maxdistance;
@@ -32,16 +33,24 @@ public:
static void shutdown();
/// gameworld coordinates of the camera eye
- static inline const math::Vector3f & eye() { return camera_eye; }
+ static inline const math::Vector3f & eye() {
+ return camera_eye;
+ }
/// gameworld coordinates of the camera target
- static inline const math::Vector3f & target() { return camera_target; }
+ static inline const math::Vector3f & target() {
+ return camera_target;
+ }
/// gameworld camera axis
- static inline const math::Axis & axis() { return camera_axis; }
+ static inline const math::Axis & axis() {
+ return camera_axis;
+ }
/// current camera mode
- static inline Mode mode() { return camera_mode; }
+ static inline Mode mode() {
+ return camera_mode;
+ }
/// reset the current mode
static void reset();
@@ -63,7 +72,7 @@ public:
/** The ortographic projetion is used to draw the user interface
*/
static void ortho();
-
+
/// set target zoom
static void set_zoom(float zoom);
@@ -106,5 +115,5 @@ private:
};
} // namespace client
-
+
#endif // __INCLUDED_RENDER_CAMERA_H__
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 4dc6e53..dea24bc 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -1,7 +1,7 @@
/*
render/draw.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <sstream>
@@ -59,15 +59,15 @@ void pass_prepare(float seconds)
using namespace model;
// lighting settings for the default light GL_LIGHT0
- GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
+ GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f };
GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- for (size_t i=0; i <3; i++) {
- light_position[i] = Camera::eye()[i];
+ for (size_t i = 0; i < 3; i++) {
+ light_position[i] = Camera::eye()[i];
}
-
+
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
@@ -86,14 +86,14 @@ void pass_prepare(float seconds)
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
-
+
if (!ext_render(entity)) {
new RenderExt(entity);
}
entity->extension((size_t) core::Extension::Render)->frame(seconds);
// globes
- if (entity->type() == core::Entity::Globe) {
+ if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
// add the globe to the globes list
@@ -109,14 +109,14 @@ void pass_prepare(float seconds)
GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- for (size_t i=0; i <3; i++) {
+ for (size_t i = 0; i < 3; i++) {
zone_light[i] = globe->location()[i];
zone_color[i] = globe->color()[i];
diffuse_light[i] = globe->color()[i] * 0.4;
}
zone_light[3] = 1.0f;
diffuse_light[3] = 1.0f;
-
+
glLightfv(GL_LIGHT1, GL_POSITION, zone_light);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
@@ -132,18 +132,18 @@ void pass_prepare(float seconds)
/* ----- Skybox ---------------------------------------------------- */
void draw_sphere_inside(math::Color const & color, float radius)
-{
+{
gl::scale(radius, radius, radius);
gl::color(color);
- size_t index = (model::SPHERESEGMENTS) * (model::SPHERESEGMENTS-1);
- size_t count = (model::SPHERESEGMENTS)*2;
+ size_t index = (model::SPHERESEGMENTS) * (model::SPHERESEGMENTS - 1);
+ size_t count = (model::SPHERESEGMENTS) * 2;
// draw body
- for (int j=0; j < (model::SPHERESEGMENTS-1)/2; j++) {
+ for (int j = 0; j < (model::SPHERESEGMENTS - 1) / 2; j++) {
glDrawArrays(gl::QuadStrip, index, count);
index += count;
- Stats::quads += count/2-1;
+ Stats::quads += count / 2 - 1;
}
}
@@ -175,7 +175,7 @@ void draw_pass_sky()
gl::enable(GL_TEXTURE_2D);
gl::push();
- gl::translate(Camera::eye());
+ gl::translate(Camera::eye());
draw_sphere_inside(math::Color(), 1016.0f);
gl::pop();
@@ -186,33 +186,33 @@ void draw_pass_sky()
/* ---- Globes ----------------------------------------------------- */
void draw_sphere(math::Color const & color, float radius)
-{
+{
gl::scale(radius, radius, radius);
gl::color(color);
size_t index = 0;
- size_t count = (model::SPHERESEGMENTS)*2;
+ size_t count = (model::SPHERESEGMENTS) * 2;
// draw body
- for (int j=0; j < (model::SPHERESEGMENTS-1)/2; j++) {
+ for (int j = 0; j < (model::SPHERESEGMENTS - 1) / 2; j++) {
glDrawArrays(gl::QuadStrip, index, count);
index += count;
- Stats::quads += count/2-1;
+ Stats::quads += count / 2 - 1;
}
}
void draw_globe(const core::EntityGlobe* globe)
{
- /*
+ /*
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();
- if(globe->flag_is_set(core::Entity::Bright)) {
+ if (globe->flag_is_set(core::Entity::Bright)) {
// bright globe, render fullbright
- gl::disable(GL_LIGHTING);
+ gl::disable(GL_LIGHTING);
} else {
// disable camera light, level light only
gl::disable(GL_LIGHT0);
@@ -234,10 +234,10 @@ void draw_globe(const core::EntityGlobe* globe)
if (has_zone_light) {
// move zone light
float fake_light[4];
- for (size_t i=0; i < 3; i++) {
+ for (size_t i = 0; i < 3; i++) {
fake_light[i] = zone_light[i] + location[i] - globe->location()[i];
}
- fake_light[3] = 1.0f;
+ fake_light[3] = 1.0f;
glLightfv(GL_LIGHT1, GL_POSITION, fake_light);
}
}
@@ -255,7 +255,7 @@ void draw_globe(const core::EntityGlobe* globe)
gl::pop();
- if(globe->flag_is_set(core::Entity::Bright)) {
+ if (globe->flag_is_set(core::Entity::Bright)) {
math::Vector3f v = globe->location() - Camera::eye();
v.normalize();
@@ -264,7 +264,7 @@ void draw_globe(const core::EntityGlobe* globe)
// FIXME a corona is actually just a giant flare
if (!globe->render_texture) {
gl::enable(GL_TEXTURE_2D);
- }
+ }
Textures::bind("textures/fx/corona");
/*
if (ext_render(globe)->distance() <= farplane) {
@@ -274,23 +274,23 @@ void draw_globe(const core::EntityGlobe* globe)
math::Color color(globe->color());
color.a = a - 0.1f;
-
+
gl::color(color);
- gl::enable(GL_BLEND);
-
+ gl::enable(GL_BLEND);
+
gl::begin(gl::Quads);
- glTexCoord2f(0,1);
- gl::vertex(location+ (Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
- glTexCoord2f(0,0);
- gl::vertex(location+ (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);
- glTexCoord2f(1,1);
- gl::vertex(location+ (Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
+ glTexCoord2f(0, 1);
+ gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
+ glTexCoord2f(0, 0);
+ gl::vertex(location + (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);
+ glTexCoord2f(1, 1);
+ gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
gl::end();
-
+
Stats::quads++;
-
+
gl::disable(GL_BLEND);
/*
if (ext_render(globe)->distance() <= farplane) {
@@ -316,11 +316,11 @@ void draw_globe(const core::EntityGlobe* globe)
}
if (globe->flag_is_set(core::Entity::Bright)) {
- gl::enable(GL_LIGHTING);
+ gl::enable(GL_LIGHTING);
} else {
gl::enable(GL_LIGHT0);
}
-
+
if (globe->render_texture) {
gl::disable(GL_TEXTURE_2D);
}
@@ -349,52 +349,52 @@ void draw_entity_cube(const core::Entity* entity)
gl::color(entity->color());
gl::begin(gl::Quads);
-
+
// top
- gl::normal(0,0,1);
+ gl::normal(0, 0, 1);
gl::vertex(v0);
gl::vertex(v1);
- gl::vertex(v2);
+ gl::vertex(v2);
gl::vertex(v3);
// bottom
- gl::normal(0,0, -1);
+ gl::normal(0, 0, -1);
gl::vertex(v7);
gl::vertex(v6);
- gl::vertex(v5);
+ gl::vertex(v5);
gl::vertex(v4);
-
+
// sides
- gl::normal(1,0,0);
+ gl::normal(1, 0, 0);
gl::vertex(v1);
- gl::vertex(v0);
- gl::vertex(v4);
- gl::vertex(v5);
+ gl::vertex(v0);
+ gl::vertex(v4);
+ gl::vertex(v5);
- gl::normal(-1,0,0);
- gl::vertex(v3);
- gl::vertex(v2);
- gl::vertex(v6);
- gl::vertex(v7);
+ gl::normal(-1, 0, 0);
+ gl::vertex(v3);
+ gl::vertex(v2);
+ gl::vertex(v6);
+ gl::vertex(v7);
- gl::normal(0,1,0);
+ gl::normal(0, 1, 0);
gl::vertex(v2);
- gl::vertex(v1);
- gl::vertex(v5);
- gl::vertex(v6);
+ gl::vertex(v1);
+ gl::vertex(v5);
+ gl::vertex(v6);
- gl::normal(0,-1,0);
+ gl::normal(0, -1, 0);
gl::vertex(v0);
- gl::vertex(v3);
- gl::vertex(v7);
- gl::vertex(v4);
+ gl::vertex(v3);
+ gl::vertex(v7);
+ gl::vertex(v4);
gl::end();
}
void draw_entity_diamond(const core::Entity* entity)
{
- float radius = entity->radius()/2;
+ float radius = entity->radius() / 2;
/* ---- draw axis lines ---- */
gl::color(entity->color_second());
@@ -411,7 +411,7 @@ void draw_entity_diamond(const core::Entity* entity)
gl::vertex(-1.25f * radius, 0, 0);
gl::vertex(-2 * radius, 0, 0);
-
+
gl::vertex(0, -1.25f * radius, 0);
gl::vertex(0, -2 * radius, 0);
@@ -421,7 +421,7 @@ void draw_entity_diamond(const core::Entity* entity)
gl::end();
/* ---- draw rotating body lines ---- */
- float angle = (core::application()->time() + ext_render(entity)->fuzz() ) * 45.0f;
+ float angle = (core::application()->time() + ext_render(entity)->fuzz()) * 45.0f;
angle = angle - 360.0f * floorf(angle / 360.0f);
gl::rotate(angle, math::Vector3f::Zaxis());
@@ -430,19 +430,19 @@ void draw_entity_diamond(const core::Entity* entity)
}
gl::color(entity->color());
- gl::begin(gl::TriangleFan );
+ gl::begin(gl::TriangleFan);
gl::normal(0, 0 , 1);
gl::vertex(0, 0, radius);
- gl::normal(1, 0 ,0);
+ gl::normal(1, 0 , 0);
gl::vertex(radius, 0.0f, 0.0f);
gl::normal(0, 1, 0);
gl::vertex(0.0f, radius, 0.0f);
- gl::normal(-1, 0 ,0);
+ gl::normal(-1, 0 , 0);
gl::vertex(-radius, 0.0f, 0.0f);
gl::normal(0, -1, 0);
gl::vertex(0.0f, -radius, 0.0f);
- gl::normal(1, 0 ,0);
+ gl::normal(1, 0 , 0);
gl::vertex(radius, 0.0f, 0.0f);
gl::end();
@@ -450,20 +450,20 @@ void draw_entity_diamond(const core::Entity* entity)
gl::begin(gl::TriangleFan);
gl::normal(0, 0 , -1);
gl::vertex(0, 0, -radius);
-
+
gl::normal(1, 0, 0);
gl::vertex(radius, 0.0f, 0.0f);
gl::normal(0, -1, 0);
gl::vertex(0.0f, -radius, 0.0f);
- gl::normal(-1, 0 ,0);
+ gl::normal(-1, 0 , 0);
gl::vertex(-radius, 0.0f, 0.0f);
gl::normal(0, 1, 0);
gl::vertex(0.0f, radius, 0.0f);
- gl::normal(1, 0 ,0);
+ gl::normal(1, 0 , 0);
gl::vertex(radius, 0.0f, 0.0f);
gl::end();
@@ -478,16 +478,16 @@ void draw_entity_axis(const core::Entity* entity)
gl::begin(gl::Lines);
gl::color(entity->color_second());
- gl::vertex(r,0.0f,0.0f);
+ gl::vertex(r, 0.0f, 0.0f);
gl::color(entity->color());
- gl::vertex(-r,0.0f,0.0f);
+ gl::vertex(-r, 0.0f, 0.0f);
- gl::vertex(0.0f,r/2,0.0f);
- gl::vertex(0.0f,-r/2,0.0f);
+ gl::vertex(0.0f, r / 2, 0.0f);
+ gl::vertex(0.0f, -r / 2, 0.0f);
- gl::vertex(0.0f,0.0f,r);
- gl::vertex(0.0f,0.0f,-r);
- gl::end();
+ gl::vertex(0.0f, 0.0f, r);
+ gl::vertex(0.0f, 0.0f, -r);
+ gl::end();
}
void draw_pass_default()
@@ -505,11 +505,11 @@ void draw_pass_default()
gl::disable(GL_LIGHTING);
}
- switch(entity->shape()) {
+ switch (entity->shape()) {
case core::Entity::Sphere:
draw_entity_sphere(entity);
break;
-
+
case core::Entity::Diamond:
draw_entity_diamond(entity);
break;
@@ -519,10 +519,10 @@ void draw_pass_default()
break;
case core::Entity::Cube:
-
- default:
- draw_entity_cube(entity);
- break;
+
+ default:
+ draw_entity_cube(entity);
+ break;
}
if (entity->flag_is_set(core::Entity::Bright)) {
@@ -557,7 +557,7 @@ void draw_fragment(model::Fragment *fragment, bool draw_details)
}
if (r_normals->value()) {
- gl::begin(gl::Lines );
+ gl::begin(gl::Lines);
gl::color(1.0f, 0.0f, 0.0f);
@@ -580,8 +580,8 @@ void draw_fragment(model::Fragment *fragment, bool draw_details)
}
void draw_model_fragments(model::Model *model,
- const math::Color & color_primary, const math::Color & color_secondary,
- const bool detail, const bool power, const float thrust)
+ const math::Color & color_primary, const math::Color & color_secondary,
+ const bool detail, const bool power, const float thrust)
{
// default material, lighted and geometry color
const model::Material *material = 0;
@@ -593,7 +593,7 @@ void draw_model_fragments(model::Model *model,
// TODO this should probably be initialized somewhere else
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+ glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
for (model::Model::Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) {
@@ -602,8 +602,8 @@ void draw_model_fragments(model::Model *model,
if (group->transform()) {
gl::push();
-
- gl::translate(group->location());
+
+ gl::translate(group->location());
if (group->type() == model::FragmentGroup::Rotate) {
float rotation_angle = math::degrees360f(core::application()->time() * group->speed());
@@ -611,57 +611,63 @@ void draw_model_fragments(model::Model *model,
} else {
gl::multmatrix(group->axis());
}
-
+
const float s = group->scale();
if (s)
gl::scale(s, s, s);
}
for (model::FragmentGroup::iterator fit = group->begin(); fit != group->end(); fit++) {
-
+
model::Fragment *fragment = (*fit);
-
+
if (fragment->material() != material) {
material = fragment->material();
-
+
if (material) {
if (material->flags() & model::Material::Engine) {
-
-/* if (use_color_array) {
+
+ /*
+ if (use_color_array) {
glDisableClientState(GL_COLOR_ARRAY);
use_color_array = false;
- }*/
-
+ }
+ */
color.assign(model->enginecolor() * thrust);
-
+
} else if (material->flags() & model::Material::Tertiary) {
-/* if (use_color_array) {
+ /*
+ if (use_color_array) {
use_color_array = false;
glDisableClientState(GL_COLOR_ARRAY);
- }*/
-
+ }
+ */
+
if ((material->flags() & model::Material::Tertiary) == model::Material::Tertiary) {
for (size_t i = 0; i < 3; i++)
color[i] = (color_primary[i] + color_secondary[i]) / 2;
-
+
} else if ((material->flags() & model::Material::Secondary) == model::Material::Secondary) {
color.assign(color_secondary);
-
- } if ((material->flags() & model::Material::Primary) == model::Material::Primary) {
+
+ }
+ if ((material->flags() & model::Material::Primary) == model::Material::Primary) {
color.assign(color_primary);
}
-
+
color.r *= material->color().r;
color.g *= material->color().g;
color.b *= material->color().b;
} else {
-/* if (!use_color_array) {
+ /*
+ if (!use_color_array) {
glEnableClientState(GL_COLOR_ARRAY);
use_color_array = true;
- }*/
+ }
+ */
color.assign(material->color());
}
-
+
if (power && (material->flags() & model::Material::Bright)) {
if (use_light) {
gl::disable(GL_LIGHTING);
@@ -691,7 +697,7 @@ void draw_model_fragments(model::Model *model,
}
if (material->flags() & model::Material::Environment) {
-
+
if (!(material->flags() & model::Material::Texture)) {
// use sky as envmap if the material defines no texture
if (core::localplayer()->zone()->sky_texture()) {
@@ -707,7 +713,7 @@ void draw_model_fragments(model::Model *model,
if (!use_env) {
// enable env mapping
gl::enable(GL_TEXTURE_GEN_S);
- gl::enable(GL_TEXTURE_GEN_T);
+ gl::enable(GL_TEXTURE_GEN_T);
use_env = true;
}
@@ -716,7 +722,7 @@ void draw_model_fragments(model::Model *model,
if (use_env) {
// disable env mapping
gl::disable(GL_TEXTURE_GEN_S);
- gl::disable(GL_TEXTURE_GEN_T);
+ gl::disable(GL_TEXTURE_GEN_T);
use_env = false;
}
}
@@ -730,7 +736,6 @@ void draw_model_fragments(model::Model *model,
} else {
// material not found
-
if (use_light) {
// disable lighting
gl::disable(GL_LIGHTING);
@@ -740,7 +745,7 @@ void draw_model_fragments(model::Model *model,
if (use_env) {
// disable env mapping
gl::disable(GL_TEXTURE_GEN_S);
- gl::disable(GL_TEXTURE_GEN_T);
+ gl::disable(GL_TEXTURE_GEN_T);
use_env = false;
}
@@ -749,14 +754,16 @@ void draw_model_fragments(model::Model *model,
use_texture = false;
}
-/* if (!use_color_array) {
+ /*
+ if (!use_color_array) {
glEnableClientState(GL_COLOR_ARRAY);
use_color_array = true;
- }*/
+ }
+ */
color.assign(1.0f, 0.0f, 1.0f);
}
}
-
+
gl::color(color);
draw_fragment(fragment, detail);
}
@@ -782,9 +789,11 @@ void draw_model_fragments(model::Model *model,
use_texture = false;
}
-/* if (!use_color_array) {
+ /*
+ if (!use_color_array) {
glEnableClientState(GL_COLOR_ARRAY);
- }*/
+ }
+ */
}
void draw_model_fragments(core::Entity *entity)
@@ -859,7 +868,7 @@ void draw_model_axis(const core::Entity *entity)
const float r = entity->radius() * 1.5f;
gl::begin(gl::Lines);
-
+
gl::color(entity->color());
gl::vertex(-r, 0.0f, 0.0f);
@@ -876,14 +885,14 @@ void draw_model_axis(const core::Entity *entity)
gl::color(1.0f, 0.0f, 0.0f);
gl::vertex(worldaxis.forward() * -1 * r);
- gl::vertex(worldaxis.forward() * r);
+ gl::vertex(worldaxis.forward() * r);
gl::vertex(worldaxis.left() * -1 * r);
gl::vertex(worldaxis.left() * r);
-
+
gl::vertex(worldaxis.up() * -1 * r);
gl::vertex(worldaxis.up() * r);
-
+
gl::end();
}
@@ -929,7 +938,7 @@ void draw_pass_model_fx(float elapsed)
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
-
+
power = true;
if ((entity->type() == core::Entity::Controlable) || (entity->type() == core::Entity::Dynamic)) {
@@ -942,17 +951,17 @@ void draw_pass_model_fx(float elapsed)
if (entity->model() && ext_render(entity)->detailvisible() && power) {
- // disable culling by default
+ // disable culling by default
gl::disable(GL_CULL_FACE);
model::Cull current_cull = model::CullNone;
-
+
// default light texture
size_t current_texture = Textures::bind("textures/fx/flare00");
gl::enable(GL_TEXTURE_2D);
-
+
gl::begin(gl::Quads);
- // draw model lights
+ // draw model lights
for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) {
model::Light *light = (*lit);
@@ -992,7 +1001,7 @@ void draw_pass_model_fx(float elapsed)
color.assign(light->color());
}
color.a = a;
-
+
location.assign(entity->location() + (entity->axis() * light->location()));
light_size = 0.0625f * light->radius();
@@ -1005,19 +1014,19 @@ void draw_pass_model_fx(float elapsed)
// draw the quad
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * light_size);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * light_size);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size);
Stats::quads++;
-
+
}
-
+
// draw flares
for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) {
model::Flare *flare = (*flit);
@@ -1074,7 +1083,7 @@ void draw_pass_model_fx(float elapsed)
gl::end();
if (current_texture != flare->texture()) {
- current_texture = Textures::bind(flare->texture());
+ current_texture = Textures::bind(flare->texture());
}
if (current_cull != flare->cull()) {
@@ -1101,14 +1110,14 @@ void draw_pass_model_fx(float elapsed)
// draw the quad
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size);
Stats::quads++;
@@ -1129,7 +1138,7 @@ void draw_pass_model_fx(float elapsed)
if (current_cull == model::CullNone) {
gl::enable(GL_CULL_FACE);
}
-
+
if (particlesystem->cull() == model::CullBack) {
gl::cullface(GL_BACK);
current_cull = model::CullBack;
@@ -1185,26 +1194,26 @@ void draw_pass_spacegrid()
gl::push();
gl::translate(Camera::target());
- gl::color(0,0, 1.0f);
+ gl::color(0, 0, 1.0f);
gl::normal(0, 0, 1.0f);
gl::begin(gl::Lines);
- for (int i=-gridsize; i <= gridsize; i++) {
- gl::color(0,0, 0, 0);
- gl::vertex(i-dx, -gridsize-dy, z);
- gl::color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
- gl::vertex(i-dx, -dy, z );
- gl::vertex(i-dx, -dy ,z );
- gl::color(0,0, 0, 0);
- gl::vertex(i-dx, gridsize-dy, z);
-
- gl::vertex(-gridsize-dx, i-dy, z );
- gl::color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
- gl::vertex(-dx, i-dy, z);
- gl::vertex(-dx, i-dy, z);
- gl::color(0,0, 0, 0);
- gl::vertex(gridsize-dx, i-dy, z);
+ for (int i = -gridsize; i <= gridsize; i++) {
+ gl::color(0, 0, 0, 0);
+ gl::vertex(i - dx, -gridsize - dy, z);
+ gl::color(0, 0, (gridsize - abs(i))*s, (gridsize - abs(i))*s);
+ gl::vertex(i - dx, -dy, z);
+ gl::vertex(i - dx, -dy , z);
+ gl::color(0, 0, 0, 0);
+ gl::vertex(i - dx, gridsize - dy, z);
+
+ gl::vertex(-gridsize - dx, i - dy, z);
+ gl::color(0, 0, (gridsize - abs(i))*s, (gridsize - abs(i))*s);
+ gl::vertex(-dx, i - dy, z);
+ gl::vertex(-dx, i - dy, z);
+ gl::color(0, 0, 0, 0);
+ gl::vertex(gridsize - dx, i - dy, z);
}
gl::end();
@@ -1227,7 +1236,7 @@ void draw(float seconds)
glPolygonMode(GL_FRONT, GL_FILL);
}
- // set vertex array pointers
+ // set vertex array pointers
glVertexPointer(3, GL_FLOAT, 0, core::game()->vertexarray()->vertex());
glNormalPointer(GL_FLOAT, 0, core::game()->vertexarray()->normal());
glTexCoordPointer(3, GL_FLOAT, 0, core::game()->vertexarray()->texture());
@@ -1239,7 +1248,7 @@ void draw(float seconds)
glEnableClientState(GL_NORMAL_ARRAY);
// glDisableClientState(GL_COLOR_ARRAY);
- gl::disable(GL_DEPTH_TEST);
+ gl::disable(GL_DEPTH_TEST);
gl::depthmask(GL_FALSE); // disable depth buffer writing
draw_pass_sky(); // draw the skysphere
@@ -1259,7 +1268,7 @@ void draw(float seconds)
}
gl::enable(GL_LIGHTING); // enable lighting
-
+
draw_pass_globes(); // draw globes
draw_pass_default(); // draw entities without model
@@ -1275,12 +1284,12 @@ void draw(float seconds)
// disable resaling of normals
gl::disable(GL_RESCALE_NORMAL);
}
-
+
gl::enable(GL_BLEND);
gl::depthmask(GL_FALSE); // disable depth buffer writing
-
+
draw_pass_spacegrid(); // draw the blue spacegrid
-
+
if (!core::localplayer()->view()) {
Dust::draw(zone_color); // draw spacedust
}
@@ -1299,10 +1308,10 @@ void draw(float seconds)
gl::enable(GL_RESCALE_NORMAL);
}
- gl::enable(GL_LIGHTING);
-
+ gl::enable(GL_LIGHTING);
+
draw_pass_model_radius();
-
+
gl::disable(GL_LIGHTING);
if (r_normalize && r_normalize->value()) {
@@ -1313,15 +1322,15 @@ void draw(float seconds)
gl::disable(GL_RESCALE_NORMAL);
}
}
-
+
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
+
gl::disable(GL_COLOR_MATERIAL); // disable color tracking
gl::disable(GL_CULL_FACE); // disable culling
-
+
gl::depthmask(GL_TRUE); // enable depth buffer writing
gl::disable(GL_DEPTH_TEST); // disable depth buffer testing
// GL_BLEND must be enabled for the GUI
@@ -1330,7 +1339,7 @@ void draw(float seconds)
// draw HUD target world space geometry, like dock indicators
void draw_target(core::Entity *entity)
{
- model::Model *model = entity->model();
+ model::Model *model = entity->model();
if (!model)
return;
@@ -1347,13 +1356,13 @@ void draw_target(core::Entity *entity)
gl::multmatrix(entity->axis());
gl::color(0, 1.0f, 1.0f, 1.0f);
-
+
for (model::Model::Docks::iterator dit = model->docks().begin(); dit != model->docks().end(); dit++) {
model::Dock *dock = (*dit);
math::Vector3f maxbox(dock->location());
math::Vector3f minbox(dock->location());
- for (size_t i=0; i < 3; i++) {
+ for (size_t i = 0; i < 3; i++) {
maxbox[i] += 0.025;
minbox[i] -= 0.025;
}
@@ -1365,7 +1374,7 @@ void draw_target(core::Entity *entity)
gl::vertex(minbox.x(), minbox.y(), maxbox.z());
gl::vertex(maxbox.x(), minbox.y(), maxbox.z());
gl::end();
-
+
// bottom
gl::begin(gl::LineLoop);
gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
@@ -1373,7 +1382,7 @@ void draw_target(core::Entity *entity)
gl::vertex(minbox.x(), minbox.y(), minbox.z());
gl::vertex(maxbox.x(), minbox.y(), minbox.z());
gl::end();
-
+
gl::begin(gl::Lines);
gl::vertex(maxbox.x(), maxbox.y(), maxbox.z());
gl::vertex(maxbox.x(), maxbox.y(), minbox.z());
diff --git a/src/render/draw.h b/src/render/draw.h
index 382d7cd..b13c7b0 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -1,7 +1,7 @@
/*
render/draw.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_DRAW_H__
@@ -12,7 +12,7 @@
#include "math/axis.h"
#include "math/vector3f.h"
-namespace render
+namespace render
{
/// draw the world
@@ -28,10 +28,11 @@ void draw_sphere(math::Color const & color, float radius);
/// draw a model
void draw_model_fragments(model::Model *model,
- const math::Color & color_primary, const math::Color & color_secondary,
- const bool detail = true, const bool power = true, const float thrust = 0.0f);
+ const math::Color & color_primary, const math::Color & color_secondary,
+ const bool detail = true, const bool power = true, const float thrust = 0.0f);
-class Stats {
+class Stats
+{
public:
static void clear();
diff --git a/src/render/dust.cc b/src/render/dust.cc
index a975e5f..cb8d84d 100644
--- a/src/render/dust.cc
+++ b/src/render/dust.cc
@@ -68,7 +68,7 @@ void Dust::draw(math::Color const &dustcolor)
dustsize = 0;
return;
}
-
+
if ((size_t) r_dustsize->value() != dustsize) {
con_debug << " changing dust size..." << std::endl;
if (dust) {
@@ -77,7 +77,7 @@ void Dust::draw(math::Color const &dustcolor)
}
dustsize = (size_t) r_dustsize->value();
}
-
+
if (dustsize <= 0) {
if (dust) {
free(dust);
@@ -96,16 +96,16 @@ void Dust::draw(math::Color const &dustcolor)
if (!dust) {
con_debug << " generating dust..." << std::endl;
- dust = (float *) malloc(sizeof(float) * dustsize* 3);
+ dust = (float *) malloc(sizeof(float) * dustsize * 3);
for (size_t i = 0; i < dustsize; i++) {
- dust[i*3] = core::localcontrol()->location().x() + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius() * 2.0f);
+ dust[i*3] = core::localcontrol()->location().x() + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius() * 2.0f);
dust[i*3+1] = core::localcontrol()->location().y() + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius() * 2.0f);
dust[i*3+2] = core::localcontrol()->location().z() + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius() * 2.0f);
}
}
-
-
+
+
traillength = math::max(math::max(core::localcontrol()->movement(), core::localcontrol()->speed() * 0.5f), 0.5f);
traillength = traillength * TRAILLENGHT / LOWSPEEDLIMIT;
@@ -113,7 +113,7 @@ void Dust::draw(math::Color const &dustcolor)
alpha = math::max(core::localcontrol()->movement(), core::localcontrol()->speed() * 0.5f);
math::clamp(alpha, 0.0f, 1.0f);
color.a = 0.25f * alpha;
-
+
gl::begin(gl::Lines);
gl::color(color);
math::Vector3f v;
@@ -127,11 +127,11 @@ void Dust::draw(math::Color const &dustcolor)
if (dsquare > (2.0f * core::localcontrol()->radius() + DUSTDISTANCE)*(2.0f * core::localcontrol()->radius() + DUSTDISTANCE)) {
for (size_t j = 0; j < 3; j++) {
- dust[i*3+j] = core::localcontrol()->location()[j] + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius() * 2.0f);
+ dust[i*3+j] = core::localcontrol()->location()[j] + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius() * 2.0f);
v[j] = dust[i*3+j] - core::localcontrol()->axis().forward()[j] * traillength;
}
}
-
+
glVertex3fv(&dust[i*3]);
gl::vertex(v);
}
diff --git a/src/render/gl.cc b/src/render/gl.cc
index 31c473f..355efab 100644
--- a/src/render/gl.cc
+++ b/src/render/gl.cc
@@ -1,13 +1,14 @@
/*
render/gl.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include "render/gl.h"
#include "math/matrix4f.h"
-namespace gl {
+namespace gl
+{
using math::Vector2f;
using math::Vector3f;
@@ -15,31 +16,32 @@ using math::Color;
std::string renderer()
{
- return std::string ((char *)glGetString(GL_RENDERER));
+ return std::string((char *)glGetString(GL_RENDERER));
}
std::string vendor()
{
- return std::string ((char *)glGetString(GL_VENDOR));
+ return std::string((char *)glGetString(GL_VENDOR));
}
std::string version()
{
- return std::string ((char *)glGetString(GL_VERSION));
+ return std::string((char *)glGetString(GL_VERSION));
}
std::string extensions()
{
- return std::string ((char *)glGetString(GL_EXTENSIONS));
+ return std::string((char *)glGetString(GL_EXTENSIONS));
}
-void begin(Primitive primitive)
-{
- ::glBegin(primitive);
+void begin(Primitive primitive)
+{
+ ::glBegin(primitive);
}
-void end() {
- ::glEnd();
+void end()
+{
+ ::glEnd();
}
void viewport(GLint x, GLint y, GLsizei width, GLsizei height)
@@ -74,79 +76,96 @@ void blendfunc(GLenum sfactor, GLenum dfactor)
}
void enable(GLenum cap)
-{
+{
glEnable(cap);
}
void disable(GLenum cap)
-{
+{
glDisable(cap);
}
-void clear (GLbitfield mask) {
+void clear(GLbitfield mask)
+{
glClear(mask);
}
-void clearcolor(Color const & color) {
+void clearcolor(Color const & color)
+{
glClearColor(color.red(), color.green(), color.blue(), color.alpha());
}
-void clearcolor(const float r, const float g, const float b, const float a) {
- glClearColor(r,g,b, a);
+void clearcolor(const float r, const float g, const float b, const float a)
+{
+ glClearColor(r, g, b, a);
}
-void rotate(const float angle, const Vector3f& vector) {
- glRotatef(angle, vector[0], vector[1], vector[2]);
+void rotate(const float angle, const Vector3f& vector)
+{
+ glRotatef(angle, vector[0], vector[1], vector[2]);
}
-void rotate(const float angle, const float x, const float y, const float z) {
- glRotatef(angle, x, y, z);
+void rotate(const float angle, const float x, const float y, const float z)
+{
+ glRotatef(angle, x, y, z);
}
-void translate(const Vector3f& vector) {
- glTranslatef(vector[0], vector[1], vector[2]);
+void translate(const Vector3f& vector)
+{
+ glTranslatef(vector[0], vector[1], vector[2]);
}
-void translate(const float x, const float y, const float z) {
- glTranslatef(x, y, z);
+void translate(const float x, const float y, const float z)
+{
+ glTranslatef(x, y, z);
}
-void scale(const Vector3f& vector) {
- glScalef(vector[0], vector[1], vector[2]);
+void scale(const Vector3f& vector)
+{
+ glScalef(vector[0], vector[1], vector[2]);
}
-void scale(const float x, const float y, const float z) {
- glScalef(x, y, z);
+void scale(const float x, const float y, const float z)
+{
+ glScalef(x, y, z);
}
-void vertex(const Vector2f& vector) {
+void vertex(const Vector2f& vector)
+{
glVertex2fv(vector.ptr());
}
-void vertex(const float x, const float y) {
+void vertex(const float x, const float y)
+{
glVertex2f(x, y);
}
-void vertex(const Vector3f& vector) {
+void vertex(const Vector3f& vector)
+{
glVertex3fv(vector.ptr());
}
-void vertex(const float x, const float y, const float z) {
+void vertex(const float x, const float y, const float z)
+{
glVertex3f(x, y, z);
}
-void normal(const Vector3f & vector) {
+void normal(const Vector3f & vector)
+{
glNormal3fv(vector.ptr());
}
-void normal(const float x, const float y, const float z) {
+void normal(const float x, const float y, const float z)
+{
glNormal3f(x, y, z);
}
-void push() {
+void push()
+{
glPushMatrix();
}
-void pop() {
+void pop()
+{
glPopMatrix();
}
@@ -161,22 +180,26 @@ void multmatrix(const math::Axis & axis)
glMultMatrixf(matrix.ptr());
}
-void color(const float r, const float g, const float b, const float a) {
- glColor4f(r,g,b,a);
+void color(const float r, const float g, const float b, const float a)
+{
+ glColor4f(r, g, b, a);
}
-void color(Color const & color) {
+void color(Color const & color)
+{
glColor4fv(color.ptr());
}
-void matrixmode(GLenum mode) {
+void matrixmode(GLenum mode)
+{
glMatrixMode(mode);
}
-void loadidentity() {
+void loadidentity()
+{
glLoadIdentity();
}
-void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar)
+void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar)
{
glFrustum(left, right, bottom, top, znear, zfar);
}
diff --git a/src/render/gl.h b/src/render/gl.h
index e182117..81c19b0 100644
--- a/src/render/gl.h
+++ b/src/render/gl.h
@@ -1,7 +1,7 @@
/*
render/gl.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_GL_H__
@@ -45,160 +45,160 @@
*/
namespace gl
{
- /// name of the hardware OpenGL renderer
- std::string renderer();
- /// vender of the system OpenGL implementation
- std::string vendor();
- /// version of the system OpenGL implementation
- std::string version();
- /// Opengl Extensions string
- std::string extensions();
-
- /// enum to denote Vertex drawing modes
- enum Primitive {
- Points=GL_POINTS,
- Lines=GL_LINES,
- LineStrip=GL_LINE_STRIP,
- LineLoop=GL_LINE_LOOP,
- Triangles=GL_TRIANGLES,
- TriangleStrip=GL_TRIANGLE_STRIP,
- TriangleFan=GL_TRIANGLE_FAN,
- Quads=GL_QUADS,
- QuadStrip=GL_QUAD_STRIP,
- Polygon=GL_POLYGON
- };
-
- /// glViewPort
- void viewport(GLint x, GLint y, GLsizei width, GLsizei height );
-
- /// set the color used to clear to buffer
- void clearcolor(math::Color const &color);
- void clearcolor(const float r, const float g, const float b, const float a);
-
- /// clear buffers to preset values
- void clear (GLbitfield mask);
-
- /// glMatrixMode
- void matrixmode(GLenum mode);
-
- /// glEnable
- void enable(GLenum cap);
-
- /// glDisable
- void disable(GLenum cap);
-
- /// glShadeModel
- void shademodel(GLenum mode);
-
- /// glCullFace
- void cullface(GLenum mode);
-
- /// glFrontFace
- void frontface(GLenum mode);
-
- /// glDepthMask
- void depthmask(GLenum mode);
-
- /// glBlendFunc
- void blendfunc(GLenum sfactor, GLenum dfactor);
-
- /// Delimite the start of a sequence of verteces describing a primitive or group of primitives
- /** @param primitive The type of drawing primitive
- * @see end()
- */
- void begin(Primitive primitive);
-
- /// delimit the end of a sequence of verteces describing a primitive or group of primitives
- /** @see begin()
- */
- void end();
-
- /// Add the next vertex the the current drawing operation
- /** From the glVertex() description:
- * vertex() commands are used within begin()/end() pairs to specify point,
- * line, and polygon vertices. The current color, normal, and texture
- * coordinates are associated with the vertex when vertex() is called.
- */
- void vertex(const math::Vector3f& vector);
-
- void vertex(const float x, const float y, const float z);
-
- void vertex(const math::Vector2f& vector);
-
- void vertex(const float x, const float y);
-
- /// 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]
- * @param vector The rotation axes, relative to the origin (0,0,0)
- */
- void rotate(const float angle, const math::Vector3f& vector);
-
- /// multiply the current matrix by a general rotation matrix
- /** @param angle The angle of the rotation, in degrees
- * @param x The x-coordinate of the rotation vector
- * @param y The y-coordinate of the rotation vector
- * @param z The z-coordinate of the rotation vector
- */
- void rotate(const float angle, const float x, const float y, const float z);
-
- /// multiply the current matrix by a general translation matrix
- /** @param vector The translation vector, relative to the origin (0,0,0)
- */
- void translate(const math::Vector3f& vector);
-
- /// multiply the current matrix by a general translation matrix
- /** @param x The x-coordinate of the translation vector
- * @param y The y-coordinate of the translation vector
- * @param z The z-coordinate of the translation vector
- */
- void translate(const float x, const float y, const float z);
-
- /// multiply the current matrix by a general scaling matrix
- /** @param vector The scale factor for all 3 axes
- */
- void scale(const math::Vector3f& vector);
-
- /// multiply the current matrix by a general scaling matrix
- /** @param x x-scaling factor
- * @param y y-scaling factor
- * @param z z-scaling factor
- */
- void scale(const float x, const float y, const float z);
-
- /// multiply the current matrix with a coordinate system transformation
- void multmatrix(const math::Axis & axis);
-
- /// multiply the current matrix with a 4x4 float matrix
- void multmatrix(const math::Matrix4f & matrix);
-
- /// specify the drawing color for the next GL functions
- /** @param color the new drawing color
- */
- void color(math::Color const & color);
-
- /** @param r red value of the new drawing color
- * @param g green value of the new drawing color
- * @param b blue value of the new drawing color
- * @param a alpha value of the new drawing color
- */
- void color(const float r, const float g, const float b, const float a=1.0f);
-
- /// Push the current transformation matrix to the stack
- void push();
-
- /// Replace the transformation matrix with the top from the stack
- void pop();
-
- /// Replace the transformation matrix with the identity matrtix
- void loadidentity();
-
- /// Perspective matrix
- void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar);
+/// name of the hardware OpenGL renderer
+std::string renderer();
+/// vender of the system OpenGL implementation
+std::string vendor();
+/// version of the system OpenGL implementation
+std::string version();
+/// Opengl Extensions string
+std::string extensions();
+
+/// enum to denote Vertex drawing modes
+enum Primitive {
+ Points = GL_POINTS,
+ Lines = GL_LINES,
+ LineStrip = GL_LINE_STRIP,
+ LineLoop = GL_LINE_LOOP,
+ Triangles = GL_TRIANGLES,
+ TriangleStrip = GL_TRIANGLE_STRIP,
+ TriangleFan = GL_TRIANGLE_FAN,
+ Quads = GL_QUADS,
+ QuadStrip = GL_QUAD_STRIP,
+ Polygon = GL_POLYGON
+};
+
+/// glViewPort
+void viewport(GLint x, GLint y, GLsizei width, GLsizei height);
+
+/// set the color used to clear to buffer
+void clearcolor(math::Color const &color);
+void clearcolor(const float r, const float g, const float b, const float a);
+
+/// clear buffers to preset values
+void clear(GLbitfield mask);
+
+/// glMatrixMode
+void matrixmode(GLenum mode);
+
+/// glEnable
+void enable(GLenum cap);
+
+/// glDisable
+void disable(GLenum cap);
+
+/// glShadeModel
+void shademodel(GLenum mode);
+
+/// glCullFace
+void cullface(GLenum mode);
+
+/// glFrontFace
+void frontface(GLenum mode);
+
+/// glDepthMask
+void depthmask(GLenum mode);
+
+/// glBlendFunc
+void blendfunc(GLenum sfactor, GLenum dfactor);
+
+/// Delimite the start of a sequence of verteces describing a primitive or group of primitives
+/** @param primitive The type of drawing primitive
+ * @see end()
+ */
+void begin(Primitive primitive);
+
+/// delimit the end of a sequence of verteces describing a primitive or group of primitives
+/** @see begin()
+ */
+void end();
+
+/// Add the next vertex the the current drawing operation
+/** From the glVertex() description:
+ * vertex() commands are used within begin()/end() pairs to specify point,
+ * line, and polygon vertices. The current color, normal, and texture
+ * coordinates are associated with the vertex when vertex() is called.
+ */
+void vertex(const math::Vector3f& vector);
+
+void vertex(const float x, const float y, const float z);
+
+void vertex(const math::Vector2f& vector);
+
+void vertex(const float x, const float y);
+
+/// 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]
+ * @param vector The rotation axes, relative to the origin (0,0,0)
+ */
+void rotate(const float angle, const math::Vector3f& vector);
+
+/// multiply the current matrix by a general rotation matrix
+/** @param angle The angle of the rotation, in degrees
+ * @param x The x-coordinate of the rotation vector
+ * @param y The y-coordinate of the rotation vector
+ * @param z The z-coordinate of the rotation vector
+ */
+void rotate(const float angle, const float x, const float y, const float z);
+
+/// multiply the current matrix by a general translation matrix
+/** @param vector The translation vector, relative to the origin (0,0,0)
+ */
+void translate(const math::Vector3f& vector);
+
+/// multiply the current matrix by a general translation matrix
+/** @param x The x-coordinate of the translation vector
+ * @param y The y-coordinate of the translation vector
+ * @param z The z-coordinate of the translation vector
+ */
+void translate(const float x, const float y, const float z);
+
+/// multiply the current matrix by a general scaling matrix
+/** @param vector The scale factor for all 3 axes
+ */
+void scale(const math::Vector3f& vector);
+
+/// multiply the current matrix by a general scaling matrix
+/** @param x x-scaling factor
+ * @param y y-scaling factor
+ * @param z z-scaling factor
+ */
+void scale(const float x, const float y, const float z);
+
+/// multiply the current matrix with a coordinate system transformation
+void multmatrix(const math::Axis & axis);
+
+/// multiply the current matrix with a 4x4 float matrix
+void multmatrix(const math::Matrix4f & matrix);
+
+/// specify the drawing color for the next GL functions
+/** @param color the new drawing color
+ */
+void color(math::Color const & color);
+
+/** @param r red value of the new drawing color
+ * @param g green value of the new drawing color
+ * @param b blue value of the new drawing color
+ * @param a alpha value of the new drawing color
+ */
+void color(const float r, const float g, const float b, const float a = 1.0f);
+
+/// Push the current transformation matrix to the stack
+void push();
+
+/// Replace the transformation matrix with the top from the stack
+void pop();
+
+/// Replace the transformation matrix with the identity matrtix
+void loadidentity();
+
+/// Perspective matrix
+void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar);
}
#endif // __INCLUDED_RENDER_GL_H__
diff --git a/src/render/image.cc b/src/render/image.cc
index 196eec9..98898ef 100644
--- a/src/render/image.cc
+++ b/src/render/image.cc
@@ -1,7 +1,7 @@
/*
render/image.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include <stdlib.h>
@@ -9,7 +9,7 @@
#include "render/image.h"
-namespace render
+namespace render
{
Image::Image(unsigned int width, unsigned int height, unsigned int channels)
@@ -34,7 +34,7 @@ void Image::clear()
void Image::swap_channels()
{
- for (size_t y =0; y < image_height; y++) {
+ for (size_t y = 0; y < image_height; y++) {
for (size_t x = 0; x < image_width; x++) {
size_t offset = y * image_width * image_channels + x * image_channels;
unsigned char tmp = image_data[offset];
@@ -52,7 +52,7 @@ void Image::pad()
if ((w % 8) != 0) {
image_width = w + (8 - (w % 8));
}
-
+
if ((w % 8) != 0) {
image_height = h + (8 - (h % 8));
}
@@ -60,9 +60,9 @@ void Image::pad()
unsigned char *image_new = (unsigned char *) malloc(size());
memset(image_new, 0, size());
- for (size_t y =0; y < h; y++) {
+ for (size_t y = 0; y < h; y++) {
memcpy((void *)&image_new[y * image_width * image_channels],
- (void *)&image_data[y * w * image_channels], (size_t) w);
+ (void *)&image_data[y * w * image_channels], (size_t) w);
}
free(image_data);
@@ -72,16 +72,16 @@ void Image::pad()
void Image::flip()
{
unsigned char line[image_width*image_channels];
- for (size_t y=0; y < image_height /2; y++) {
+ for (size_t y = 0; y < image_height / 2; y++) {
memcpy(line,
- &image_data[y*image_width*image_channels],
- image_width*image_channels);
+ &image_data[y*image_width*image_channels],
+ image_width*image_channels);
memcpy(&image_data[y*image_width*image_channels],
- &image_data[(image_height-1-y)*image_width*image_channels],
- image_width*image_channels);
+ &image_data[(image_height-1-y)*image_width*image_channels],
+ image_width*image_channels);
memcpy(&image_data[(image_height-1-y)*image_width*image_channels],
- line,
- image_width*image_channels);
+ line,
+ image_width*image_channels);
}
}
diff --git a/src/render/image.h b/src/render/image.h
index c7add6f..244948e 100644
--- a/src/render/image.h
+++ b/src/render/image.h
@@ -1,7 +1,7 @@
/*
render/image.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_IMAGE_H__
@@ -9,34 +9,50 @@
#include <string>
-namespace render {
+namespace render
+{
/// RGB (24bpp) or RGBA (32bpp) image data
-class Image {
+class Image
+{
public:
Image(unsigned int width, unsigned int height, unsigned int channels);
~Image();
/// pointer to the raw image data
- inline unsigned char *data() { return image_data; }
+ inline unsigned char *data() {
+ return image_data;
+ }
/// index into the raw image data
- inline unsigned char *operator[](size_t index) { return &image_data[index]; }
+ inline unsigned char *operator[](size_t index) {
+ return &image_data[index];
+ }
/// width of the image in pixels
- inline unsigned int width() const { return image_width; }
+ inline unsigned int width() const {
+ return image_width;
+ }
/// height of the image in pixels
- inline unsigned int height() const { return image_height; }
+ inline unsigned int height() const {
+ return image_height;
+ }
/// size of the image data in bytes
- inline size_t size() const { return ((size_t) image_width * (size_t) image_height * (size_t) image_channels); }
+ inline size_t size() const {
+ return ((size_t) image_width *(size_t) image_height *(size_t) image_channels);
+ }
/// number of channels 3 (RGB) or 4 (RGBA)
- inline unsigned int channels() const { return image_channels; }
+ inline unsigned int channels() const {
+ return image_channels;
+ }
/// bits per pixel
- inline unsigned int bpp() const { return (image_channels * 8); }
+ inline unsigned int bpp() const {
+ return (image_channels * 8);
+ }
/// set image data to zero
void clear();
diff --git a/src/render/jpgfile.cc b/src/render/jpgfile.cc
index 5ed3ff8..890c543 100644
--- a/src/render/jpgfile.cc
+++ b/src/render/jpgfile.cc
@@ -23,14 +23,15 @@ http://www.zarb.org/~gc/html/libpng.html
#undef HAVE_STDLIB_H
#endif
extern "C" {
- #include "jpeglib.h"
+#include "jpeglib.h"
}
-namespace render {
+namespace render
+{
Image *JPG::load(const char *filename)
{
- struct jpeg_decompress_struct jpeg_decompression_info;
+ struct jpeg_decompress_struct jpeg_decompression_info;
struct jpeg_error_mgr jerr;
int row_stride = 0;
@@ -44,20 +45,20 @@ Image *JPG::load(const char *filename)
//con_warn << "Could not open " << filename << std::endl;
return 0;
}
-
+
// initialize decompression structures
jpeg_decompression_info.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&jpeg_decompression_info);
- jpeg_stdio_src(&jpeg_decompression_info, jpg_file->handle());
+ jpeg_stdio_src(&jpeg_decompression_info, jpg_file->handle());
// read JPEG header
jpeg_read_header(&jpeg_decompression_info, TRUE);
jpeg_start_decompress(&jpeg_decompression_info);
row_stride = jpeg_decompression_info.output_width * jpeg_decompression_info.output_components;
- image = new Image(jpeg_decompression_info.output_width,
- jpeg_decompression_info.output_height,
- jpeg_decompression_info.output_components);
+ image = new Image(jpeg_decompression_info.output_width,
+ jpeg_decompression_info.output_height,
+ jpeg_decompression_info.output_components);
// read pixel data
JSAMPLE *row_pointer;
@@ -65,11 +66,11 @@ Image *JPG::load(const char *filename)
row_pointer = (*image)[jpeg_decompression_info.output_scanline*row_stride];
jpeg_read_scanlines(&jpeg_decompression_info, &row_pointer, 1);
}
- jpeg_finish_decompress(&jpeg_decompression_info);
+ jpeg_finish_decompress(&jpeg_decompression_info);
// destroy decompression structures
jpeg_destroy_decompress(&jpeg_decompression_info);
- filesystem::close(jpg_file);
+ filesystem::close(jpg_file);
con_debug << " " << filename << " " << image->width() << "x" << image->height() << "x" << image->bpp() << "bpp" << std::endl;
return image;
@@ -83,10 +84,10 @@ void JPG::save(const char *filename, Image & image, int jpeg_quality)
JSAMPROW row_pointer[1];
int row_stride;
- FILE *jpg_file = fopen(filename, "wb");
- if (!jpg_file) {
- con_warn << "Could not write " << filename << std::endl;
- return;
+ FILE *jpg_file = fopen(filename, "wb");
+ if (!jpg_file) {
+ con_warn << "Could not write " << filename << std::endl;
+ return;
}
jpeg_compression_info.err = jpeg_std_error(&jerr);
diff --git a/src/render/jpgfile.h b/src/render/jpgfile.h
index 858a8a3..feb03b9 100644
--- a/src/render/jpgfile.h
+++ b/src/render/jpgfile.h
@@ -14,11 +14,12 @@ namespace render
{
/// a class for loading and saving .jpg files
-class JPG {
+class JPG
+{
public:
/// load a JPG image file from disk
- /** @param filename short path to the filename to be loaded
+ /** @param filename short path to the filename to be loaded
*/
static Image *load(const char * filename);
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 13b69a4..6ffcd35 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -12,7 +12,8 @@
#include "render/textures.h"
#include "core/application.h"
-namespace render {
+namespace render
+{
/* ---- class Particle --------------------------------------------- */
@@ -35,7 +36,7 @@ void ParticleScript::list()
{
std::string str;
for (Registry::iterator it = particles_registry.begin(); it != particles_registry.end(); it++) {
-
+
ParticleScript *script = (*it).second;
switch (script->type()) {
case Flame:
@@ -59,16 +60,16 @@ void ParticleScript::list()
void ParticleScript::clear()
{
for (Registry::iterator it = particles_registry.begin(); it != particles_registry.end(); it++) {
- delete (*it).second;
+ delete(*it).second;
(*it).second = 0;
}
- particles_registry.clear();
+ particles_registry.clear();
}
ParticleScript *ParticleScript::find(const std::string &label)
{
Registry::iterator it = particles_registry.find(label);
-
+
if (it != particles_registry.end()) {
return (*it).second;
} else {
@@ -195,7 +196,7 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, mod
particlesystem_radius = modelclass->radius();
else
particlesystem_radius = particlesystem_script->radius();
-
+
color.assign(particlesystem_script->color());
}
@@ -220,7 +221,7 @@ ParticleSystem::~ParticleSystem()
void ParticleSystem::clear()
{
for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
- delete (*it);
+ delete(*it);
}
particlesystem_stream.clear();
}
@@ -242,7 +243,7 @@ void ParticleSystem::draw(float elapsed)
// remove dead particles
Stream::reverse_iterator it = particlesystem_stream.rbegin();
while ((it != particlesystem_stream.rend()) && ((*it)->time() + particlesystem_script->timeout() <= now)) {
- delete (*particlesystem_stream.rbegin());
+ delete(*particlesystem_stream.rbegin());
particlesystem_stream.pop_back();
it = particlesystem_stream.rbegin();
}
@@ -279,13 +280,15 @@ void ParticleSystem::draw(float elapsed)
/* ---- class Jet -------------------------------------------------- */
Jet::Jet(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Jet::~Jet()
{}
-void Jet::draw(float elapsed) {
+void Jet::draw(float elapsed)
+{
if (!particlesystem_script)
return;
@@ -299,12 +302,12 @@ void Jet::draw(float elapsed) {
for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
Particle *particle = (*it);
-
+
quad[0].assign(particle->axis().up() - particle->axis().left());
quad[1].assign(particle->axis().up() + particle->axis().left());
quad[2].assign(particle->axis().up() * -1 + particle->axis().left());
quad[3].assign(particle->axis().up() * -1 - particle->axis().left());
-
+
float t = now - particle->time();
float f = 0;
@@ -320,14 +323,14 @@ void Jet::draw(float elapsed) {
float radius = particlesystem_radius * f;
color.a = f * particlesystem_script->alpha();
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex(particle->location() + quad[0] * radius);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(particle->location() + quad[1] * radius);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(particle->location() + quad[2] * radius);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex(particle->location() + quad[3] * radius);
Stats::quads++;
}
@@ -338,13 +341,15 @@ void Jet::draw(float elapsed) {
/* ---- class Spray ------------------------------------------------ */
Spray::Spray(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Spray::~Spray()
{}
-void Spray::draw(float elapsed) {
+void Spray::draw(float elapsed)
+{
if (!particlesystem_script)
return;
@@ -358,12 +363,12 @@ void Spray::draw(float elapsed) {
for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
Particle *particle = (*it);
-
+
quad[0].assign(Camera::axis().up() - Camera::axis().left());
quad[1].assign(Camera::axis().up() + Camera::axis().left());
quad[2].assign(Camera::axis().up() * -1 + Camera::axis().left());
quad[3].assign(Camera::axis().up() * -1 - Camera::axis().left());
-
+
float t = now - particle->time();
float f = 0;
@@ -379,14 +384,14 @@ void Spray::draw(float elapsed) {
float radius = particlesystem_radius * f;
color.a = f * particlesystem_script->alpha();
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex(particle->location() + quad[0] * radius);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(particle->location() + quad[1] * radius);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(particle->location() + quad[2] * radius);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex(particle->location() + quad[3] * radius);
Stats::quads++;
}
@@ -399,22 +404,24 @@ void Spray::draw(float elapsed) {
/* ---- class Trail ------------------------------------------------ */
Trail::Trail(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Trail::~Trail()
{}
-void Trail::draw(float elapsed) {
+void Trail::draw(float elapsed)
+{
if (!particlesystem_script)
return;
- ParticleSystem::draw(elapsed);
+ ParticleSystem::draw(elapsed);
if (particlesystem_stream.size()) {
Textures::bind(particlesystem_texture);
-
+
gl::begin(gl::Quads);
Stream::iterator first = particlesystem_stream.begin();
@@ -434,18 +441,18 @@ void Trail::draw(float elapsed) {
if (tp > 0) {
color.a = 0.0f;
gl::color(color);
-
- glTexCoord2f(1,0);
+
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
-
+
color.a = fp;
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
Stats::quads++;
}
@@ -468,17 +475,17 @@ void Trail::draw(float elapsed) {
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,1);
+ glTexCoord2f(0, 1);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * f);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * f);
Stats::quads++;
@@ -496,21 +503,23 @@ void Trail::draw(float elapsed) {
/* ---- class Flame ------------------------------------------------ */
Flame::Flame(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Flame::~Flame()
{}
-void Flame::draw(float elapsed) {
+void Flame::draw(float elapsed)
+{
if (!particlesystem_script)
return;
- ParticleSystem::draw(elapsed);
+ ParticleSystem::draw(elapsed);
if (particlesystem_stream.size() > 1) {
-
+
Textures::bind(particlesystem_texture);
gl::begin(gl::Quads);
@@ -532,61 +541,61 @@ void Flame::draw(float elapsed) {
if (tp > 0) {
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * fp);
Stats::quads++;
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * fp);
Stats::quads++;
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * fp);
Stats::quads++;
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * fp);
Stats::quads++;
}
@@ -607,61 +616,61 @@ void Flame::draw(float elapsed) {
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() + (*first)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * f);
Stats::quads++;
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() + (*first)->axis().up() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * f);
Stats::quads++;
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() - (*first)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * f);
Stats::quads++;
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() - (*first)->axis().up() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * f);
Stats::quads++;
diff --git a/src/render/particles.h b/src/render/particles.h
index cf0f5eb..15e9827 100644
--- a/src/render/particles.h
+++ b/src/render/particles.h
@@ -15,22 +15,30 @@
#include "core/entity.h"
#include "model/parts.h"
-namespace render {
+namespace render
+{
/* ---- class Particle --------------------------------------------- */
/// one particle
-class Particle {
+class Particle
+{
public:
Particle(const math::Vector3f &location, float time);
Particle(const math::Vector3f &location, const math::Axis &axis, float time);
/// location of the particle, in world coordinates
- inline math::Vector3f &location() { return particle_location; }
+ inline math::Vector3f &location() {
+ return particle_location;
+ }
- inline math::Axis &axis() { return particle_axis; }
+ inline math::Axis &axis() {
+ return particle_axis;
+ }
- inline const float time() const { return particle_time; }
+ inline const float time() const {
+ return particle_time;
+ }
protected:
math::Vector3f particle_location;
@@ -42,31 +50,52 @@ protected:
/* ---- class ParticleScript --------------------------------------- */
/// class to hold particle scripts
-class ParticleScript {
+class ParticleScript
+{
public:
- enum Type {Jet=0, Trail=1, Flame=2, Spray=3 };
+ enum Type {Jet = 0, Trail = 1, Flame = 2, Spray = 3 };
+
+ inline const Type type() const {
+ return particles_type;
+ }
- inline const Type type() const { return particles_type; }
+ inline const std::string &label() const {
+ return particles_label;
+ }
- inline const std::string &label() const { return particles_label; }
+ inline const std::string &texture() const {
+ return particles_texture;
+ }
- inline const std::string &texture() const { return particles_texture; }
+ inline const math::Color &color() const {
+ return particles_color;
+ }
- inline const math::Color &color() const { return particles_color; }
+ inline float radius() const {
+ return particles_radius;
+ }
- inline float radius() const { return particles_radius; }
+ inline float timeout() const {
+ return particles_timeout;
+ }
- inline float timeout() const { return particles_timeout; }
+ inline float eject() const {
+ return particles_eject;
+ }
- inline float eject() const { return particles_eject; }
+ inline float speed() const {
+ return particles_speed;
+ }
- inline float speed() const { return particles_speed; }
+ inline float alpha() const {
+ return particles_alpha;
+ }
- inline float alpha() const { return particles_alpha; }
+ inline float offset() const {
+ return particles_offset;
+ }
- inline float offset() const { return particles_offset; }
-
static ParticleScript *load(const std::string &label);
static void clear();
@@ -81,8 +110,8 @@ private:
std::string particles_label;
std::string particles_texture;
Type particles_type;
- math::Color particles_color;
-
+ math::Color particles_color;
+
float particles_radius;
float particles_timeout;
float particles_eject;
@@ -98,21 +127,30 @@ private:
/* ---- class ParticleSystem --------------------------------------- */
/// abstract base class for a particle system attached to an entity
-class ParticleSystem {
+class ParticleSystem
+{
public:
ParticleSystem(ParticleScript *script, core::Entity *entity, model::Particles *modelclass);
virtual ~ParticleSystem();
/// index of the texture to use
- inline const size_t texture() const { return particlesystem_texture; }
+ inline const size_t texture() const {
+ return particlesystem_texture;
+ }
/// location of the particle system within the entity
- inline const math::Vector3f &location() const { return particlesystem_location; }
+ inline const math::Vector3f &location() const {
+ return particlesystem_location;
+ }
/// axis of the particle system within the entity
- inline const math::Axis &axis() const { return particlesystem_axis; }
+ inline const math::Axis &axis() const {
+ return particlesystem_axis;
+ }
- inline const model::Cull cull() const { return particlesystem_cull; }
+ inline const model::Cull cull() const {
+ return particlesystem_cull;
+ }
virtual void draw(float elapsed);
@@ -125,16 +163,18 @@ public:
protected:
core::Entity *particlesystem_entity;
-
+
typedef std::deque<Particle *> Stream;
- inline Stream & stream() { return particlesystem_stream; }
+ inline Stream & stream() {
+ return particlesystem_stream;
+ }
size_t particlesystem_texture;
math::Axis particlesystem_axis;
math::Vector3f particlesystem_location;
-
+
float particlesystem_last_eject;
ParticleScript *particlesystem_script;
@@ -146,11 +186,11 @@ protected:
float particlesystem_radius;
float now;
math::Color color;
-
+
model::Particles *particlesystem_modelclass;
model::Cull particlesystem_cull;
};
-
+
/* ---- class Flame ------------------------------------------------ */
/// flame style particles, like engine flames
@@ -159,7 +199,7 @@ class Flame : public ParticleSystem
public:
Flame(ParticleScript *script, core::Entity *entity, model::Particles *modelclass);
virtual ~Flame();
-
+
virtual void draw(float elapsed);
};
@@ -171,7 +211,7 @@ class Jet : public ParticleSystem
public:
Jet(ParticleScript *script, core::Entity *entity, model::Particles *modelclass);
virtual ~Jet();
-
+
virtual void draw(float elapsed);
};
@@ -183,7 +223,7 @@ class Spray : public ParticleSystem
public:
Spray(ParticleScript *script, core::Entity *entity, model::Particles *modelclass);
virtual ~Spray();
-
+
virtual void draw(float elapsed);
};
diff --git a/src/render/pngfile.cc b/src/render/pngfile.cc
index d011aff..da434db 100644
--- a/src/render/pngfile.cc
+++ b/src/render/pngfile.cc
@@ -21,7 +21,8 @@ http://www.zarb.org/~gc/html/libpng.html
#include "render/pngfile.h"
#include "sys/sys.h"
-namespace render {
+namespace render
+{
Image *PNG::load(const char *filename)
{
@@ -58,14 +59,14 @@ Image *PNG::load(const char *filename)
}
png_infop info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
- con_warn << "Error reading " << filename << ": png_create_info_struct failed!" << std::endl;
+ if (!info_ptr) {
+ con_warn << "Error reading " << filename << ": png_create_info_struct failed!" << std::endl;
filesystem::close(png_file);
png_destroy_read_struct(&png_ptr, 0, 0);
return 0;
}
- if (setjmp(png_jmpbuf(png_ptr))) {
- con_warn << "Error reading " << filename << ": error during init_io!" << std::endl;
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ con_warn << "Error reading " << filename << ": error during init_io!" << std::endl;
filesystem::close(png_file);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
return 0;
@@ -73,19 +74,19 @@ Image *PNG::load(const char *filename)
/* read the PNG header */
png_init_io(png_ptr, png_file->handle());
- png_set_sig_bytes(png_ptr, 8);
+ png_set_sig_bytes(png_ptr, 8);
- png_read_info(png_ptr, info_ptr);
+ png_read_info(png_ptr, info_ptr);
- int png_width = info_ptr->width;
- int png_height = info_ptr->height;
- //int png_color_type = info_ptr->color_type;
- int png_depth = info_ptr->bit_depth;
+ int png_width = info_ptr->width;
+ int png_height = info_ptr->height;
+ //int png_color_type = info_ptr->color_type;
+ int png_depth = info_ptr->bit_depth;
- //int number_of_passes = png_set_interlace_handling(png_ptr);
+ //int number_of_passes = png_set_interlace_handling(png_ptr);
png_set_interlace_handling(png_ptr);
- png_read_update_info(png_ptr, info_ptr);
-
+ png_read_update_info(png_ptr, info_ptr);
+
if (png_depth != 8) {
con_warn << "Error reading " << filename << ": bits per channel must be 8!" << std::endl;
filesystem::close(png_file);
@@ -97,7 +98,7 @@ Image *PNG::load(const char *filename)
image = new Image(png_width, png_height, channels);
/* read image data */
- if (setjmp(png_jmpbuf(png_ptr))) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error reading " << filename << std::endl;
filesystem::close(png_file);
delete image;
@@ -107,13 +108,13 @@ Image *PNG::load(const char *filename)
png_bytep row_pointers[png_height];
- for (size_t i=0; i < (size_t)png_height; i++)
- row_pointers[i] = (png_bytep) (*image)[i * info_ptr->rowbytes];
+ for (size_t i = 0; i < (size_t)png_height; i++)
+ row_pointers[i] = (png_bytep)(*image)[i * info_ptr->rowbytes];
// read pixel data
- png_read_image(png_ptr, row_pointers);
+ png_read_image(png_ptr, row_pointers);
- filesystem::close(png_file);
+ filesystem::close(png_file);
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
con_debug << " " << filename << " " << image->width() << "x" << image->height() << "x" << image->bpp() << "bpp" << std::endl;
@@ -123,50 +124,50 @@ Image *PNG::load(const char *filename)
void PNG::save(const char *filename, Image & image)
{
- FILE *png_file = fopen(filename, "wb");
- if (!png_file) {
- con_warn << "Could not write " << filename << std::endl;
- return;
+ FILE *png_file = fopen(filename, "wb");
+ if (!png_file) {
+ con_warn << "Could not write " << filename << std::endl;
+ return;
}
- png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr) {
+ png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_ptr) {
fclose(png_file);
con_warn << "Error writing " << filename << ": png_create_write_struct failed!" << std::endl;
return;
}
- png_infop info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr) {
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
con_warn << "Error writing " << filename << ": png_create_info_struct failed!" << std::endl;
fclose(png_file);
png_destroy_write_struct(&png_ptr, 0);
return;
}
- if (setjmp(png_jmpbuf(png_ptr))) {
+ if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error reading " << filename << ": error during init_io!" << std::endl;
fclose(png_file);
png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
- png_init_io(png_ptr, png_file);
+ png_init_io(png_ptr, png_file);
- /* write header */
- if (setjmp(png_jmpbuf(png_ptr))) {
+ /* write header */
+ if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error writing " << filename << ": error writing header!" << std::endl;
fclose(png_file);
png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
- png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(), 8, PNG_COLOR_TYPE_RGB,
- PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+ png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(), 8, PNG_COLOR_TYPE_RGB,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
- png_write_info(png_ptr, info_ptr);
+ png_write_info(png_ptr, info_ptr);
- /* write image data */
+ /* write image data */
if (setjmp(png_jmpbuf(png_ptr))) {
con_warn << "Error writing " << filename << ": error writing header!" << std::endl;
fclose(png_file);
@@ -176,8 +177,8 @@ void PNG::save(const char *filename, Image & image)
png_bytep row_pointers[image.height()];
- for (size_t i = 0; i < image.height(); i++)
- row_pointers[i] = (png_bytep) image[i * image.width() * image.channels()];
+ for (size_t i = 0; i < image.height(); i++)
+ row_pointers[i] = (png_bytep) image[i * image.width() * image.channels()];
png_write_image(png_ptr, row_pointers);
@@ -189,9 +190,9 @@ void PNG::save(const char *filename, Image & image)
return;
}
- png_write_end(png_ptr, NULL);
+ png_write_end(png_ptr, NULL);
- fclose(png_file);
+ fclose(png_file);
png_destroy_write_struct(&png_ptr, &info_ptr);
con_print << "Wrote " << filename << std::endl;
diff --git a/src/render/pngfile.h b/src/render/pngfile.h
index 4559f70..96e9ab6 100644
--- a/src/render/pngfile.h
+++ b/src/render/pngfile.h
@@ -14,11 +14,12 @@ namespace render
{
/// a class for loading and saving .png files
-class PNG {
+class PNG
+{
public:
/// load a PNG image file from disk
- /** @param filename short path to the filename to be loaded
+ /** @param filename short path to the filename to be loaded
*/
static Image *load(const char * filename);
diff --git a/src/render/render.cc b/src/render/render.cc
index 12445a6..03c5c87 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -1,7 +1,7 @@
/*
render/render.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include <iostream>
@@ -24,7 +24,8 @@
#include "render/textures.h"
#include "sys/sys.h"
-namespace render {
+namespace render
+{
core::Cvar *r_axis = 0;
core::Cvar *r_bbox = 0;
@@ -53,7 +54,7 @@ void func_list_particles(std::string const &args)
ParticleScript::list();
}
-void init(int width, int height)
+void init(int width, int height)
{
con_print << "^BInitializing renderer..." << std::endl;
@@ -148,8 +149,8 @@ void unload()
for (core::Entity::Registry::iterator it = core::Entity::registry().begin(); it != core::Entity::registry().end(); it++) {
core:: Entity *entity = (*it).second;
-
- if (entity->type() == core::Entity::Globe) {
+
+ if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
if (globe->render_texture) {
render::Textures::unload(globe->render_texture);
@@ -179,7 +180,7 @@ void clear()
if (entity->model())
entity->set_model(0);
- if (entity->type() == core::Entity::Globe) {
+ if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
globe->render_texture = 0;
}
diff --git a/src/render/render.h b/src/render/render.h
index 17ba42c..4d2e9c2 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -1,7 +1,7 @@
/*
render/render.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_H__
@@ -19,50 +19,54 @@
#include "render/textures.h"
#include "render/renderext.h"
-namespace render {
+namespace render
+{
- /// initialize the render subsystem
- void init(int width, int height);
+/// initialize the render subsystem
+void init(int width, int height);
- /// shutdown the render subsystem
- void shutdown();
+/// shutdown the render subsystem
+void shutdown();
- /// reset all render data
- void reset();
+/// reset all render data
+void reset();
- /// load game render data
- void load();
+/// load game render data
+void load();
- /// unload game render data
- void unload();
+/// unload game render data
+void unload();
- /// resize viewport
- void resize(int width, int height);
+/// resize viewport
+void resize(int width, int height);
- /// render entity axis
- extern core::Cvar *r_axis;
- /// render model bounding boxes
- extern core::Cvar *r_bbox;
- /// render the spacegrid
- extern core::Cvar *r_grid;
- /// render particle systems
- extern core::Cvar *r_particles;
- /// render entity radius
- extern core::Cvar *r_radius;
- /// render sky
- extern core::Cvar *r_sky;
- /// render wireframe models
- extern core::Cvar *r_wireframe;
- /// render vertex normals
- extern core::Cvar *r_normals;
- /// render collision
- extern core::Cvar *r_collision;
- /// use hardware generated mipmaps (requires OpenGL 1.4, does not work on all cards)
- extern core::Cvar *r_mipmap;
- /// use GL_NORMALIZE instead of GL_RESCALE_NORMAL
- extern core::Cvar *r_normalize;
+/// render entity axis
+extern core::Cvar *r_axis;
+/// render model bounding boxes
+extern core::Cvar *r_bbox;
+/// render the spacegrid
+extern core::Cvar *r_grid;
+/// render particle systems
+extern core::Cvar *r_particles;
+/// render entity radius
+extern core::Cvar *r_radius;
+/// render sky
+extern core::Cvar *r_sky;
+/// render wireframe models
+extern core::Cvar *r_wireframe;
+/// render vertex normals
+extern core::Cvar *r_normals;
+/// render collision
+extern core::Cvar *r_collision;
+/// use hardware generated mipmaps (requires OpenGL 1.4, does not work on all cards)
+extern core::Cvar *r_mipmap;
+/// use GL_NORMALIZE instead of GL_RESCALE_NORMAL
+extern core::Cvar *r_normalize;
- inline RenderExt *ext_render(const core::Entity *entity) { return static_cast<RenderExt *>(entity->extension((size_t)core::Extension::Render)); }
+inline RenderExt *ext_render(const core::Entity *entity)
+{
+ return static_cast<RenderExt *>(entity->extension((size_t)core::Extension::Render));
+}
}
diff --git a/src/render/renderext.cc b/src/render/renderext.cc
index b743686..989a892 100644
--- a/src/render/renderext.cc
+++ b/src/render/renderext.cc
@@ -53,10 +53,10 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
flare->set_texture(Textures::load(flarename.str()));
}
- for(model::Model::ParticleSystems::iterator pit = model->particles().begin(); pit != model->particles().end(); pit++) {
+ for (model::Model::ParticleSystems::iterator pit = model->particles().begin(); pit != model->particles().end(); pit++) {
model::Particles *particlesystem = (*pit);
- // load particle systems
+ // load particle systems
ParticleScript *script = ParticleScript::load(particlesystem->script());
if (script) {
if (script->type() == render::ParticleScript::Trail) {
@@ -74,8 +74,8 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
}
}
}
-
- } else if (entity->type() == core::Entity::Globe) {
+
+ } else if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
// load globe textures
@@ -92,7 +92,7 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
RenderExt::~RenderExt()
{
for (ParticleSystems::iterator it = state_particles.begin(); it != state_particles.end(); it++) {
- delete (*it);
+ delete(*it);
}
state_particles.clear();
}
@@ -139,7 +139,7 @@ void RenderExt::frame(float elapsed)
state_visible = true;
state_detailvisible = false;
}
-
+
} else {
// entity out of range
state_visible = false;
@@ -151,7 +151,7 @@ void RenderExt::frame(float elapsed)
state_behind = true;
}
-
+
}
diff --git a/src/render/renderext.h b/src/render/renderext.h
index 3834769..ce4b2a4 100644
--- a/src/render/renderext.h
+++ b/src/render/renderext.h
@@ -16,7 +16,8 @@ namespace render
{
/// the render extension of an entity
-class RenderExt :public core::Extension {
+class RenderExt : public core::Extension
+{
public:
RenderExt(core::Entity *entity);
~RenderExt();
@@ -25,32 +26,44 @@ public:
virtual void frame(float elapsed);
- inline bool visible() const { return state_visible; }
+ inline bool visible() const {
+ return state_visible;
+ }
- inline bool detailvisible() const { return state_detailvisible; }
+ inline bool detailvisible() const {
+ return state_detailvisible;
+ }
/**
* true if the entity is behind the camera
*/
- inline bool behind() const { return state_behind; }
+ inline bool behind() const {
+ return state_behind;
+ }
- inline float fuzz() const { return state_fuzz; }
+ inline float fuzz() const {
+ return state_fuzz;
+ }
/// distance to the camera
- inline float distance() const { return state_distance; }
+ inline float distance() const {
+ return state_distance;
+ }
/// particles
- inline ParticleSystems &particles() { return state_particles; }
+ inline ParticleSystems &particles() {
+ return state_particles;
+ }
private:
bool state_visible;
bool state_detailvisible;
bool state_behind;
-
+
float state_fuzz;
float state_distance;
- ParticleSystems state_particles;
+ ParticleSystems state_particles;
};
} // namespace render
diff --git a/src/render/screenshot.cc b/src/render/screenshot.cc
index dcbada4..342977a 100644
--- a/src/render/screenshot.cc
+++ b/src/render/screenshot.cc
@@ -1,7 +1,7 @@
/*
render/screenshot.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include <iomanip>
@@ -17,7 +17,8 @@
#include "render/tgafile.h"
#include "render/gl.h"
-namespace render {
+namespace render
+{
core::Cvar *Screenshot::screenshotformat = 0;
core::Cvar *Screenshot::screenshotquality = 0;
@@ -27,7 +28,7 @@ int Screenshot::number = 0;
void Screenshot::save()
{
- bool available = false;
+ bool available = false;
std::string filename;
const int TYPETGA = 0;
const int TYPEPNG = 1;
@@ -46,7 +47,7 @@ void Screenshot::save()
if ((screenshotformat->str().compare("jpg") == 0) || (screenshotformat->str().compare("jpeg") == 0)) {
filetype = TYPEJPG;
- if (screenshotquality->value() == 0 ) {
+ if (screenshotquality->value() == 0) {
(*screenshotquality) = 85;
} else if (screenshotquality->value() < 10) {
(*screenshotquality) = 10;
@@ -65,19 +66,19 @@ void Screenshot::save()
(*screenshotformat) = "tga";
}
- // find the first available screenshots/osirion-yyyymmdd-hhmm-xxxx.ext
+ // find the first available screenshots/osirion-yyyymmdd-hhmm-xxxx.ext
std::stringstream filenamestr;
int day, month, year, hour, min;
-
+
sys::get_datetime(year, month, day, hour, min);
-
+
filenamestr << filesystem::writedir() << "screenshots/osirion" << '-';
// date
filenamestr << std::setfill('0') << std::setw(4) << year << std::setw(2) << month << std::setw(2) << day << '-';
- // time
+ // time
filenamestr << std::setfill('0') << std::setw(2) << hour << std::setw(2) << min << '-';
- do {
+ do {
std::stringstream nstr;
nstr << std::setw(4) << std::setfill('0') << number;
@@ -88,32 +89,32 @@ void Screenshot::save()
filename.append(".");
filename.append(screenshotformat->str());
- FILE *handle = fopen(filename.c_str(), "r");
- if (handle) {
- fclose(handle);
- } else {
- available = true;
- }
+ FILE *handle = fopen(filename.c_str(), "r");
+ if (handle) {
+ fclose(handle);
+ } else {
+ available = true;
+ }
number++;
- } while (!available);
+ } while (!available);
render::Image image(State::width(), State::height(), 3);
- glReadPixels(0, 0, (GLsizei) State::width(), (GLsizei) State::height(),
- GL_RGB, GL_UNSIGNED_BYTE, (void *) image.data());
+ glReadPixels(0, 0, (GLsizei) State::width(), (GLsizei) State::height(),
+ GL_RGB, GL_UNSIGNED_BYTE, (void *) image.data());
image.flip();
if (filetype == TYPEPNG) {
-/* if ((Camera::width() % 8 != 0 ) || (Camera::height() % 8 != 0 )) {
- image.pad();
- }*/
+ /* if ((Camera::width() % 8 != 0 ) || (Camera::height() % 8 != 0 )) {
+ image.pad();
+ }*/
render::PNG::save(filename.c_str(), image);
} else if (filetype == TYPEJPG) {
-/* if ((Camera::width() % 8 != 0 ) || (Camera::height() % 8 != 0 )) {
- image.pad();
- }
-*/
+ /* if ((Camera::width() % 8 != 0 ) || (Camera::height() % 8 != 0 )) {
+ image.pad();
+ }
+ */
render::JPG::save(filename.c_str(), image, (int) screenshotquality->value());
} else if (filetype == TYPETGA) {
render::TGA::save(filename.c_str(), image);
diff --git a/src/render/screenshot.h b/src/render/screenshot.h
index 8b9269a..4be57fa 100644
--- a/src/render/screenshot.h
+++ b/src/render/screenshot.h
@@ -1,7 +1,7 @@
/*
render/screenshot.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_SCREENSHOT_H__
@@ -9,9 +9,11 @@
#include "core/cvar.h"
-namespace render {
+namespace render
+{
-class Screenshot {
+class Screenshot
+{
public:
static void save();
@@ -19,7 +21,7 @@ public:
static core::Cvar *screenshotquality;
private:
- static int number;
+ static int number;
};
} // namespace render
diff --git a/src/render/state.cc b/src/render/state.cc
index 96c7c0a..1a345c7 100644
--- a/src/render/state.cc
+++ b/src/render/state.cc
@@ -1,7 +1,7 @@
/*
render/state.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include <string>
@@ -11,7 +11,8 @@
#include "render/gl.h"
#include "render/render.h"
-namespace render {
+namespace render
+{
int State::render_width = 0;
int State::render_height = 0;
@@ -23,9 +24,9 @@ void State::init(int width, int height)
resize(width, height);
render_has_generate_mipmaps = false;
-
+
std::string version(gl::version());
- for (size_t i =0; i < version.size(); i++) {
+ for (size_t i = 0; i < version.size(); i++) {
if (version[i] == '.')
version[i] = ' ';
}
@@ -54,12 +55,12 @@ void State::resize(int width, int height)
{
render_width = width;
render_height = height;
-
+
render_aspect = (float) width / (float) height;
-
+
clear();
}
-
+
void State::clear()
{
// set viewport
@@ -80,9 +81,9 @@ void State::clear()
//gl::shademodel(GL_FLAT);
// color tracking
- glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+ glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
- // material settings
+ // material settings
GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance);
glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128
@@ -97,7 +98,7 @@ void State::clear()
gl::frontface(GL_CCW);
gl::disable(GL_CULL_FACE);
gl::disable(GL_DEPTH_TEST);
- gl::disable(GL_BLEND);
+ gl::disable(GL_BLEND);
gl::disable(GL_TEXTURE_2D);
}
diff --git a/src/render/state.h b/src/render/state.h
index df4d7cd..9a5a67c 100644
--- a/src/render/state.h
+++ b/src/render/state.h
@@ -1,16 +1,18 @@
/*
render/state.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_STATE_H__
#define __INCLUDED_RENDER_STATE_H__
-namespace render {
+namespace render
+{
-class State {
+class State
+{
public:
static void init(int width, int height);
static void shutdown();
@@ -18,10 +20,18 @@ public:
static void resize(int width, int height);
static void clear();
- inline static int width() { return render_width; }
- inline static int height() { return render_height; }
- inline static float aspect() { return render_aspect; }
- inline static bool has_generate_mipmaps() { return render_has_generate_mipmaps; }
+ inline static int width() {
+ return render_width;
+ }
+ inline static int height() {
+ return render_height;
+ }
+ inline static float aspect() {
+ return render_aspect;
+ }
+ inline static bool has_generate_mipmaps() {
+ return render_has_generate_mipmaps;
+ }
private:
static int render_width;
diff --git a/src/render/text.cc b/src/render/text.cc
index f4b75c4..cd169b5 100644
--- a/src/render/text.cc
+++ b/src/render/text.cc
@@ -31,11 +31,11 @@ void Text::init()
base_color[6] = new math::Color(1, 0, 1);
base_color[7] = new math::Color(1, 1, 1);
- for (size_t i=0; i< 26; i++) {
+ for (size_t i = 0; i < 26; i++) {
core_color[i] = new math::Color(.75, .75, .75);
}
- // N - normal color
+ // N - normal color
core_color[(size_t)('N'-'A')]->assign(.75, .75, .75);
// D - Debug color
core_color[(size_t)('D'-'A')]->assign(.5, .5, .5);
@@ -51,12 +51,12 @@ void Text::init()
void Text::shutdown()
{
- for (size_t i=0; i< 7; i++) {
+ for (size_t i = 0; i < 7; i++) {
delete base_color[i];
base_color[i] = 0;
}
- for (size_t i=0; i< 26; i++) {
+ for (size_t i = 0; i < 26; i++) {
delete core_color[i];
core_color[i] = 0;
}
@@ -65,20 +65,20 @@ void Text::shutdown()
void Text::assign_color(const char c, const math::Color &color)
{
if (('A' <= c) && (c <= 'Z')) {
- core_color[(size_t) (c - 'A')]->assign(color);
+ core_color[(size_t)(c - 'A')]->assign(color);
} else if (('0' <= c) && (c <= '9')) {
- base_color[(size_t) (c - '0')]->assign(color);
+ base_color[(size_t)(c - '0')]->assign(color);
}
}
void Text::setcolor(const char color)
{
if (('A' <= color) && (color <= 'Z')) {
- gl::color(*core_color[(size_t) (color - 'A')]);
- }
+ gl::color(*core_color[(size_t)(color - 'A')]);
+ }
else if (('0' <= color) && (color <= '9')) {
- gl::color(*base_color[(size_t) (color - '0')]);
+ gl::color(*base_color[(size_t)(color - '0')]);
}
}
@@ -105,16 +105,16 @@ void Text::draw(float x, float y, const char ascii)
gl::begin(gl::Quads);
glTexCoord2f(fcol, frow);
- gl::vertex(x,y, 0);
+ gl::vertex(x, y, 0);
glTexCoord2f(fcol + 0.0625f, frow);
- gl::vertex(x+text_fontwidth,y, 0);
+ gl::vertex(x + text_fontwidth, y, 0);
- glTexCoord2f(fcol +0.0625f, frow + 0.0625f);
- gl::vertex(x+text_fontwidth,y+text_fontheight, 0);
+ glTexCoord2f(fcol + 0.0625f, frow + 0.0625f);
+ gl::vertex(x + text_fontwidth, y + text_fontheight, 0);
- glTexCoord2f(fcol, frow+0.0625f);
- gl::vertex(x,y+text_fontheight, 0);
+ glTexCoord2f(fcol, frow + 0.0625f);
+ gl::vertex(x, y + text_fontheight, 0);
gl::end();
}
@@ -127,10 +127,10 @@ void Text::draw(float x, float y, const char *text)
while (*c) {
if (aux::is_base_color_code(c)) {
c++;
- gl::color(*base_color[ (size_t)(*c - '0')]);
+ gl::color(*base_color[(size_t)(*c - '0')]);
} else if (aux::is_core_color_code(c)) {
c++;
- gl::color(*core_color[ (size_t)(*c - 'A')]);
+ gl::color(*core_color[(size_t)(*c - 'A')]);
} else {
draw(x, y, *c);
x += text_fontwidth;
@@ -142,7 +142,7 @@ void Text::draw(float x, float y, const char *text)
void Text::draw(float x, float y, std::stringstream & textstream)
{
char line[MAXCMDSIZE];
- while (textstream.getline(line, MAXCMDSIZE-1)) {
+ while (textstream.getline(line, MAXCMDSIZE - 1)) {
draw(x, y, line);
y += text_fontheight;
}
diff --git a/src/render/text.h b/src/render/text.h
index 4762639..631f1cd 100644
--- a/src/render/text.h
+++ b/src/render/text.h
@@ -43,17 +43,21 @@ public:
/// set the font
static void setfont(const char *texture, float width, float height);
-
+
/// set the color
static void setcolor(const char color);
/// current font width
- static inline float fontwidth() { return text_fontwidth; }
+ static inline float fontwidth() {
+ return text_fontwidth;
+ }
/// current font height
- static inline float fontheight() { return text_fontheight; }
+ static inline float fontheight() {
+ return text_fontheight;
+ }
- enum Color {Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7};
+ enum Color {Black = 0, Red = 1, Green = 2, Yellow = 3, Blue = 4, Cyan = 5, Magenta = 6, White = 7};
static math::Color * base_color[10];
static math::Color * core_color[26];
diff --git a/src/render/textures.cc b/src/render/textures.cc
index 6817aa5..25521e9 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -37,7 +37,7 @@ void Textures::init()
if (registry.size()) {
clear();
} else {
- memset(textures,0, sizeof(textures));
+ memset(textures, 0, sizeof(textures));
}
// "no texture" bitmap
@@ -75,7 +75,7 @@ void Textures::list()
void Textures::clear()
{
- for (size_t i=0; i < MAXTEXTURES; i++) {
+ for (size_t i = 0; i < MAXTEXTURES; i++) {
if (textures[i]) {
glDeleteTextures(1, &textures[i]);
}
@@ -83,7 +83,7 @@ void Textures::clear()
}
registry.clear();
- memset(textures,0, sizeof(textures));
+ memset(textures, 0, sizeof(textures));
}
void Textures::unload(const std::string &name)
@@ -160,7 +160,7 @@ size_t Textures::load(const std::string &name, const bool filter)
filename.append(".tga");
image = TGA::load(filename.c_str());
}
-
+
if (!image) {
// try the jpg version
filename.assign(name);
@@ -180,11 +180,11 @@ size_t Textures::load(const std::string &name, const bool filter)
int texture_format;
int texture_internalformat;
-
+
if (filter) {
// scaling functions
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// 4 levels of mipmaps
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
@@ -198,10 +198,10 @@ size_t Textures::load(const std::string &name, const bool filter)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
} else {
// scaling functions
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// no mipmaps, base level only
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
}
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -212,15 +212,15 @@ size_t Textures::load(const std::string &name, const bool filter)
texture_format = GL_RGB;
texture_internalformat = GL_RGB8;
}
-
+
if (filter && (r_mipmap->value() <= 0)) {
gluBuild2DMipmaps(GL_TEXTURE_2D,
- texture_internalformat, image->width(), image->height(),
- texture_format, GL_UNSIGNED_BYTE, image->data());
+ texture_internalformat, image->width(), image->height(),
+ texture_format, GL_UNSIGNED_BYTE, image->data());
} else {
glTexImage2D(GL_TEXTURE_2D, 0,
- texture_internalformat, image->width(), image->height(), 0,
- texture_format, GL_UNSIGNED_BYTE, image->data());
+ texture_internalformat, image->width(), image->height(), 0,
+ texture_format, GL_UNSIGNED_BYTE, image->data());
}
// add to the registry
@@ -260,7 +260,7 @@ size_t Textures::bind(const std::string &name, const bool filter)
} else {
id = load(name, filter);
}
-
+
return id;
}
diff --git a/src/render/tgafile.cc b/src/render/tgafile.cc
index d4d5df8..db54645 100644
--- a/src/render/tgafile.cc
+++ b/src/render/tgafile.cc
@@ -21,7 +21,7 @@
9 Colormapped image data Yes Yes
10 Truecolor image data No Yes
11 Monochrome image data No Yes
-
+
TGA multi-byte integer values have LSB first
*/
@@ -57,7 +57,7 @@ Image *TGA::load(const char *filename)
// TGA header
unsigned char header[18];
- memset(header, 0, sizeof(header));
+ memset(header, 0, sizeof(header));
if (!tga_file->read(header, 18)) {
con_warn << "Error reading " << filename << std::endl;
@@ -65,38 +65,38 @@ Image *TGA::load(const char *filename)
return 0;
}
- // byte 0 - image ID field length
+ // byte 0 - image ID field length
unsigned int tga_idlength = header[0];
- // byte 1 - color map type
+ // byte 1 - color map type
unsigned int tga_colormap = header[1];
- // byte 2 - image type
+ // byte 2 - image type
unsigned int tga_type = header[2];
- // byte 3+4 - color map first entry index
+ // byte 3+4 - color map first entry index
//unsigned int tga_colormap_first = header[3] + (header[4] << 8 );
// byte 5+6 - color map length (in bits)
- unsigned int tga_color_map_length = header[5] +(header[6] << 8 );
+ unsigned int tga_color_map_length = header[5] + (header[6] << 8);
// byte 7 - color map entry length
unsigned int tga_colormap_entry = header[7];
// byte 8+9 - image x origin
// byte 10+11 - image y origin
- // byte 12+13 - image width (LSB first)
+ // byte 12+13 - image width (LSB first)
unsigned int tga_width = header[12] + (header[13] << 8);
- // byte 14+15 - image height (LSB first)
+ // byte 14+15 - image height (LSB first)
unsigned int tga_height = header[14] + (header[15] << 8);
- // byte 16 - image color depth (in bits)
+ // byte 16 - image color depth (in bits)
unsigned int tga_depth = header[16];
- // byte 17 - image descriptor byte
+ // byte 17 - image descriptor byte
unsigned int tga_descriptor = header[17];
-
+
// read the image id if there is one
if (tga_idlength)
tga_file->skip(tga_idlength);
@@ -105,7 +105,7 @@ Image *TGA::load(const char *filename)
if (tga_colormap) {
if (tga_colormap > 1)
con_warn << filename << ": invalid color map type!" << std::endl;
-
+
tga_file->skip(tga_color_map_length*tga_colormap_entry);
}
@@ -113,92 +113,92 @@ Image *TGA::load(const char *filename)
unsigned int index = 0;
unsigned int channels = tga_depth / 8;
- switch(tga_type) {
+ switch (tga_type) {
- case TGA_NONE:
- con_warn << "Error reading " << filename
+ case TGA_NONE:
+ con_warn << "Error reading " << filename
<< ": no image data!" << std::endl;
- filesystem::close(tga_file);
- return 0;
- break;
+ filesystem::close(tga_file);
+ return 0;
+ break;
- case TGA_TRUECOLOR:
- if ((tga_depth == 24) || (tga_depth == 32)) {
+ case TGA_TRUECOLOR:
+ if ((tga_depth == 24) || (tga_depth == 32)) {
- image = new Image(tga_width, tga_height, channels);
+ image = new Image(tga_width, tga_height, channels);
- for (size_t i = 0; i < tga_width * tga_height; i++) {
- tga_file->read((void *)(*image)[i*(size_t)channels], channels);
- }
+ for (size_t i = 0; i < tga_width * tga_height; i++) {
+ tga_file->read((void *)(*image)[i*(size_t)channels], channels);
+ }
- image->swap_channels();
+ image->swap_channels();
- } else if (tga_depth == 16) {
-
- channels = 3;
- image = new Image(tga_width, tga_height,channels);
-
- for (size_t i =0; i < tga_width * tga_height; i++) {
- // unpack one pixel
- unsigned char pixel_data[2];
- tga_file->read((void *)pixel_data, 2);
- unsigned int unpacked = pixel_data[0] + pixel_data[1]* 0xff;
-
- unsigned int b = (unpacked & 0x1f) << 3;
- unsigned int g = ((unpacked >> 5) & 0x1f) << 3;
- unsigned int r = ((unpacked >> 10) & 0x1f) << 3;
-
- // store it
- image->data()[i * channels] = (unsigned char) b;
- image->data()[i * channels+1] = (unsigned char) g;
- image->data()[i * channels+2] = (unsigned char) r;
- }
- } else {
- con_warn << "Error reading " << filename
+ } else if (tga_depth == 16) {
+
+ channels = 3;
+ image = new Image(tga_width, tga_height, channels);
+
+ for (size_t i = 0; i < tga_width * tga_height; i++) {
+ // unpack one pixel
+ unsigned char pixel_data[2];
+ tga_file->read((void *)pixel_data, 2);
+ unsigned int unpacked = pixel_data[0] + pixel_data[1] * 0xff;
+
+ unsigned int b = (unpacked & 0x1f) << 3;
+ unsigned int g = ((unpacked >> 5) & 0x1f) << 3;
+ unsigned int r = ((unpacked >> 10) & 0x1f) << 3;
+
+ // store it
+ image->data()[i * channels] = (unsigned char) b;
+ image->data()[i * channels+1] = (unsigned char) g;
+ image->data()[i * channels+2] = (unsigned char) r;
+ }
+ } else {
+ con_warn << "Error reading " << filename
<< ": unsupported image depth '" << tga_depth << "'!" << std::endl;
- filesystem::close(tga_file);
- return 0;
- }
-
- break;
+ filesystem::close(tga_file);
+ return 0;
+ }
- case TGA_TRUECOLOR_RLE:
+ break;
- image = new Image(tga_width, tga_height, channels);
+ case TGA_TRUECOLOR_RLE:
- while (index < tga_width * tga_height) {
- unsigned char rle = 0;
- unsigned char pixel_data[4];
+ image = new Image(tga_width, tga_height, channels);
- // read RLE packet byte
- tga_file->read(&rle, 1);
-
- if (rle < 128) {
- rle++; // rle contains the number of pixels-1
- tga_file->read((void *)(*image)[index*channels], rle*channels);
- index += rle;
+ while (index < tga_width * tga_height) {
+ unsigned char rle = 0;
+ unsigned char pixel_data[4];
- } else {
- rle -= 127; // rle contains 128 + the number of identical pixels-1
- tga_file->read(pixel_data, channels);
-
- while (rle > 0 ) {
- memcpy((void *)(*image)[index*channels], (void *)pixel_data, channels);
- index++;
- rle--;
+ // read RLE packet byte
+ tga_file->read(&rle, 1);
+
+ if (rle < 128) {
+ rle++; // rle contains the number of pixels-1
+ tga_file->read((void *)(*image)[index*channels], rle*channels);
+ index += rle;
+
+ } else {
+ rle -= 127; // rle contains 128 + the number of identical pixels-1
+ tga_file->read(pixel_data, channels);
+
+ while (rle > 0) {
+ memcpy((void *)(*image)[index*channels], (void *)pixel_data, channels);
+ index++;
+ rle--;
+ }
}
}
- }
- image->swap_channels();
+ image->swap_channels();
+
+ break;
- break;
-
- default:
- con_warn << "Error reading " << filename
+ default:
+ con_warn << "Error reading " << filename
<< ": unsupported TGA type '" << (int) tga_type << "'!" << std::endl;
- filesystem::close(tga_file);
- return 0;
+ filesystem::close(tga_file);
+ return 0;
}
filesystem::close(tga_file);
@@ -221,35 +221,35 @@ void TGA::save(const char *filename, Image & image)
if (!filename)
return;
- std::ofstream ofs(filename, std::ios_base::out | std::ios_base::binary );
+ std::ofstream ofs(filename, std::ios_base::out | std::ios_base::binary);
- if (!ofs.is_open()) {
- con_warn << "Could not write " << filename << std::endl;
- return;
- }
+ if (!ofs.is_open()) {
+ con_warn << "Could not write " << filename << std::endl;
+ return;
+ }
// write TGA header
unsigned char header[18];
memset(header, 0, sizeof(header));
// byte 0 - image ID field length = 0 (no image ID field present)
- // byte 1 - color map type = 0 (no palette present)
- // byte 2 - image type = 10 (truecolor RLE encoded)
- header[2] = TGA_TRUECOLOR_RLE;
- // byte 3-11 - palette data (not used)
- // byte 12+13 - image width
- header[12] = (image.width() & 0xff);
- header[13] = ((image.width() >> 8) & 0xff);
- // byte 14+15 - image height
- header[14] = (image.height() & 0xff);
- header[15] = ((image.height() >> 8) & 0xff);
- // byte 16 - image color depth = 24 (RGB) or 32 (RGBA)
- header[16] = image.channels() * 8;
- // byte 17 - image descriptor byte = 0x20 (origin at bottom left)
- header[17] = 0x20;
+ // byte 1 - color map type = 0 (no palette present)
+ // byte 2 - image type = 10 (truecolor RLE encoded)
+ header[2] = TGA_TRUECOLOR_RLE;
+ // byte 3-11 - palette data (not used)
+ // byte 12+13 - image width
+ header[12] = (image.width() & 0xff);
+ header[13] = ((image.width() >> 8) & 0xff);
+ // byte 14+15 - image height
+ header[14] = (image.height() & 0xff);
+ header[15] = ((image.height() >> 8) & 0xff);
+ // byte 16 - image color depth = 24 (RGB) or 32 (RGBA)
+ header[16] = image.channels() * 8;
+ // byte 17 - image descriptor byte = 0x20 (origin at bottom left)
+ header[17] = 0x20;
// write header
- ofs.write((char *)header, sizeof(header));
+ ofs.write((char *)header, sizeof(header));
// write image data
// TGA has the R and B channels switched
@@ -259,16 +259,16 @@ void TGA::save(const char *filename, Image & image)
bool compress = false;
size_t block_length = 0;
- for (int y = image.height()-1; y >= 0; y--) {
+ for (int y = image.height() - 1; y >= 0; y--) {
for (size_t x = 0; x < image.width(); x++) {
- size_t index = y*image.width()*image.channels() + x * image.channels();
+ size_t index = y * image.width() * image.channels() + x * image.channels();
pixel_data[0] = *image[index+2];
pixel_data[1] = *image[index+1];
pixel_data[2] = *image[index];
if (image.channels() == 4)
- pixel_data[3] = *image[index+3];
-
+ pixel_data[3] = *image[index+3];
+
if (block_length == 0) {
memcpy(block_data, pixel_data, image.channels());
block_length++;
@@ -284,12 +284,12 @@ void TGA::save(const char *filename, Image & image)
block_length++;
} else {
- // uncompressed block and pixel data is identical
- if (block_length > 1 ) {
- // write the uncompressed block
+ // uncompressed block and pixel data is identical
+ if (block_length > 1) {
+ // write the uncompressed block
rle_packet = block_length - 2;
ofs.write((char *)&rle_packet, 1);
- ofs.write((char *)block_data, (block_length-1) * image.channels());
+ ofs.write((char *)block_data, (block_length - 1) * image.channels());
block_length = 1;
}
memcpy(block_data, pixel_data, image.channels());
@@ -305,9 +305,9 @@ void TGA::save(const char *filename, Image & image)
} else {
- // compressed block and pixel data differs
+ // compressed block and pixel data differs
if (block_length > 1) {
- // write the compressed block
+ // write the compressed block
rle_packet = block_length + 127;
ofs.write((char *)&rle_packet, 1);
ofs.write((char *)block_data, image.channels());
diff --git a/src/render/tgafile.h b/src/render/tgafile.h
index 767a871..26a10e6 100644
--- a/src/render/tgafile.h
+++ b/src/render/tgafile.h
@@ -14,11 +14,12 @@ namespace render
{
/// a class for loading and saving .tga files
-class TGA {
+class TGA
+{
public:
/// load a TGA image file from disk
- /** @param filename short path to the filename to be loaded
+ /** @param filename short path to the filename to be loaded
*/
static Image *load(const char * filename);