(reset-points
)
(objects
- (spotlight (x 100) (y 300))
- (spotlight (x 500) (y 200))
+ (spotlight (x 100) (y 300)
+ (red 1.0)
+ (green 0.0)
+ (blue 0.0)
+ (alpha 1.0)
+ (angle 60)
+ )
+ (spotlight (x 500) (y 300)
+ (red 0.0)
+ (green 0.0)
+ (blue 1.0)
+ (alpha 1.0)
+ (angle 0))
+
+ (spotlight (x 300) (y 100)
+ (red 0.0)
+ (green 1.0)
+ (blue 0.0)
+ (alpha 1.0)
+ (angle -60))
+
)
)
#include "sector.hpp"
Spotlight::Spotlight(const lisp::Lisp& lisp)
+ : angle(0.0f),
+ color(1.0f, 1.0f, 1.0f)
{
lisp.get("x", position.x);
lisp.get("y", position.y);
+
+ lisp.get("angle", angle);
+
+ lisp.get("red", color.red);
+ lisp.get("green", color.green);
+ lisp.get("blue", color.blue);
+ lisp.get("alpha", color.alpha);
center = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
base = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
light = sprite_manager->create("images/objects/spotlight/light.sprite");
- angle = 0.0f;
+
}
Spotlight::~Spotlight()
context.push_target();
context.set_target(DrawingContext::LIGHTMAP);
+ light->set_color(color);
+ light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
light->set_angle(angle);
light->draw(context, position, 0);
#include "game_object.hpp"
#include "math/vector.hpp"
#include "lisp/lisp.hpp"
+#include "video/color.hpp"
class Sprite;
Sprite* lights;
Sprite* light;
Sprite* lightcone;
+
+ Color color;
};
#endif
#include "timer.hpp"
Sprite::Sprite(SpriteData& newdata)
- : data(newdata), frame(0), animation_loops(-1), angle(0.0f)
+ : data(newdata),
+ frame(0),
+ animation_loops(-1),
+ angle(0.0f),
+ color(1.0f, 1.0f, 1.0f, 1.0f)
{
action = data.get_action("normal");
if(!action)
: data(other.data), frame(other.frame),
animation_loops(other.animation_loops),
angle(0.0f),
+ color(1.0f, 1.0f, 1.0f, 1.0f),
action(other.action)
{
last_ticks = real_time;
context.draw_surface(action->surfaces[(int)frame],
pos - Vector(action->x_offset, action->y_offset),
angle,
+ color,
+ blend,
layer + action->z_order);
}
return angle;
}
+void
+Sprite::set_color(const Color& c)
+{
+ color = c;
+}
+
+Color
+Sprite::get_color() const
+{
+ return color;
+}
+
+void
+Sprite::set_blend(const Blend& b)
+{
+ blend = b;
+}
+
+Blend
+Sprite::get_blend() const
+{
+ return blend;
+}
+
/* EOF */
#include "math/vector.hpp"
#include "math/rect.hpp"
#include "sprite_data.hpp"
+#include "video/color.hpp"
+#include "video/drawing_context.hpp"
class Surface;
class DrawingContext;
+class Color;
+class Blend;
class Sprite
{
/** Get the angle of the sprite rotation in degree */
float get_angle() const;
+ void set_color(const Color& color);
+
+ Color get_color() const;
+
+ void set_blend(const Blend& blend);
+
+ Blend get_blend() const;
+
/** Get current frame */
int get_frame() const
{ return (int)frame; }
int animation_loops;
float last_ticks;
float angle;
-
+ Color color;
+ Blend blend;
+
SpriteData::Action* action;
};
}
void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position, float angle,
- int layer)
+DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+ float angle, const Color& color, const Blend& blend,
+ int layer)
{
assert(surface != 0);
request.drawing_effect = transform.drawing_effect;
request.alpha = transform.alpha;
request.angle = angle;
+ request.color = color;
+ request.blend = blend;
+
request.request_data = const_cast<Surface*> (surface);
requests->push_back(request);
DrawingContext::draw_surface(const Surface* surface, const Vector& position,
int layer)
{
- draw_surface(surface, position, 0.0f, layer);
+ draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
}
void
if (i->angle == 0.0f)
surface->draw(i->pos.x, i->pos.y, i->alpha, i->drawing_effect);
else
- surface->draw(i->pos.x, i->pos.y, i->alpha, i->angle, i->drawing_effect);
+ surface->draw(i->pos.x, i->pos.y, i->alpha, i->angle, i->color, i->blend, i->drawing_effect);
break;
}
case SURFACE_PART:
LAYER_GUI = 500
};
+class Blend
+{
+public:
+ GLenum sfactor;
+ GLenum dfactor;
+
+ Blend()
+ : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
+ {}
+
+ Blend(GLenum s, GLenum d)
+ : sfactor(s), dfactor(d)
+ {}
+};
+
/**
* This class provides functions for drawing things on screen. It also
* maintains a stack of transforms that are applied to graphics.
void draw_surface(const Surface* surface, const Vector& position,
int layer);
/// Adds a drawing request for a surface into the request list.
- void draw_surface(const Surface* surface, const Vector& position, float angle,
+ void draw_surface(const Surface* surface, const Vector& position,
+ float angle, const Color& color, const Blend& blend,
int layer);
/// Adds a drawing request for part of a surface.
void draw_surface_part(const Surface* surface, const Vector& source,
/// the currently active transform
Transform transform;
- class Blend
- {
- public:
- GLenum sfactor;
- GLenum dfactor;
-
- Blend()
- : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
- {}
- };
std::vector<Blend> blend_stack;
Blend blend_mode;
float alpha;
Blend blend;
float angle;
-
+ Color color;
+
void* request_data;
DrawingRequest()
- : angle(0.0f)
+ : angle(0.0f),
+ color(1.0f, 1.0f, 1.0f, 1.0f)
{}
bool operator<(const DrawingRequest& other) const
#include "gameconfig.hpp"
#include "physfs/physfs_sdl.hpp"
#include "video/surface.hpp"
+#include "video/drawing_context.hpp"
+#include "video/color.hpp"
#include "image_texture.hpp"
#include "texture_manager.hpp"
float uv_left, float uv_top,
float uv_right, float uv_bottom,
float angle,
+ const Color& color,
+ const Blend& blend,
DrawingEffect effect)
{
if(effect & HORIZONTAL_FLIP)
top -= center_y;
bottom -= center_y;
+ glBlendFunc(blend.sfactor, blend.dfactor);
+ glColor4f(color.red, color.green, color.blue, color.alpha);
glBegin(GL_QUADS);
glTexCoord2f(uv_left, uv_top);
glVertex2f(left*ca - top*sa + center_x,
glVertex2f(left*ca - bottom*sa + center_x,
left*sa + bottom*ca + center_y);
glEnd();
+
+ // FIXME: find a better way to restore the blend mode
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void
-Surface::draw(float x, float y, float alpha, float angle, DrawingEffect effect) const
+Surface::draw(float x, float y, float alpha, float angle, const Color& color, const Blend& blend, DrawingEffect effect) const
{
glColor4f(1.0f, 1.0f, 1.0f, alpha);
glBindTexture(GL_TEXTURE_2D, texture->get_handle());
x + width, y + height,
uv_left, uv_top, uv_right, uv_bottom,
angle,
+ color,
+ blend,
effect);
}
#include <string>
+class Color;
+class Blend;
class ImageTexture;
/// bitset for drawing effects
float uv_right;
float uv_bottom;
- void draw(float x, float y, float alpha, float angle, DrawingEffect effect) const;
+ void draw(float x, float y, float alpha, float angle, const Color& color, const Blend& blend, DrawingEffect effect) const;
void draw(float x, float y, float alpha, DrawingEffect effect) const;
void draw_part(float src_x, float src_y, float dst_x, float dst_y,
float width, float height,