Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-08-26 17:42:30 +0000
committerStijn Buys <ingar@osirion.org>2008-08-26 17:42:30 +0000
commitcc0a4412a4ac7f1f78ef7e644a0c06c6dd6dd129 (patch)
tree27271e45ca42c1039d149ab30637fe4fb08eb732 /src/render
parent02e623574c4c12c40a0757ed934a93353f34a653 (diff)
improved dust rendering
Diffstat (limited to 'src/render')
-rw-r--r--src/render/draw.cc11
-rw-r--r--src/render/dust.cc20
-rw-r--r--src/render/image.h3
-rw-r--r--src/render/jpgfile.cc32
-rw-r--r--src/render/pngfile.cc5
-rw-r--r--src/render/textures.cc30
-rw-r--r--src/render/tga.cc3
7 files changed, 69 insertions, 35 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 9c5a0d0..415a56c 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -855,8 +855,11 @@ void draw_pass_model_fx(float elapsed)
// draw model engines for Controlable entities
if ((entity->type() == core::Entity::Controlable) && entity->model()->engines().size()) {
-
- u = static_cast<core::EntityControlable *>(entity)->thrust();
+ core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
+ u = ec->thrust();
+ if ((ec->eventstate() == core::Entity::ImpulseInitiate) || (ec->eventstate() == core::Entity::Impulse)) {
+ u = 1;
+ }
if (u > 0) {
t = entity->state()->state_engine_trail_offset;
@@ -901,14 +904,14 @@ void draw_pass_model_fx(float elapsed)
Stats::quads++;
}
- if (!engine->notrail()) {
+ if (!(engine->notrail() || (ec->eventstate() == core::Entity::Impulse))) {
// draw the engine trail
if (current_texture != circle_texture) {
gl::end();
current_texture = Textures::bind(circle_texture);
gl::begin(gl::Quads);
}
- color.assign(1.0f, 1.0f);
+ color.assign(1.0f, 1.0f);
offset.assign(entity->state()->axis().forward() * engine_size);
if (t > 0)
diff --git a/src/render/dust.cc b/src/render/dust.cc
index 25df9f9..ad337b3 100644
--- a/src/render/dust.cc
+++ b/src/render/dust.cc
@@ -91,8 +91,9 @@ void Dust::draw()
return;
}
- if (! core::localcontrol()->speed())
- return;
+ alpha = math::max(core::localcontrol()->movement(), core::localcontrol()->speed());
+ math::clamp(alpha, 0.0f, 1.0f);
+ alpha = 0.2f + alpha * 0.8f;
if (!dust) {
con_debug << " generating dust..." << std::endl;
@@ -105,17 +106,10 @@ void Dust::draw()
dust[i*3+2] = core::localcontrol()->location().z + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius());
}
}
-
- math::Color color(1.0f, 1.0f);
- alpha = core::localcontrol()->speed() / LOWSPEEDLIMIT;
- if (alpha > DUSTMAXALPHA)
- alpha = DUSTMAXALPHA;
- color.a = alpha;
-
- traillength = core::localcontrol()->speed() / LOWSPEEDLIMIT;
- /*if (traillength > 1)
- traillength = 1.0f; */
- traillength *= TRAILLENGHT;
+
+ math::Color color(1.0f, alpha);
+ traillength = math::max(math::max(core::localcontrol()->movement(), core::localcontrol()->speed()), 0.5f);
+ traillength = traillength * TRAILLENGHT / LOWSPEEDLIMIT;
gl::color(color);
gl::begin(gl::Lines);
diff --git a/src/render/image.h b/src/render/image.h
index c9cc029..3c82792 100644
--- a/src/render/image.h
+++ b/src/render/image.h
@@ -35,6 +35,9 @@ public:
/// number of channels 3 (RGB) or 4 (RGBA)
inline unsigned int channels() const { return image_channels; }
+ /// bits per pixel
+ 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 74cdea9..872233f 100644
--- a/src/render/jpgfile.cc
+++ b/src/render/jpgfile.cc
@@ -26,6 +26,10 @@ namespace render {
Image *JPG::load(const char *filename)
{
+ struct jpeg_decompress_struct jpeg_decompression_info;
+ struct jpeg_error_mgr jerr;
+
+ int row_stride = 0;
Image *image = 0;
if (!filename)
@@ -36,12 +40,34 @@ 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());
+
+ // 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);
+
+ // read pixel data
+ JSAMPLE *row_pointer;
+ while (jpeg_decompression_info.output_scanline < jpeg_decompression_info.output_height) {
+ 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);
-
+ // destroy decompression structures
+ jpeg_destroy_decompress(&jpeg_decompression_info);
filesystem::close(jpg_file);
-// con_debug << " " << filename << " " << png_width << "x" << png_height << "x" << channels * png_depth << "bpp" << std::endl;
-
+ con_debug << " " << filename << " " << image->width() << "x" << image->height() << "x" << image->bpp() << "bpp" << std::endl;
return image;
}
diff --git a/src/render/pngfile.cc b/src/render/pngfile.cc
index bff6a54..d011aff 100644
--- a/src/render/pngfile.cc
+++ b/src/render/pngfile.cc
@@ -110,14 +110,13 @@ Image *PNG::load(const char *filename)
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);
filesystem::close(png_file);
-
- con_debug << " " << filename << " " << png_width << "x" << png_height << "x" << channels * png_depth << "bpp" << std::endl;
-
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
+ con_debug << " " << filename << " " << image->width() << "x" << image->height() << "x" << image->bpp() << "bpp" << std::endl;
return image;
}
diff --git a/src/render/textures.cc b/src/render/textures.cc
index 6ceb7cd..a041c32 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -10,6 +10,7 @@
#include "render/textures.h"
#include "render/tga.h"
#include "render/pngfile.h"
+#include "render/jpgfile.h"
#include "sys/sys.h"
#include "core/application.h"
@@ -76,23 +77,32 @@ size_t Textures::load(std::string name, bool filter)
std::string filename;
Image *image = 0;
- // try the png version
- filename.assign(name);
- filename.append(".png");
- image = PNG::load(filename.c_str());
+ if (!image) {
+ // try the png version
+ filename.assign(name);
+ filename.append(".png");
+ image = PNG::load(filename.c_str());
+ }
if (!image) {
// try the tga version
filename.assign(name);
filename.append(".tga");
image = TGA::load(filename.c_str());
+ }
+
+ if (!image) {
+ // try the jpg version
+ filename.assign(name);
+ filename.append(".jpg");
+ image = JPG::load(filename.c_str());
+ }
- if (!image) {
- // add to the registry with id 0 (texture not found)
- con_warn << "Could not open " << filename << std::endl;
- registry[name] = 0;
- return 0;
- }
+ if (!image) {
+ // add to the registry with id 0 (texture not found)
+ con_warn << "Could not open " << filename << std::endl;
+ registry[name] = 0;
+ return 0;
}
size_t id = index;
diff --git a/src/render/tga.cc b/src/render/tga.cc
index 9703ce8..d9e5cb2 100644
--- a/src/render/tga.cc
+++ b/src/render/tga.cc
@@ -211,8 +211,7 @@ Image *TGA::load(const char *filename)
con_warn << filename << ": descriptor bit 4 (left-right) set!" << std::endl;
}
- con_debug << " " << filename << " " << tga_width << "x" << tga_height << "x" << tga_depth << "bpp" << std::endl;
-
+ con_debug << " " << filename << " " << image->width() << "x" << image->height() << "x" << image->bpp() << "bpp" << std::endl;
return image;
}