target_stack.clear();
//Use Lightmap if ambient color is not white.
- bool use_lightmap = ( ambient_color.red != 1.0f || ambient_color.green != 1.0f ||
- ambient_color.blue != 1.0f );
+ bool use_lightmap = ( ambient_color.red != 1.0f ||
+ ambient_color.green != 1.0f ||
+ ambient_color.blue != 1.0f );
// PART1: create lightmap
if(use_lightmap) {
request->layer = LAYER_HUD - 1;
drawing_requests.push_back(request);
}
+ handle_drawing_requests(drawing_requests);
clear_drawing_requests(lightmap_requests);
-
- handle_drawing_requests(drawing_requests);
clear_drawing_requests(drawing_requests);
obstack_free(&obst, NULL);
#include "math/rectf.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
-#include "video/drawing_request.hpp"
#include "video/font.hpp"
#include "video/font_ptr.hpp"
#include "video/texture.hpp"
+class DrawingRequest;
+class Lightmap;
+class Renderer;
class Surface;
class Texture;
-class Renderer;
-class Lightmap;
-inline int next_po2(int val)
+// some constants for predefined layer values
+enum {
+ // Image/gradient backgrounds (should cover entire screen)
+ LAYER_BACKGROUND0 = -300,
+ // Particle backgrounds
+ LAYER_BACKGROUND1 = -200,
+ // Tilemap backgrounds
+ LAYER_BACKGROUNDTILES = -100,
+ // Solid tilemaps
+ LAYER_TILES = 0,
+ // Ordinary objects
+ LAYER_OBJECTS = 50,
+ // Objects that pass through walls
+ LAYER_FLOATINGOBJECTS = 150,
+ //
+ LAYER_FOREGROUNDTILES = 200,
+ //
+ LAYER_FOREGROUND0 = 300,
+ //
+ LAYER_FOREGROUND1 = 400,
+ // Hitpoints, time, coins, etc.
+ LAYER_HUD = 500,
+ // Menus, mouse, console etc.
+ LAYER_GUI = 600
+};
+
+class Blend
{
- int result = 1;
- while(result < val)
- result *= 2;
+public:
+ GLenum sfactor;
+ GLenum dfactor;
+
+ Blend()
+ : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA)
+ {}
- return result;
-}
+ Blend(GLenum s, GLenum d)
+ : sfactor(s), dfactor(d)
+ {}
+};
+
+enum Target {
+ NORMAL, LIGHTMAP
+};
/**
* This class provides functions for drawing things on screen. It also
#include "math/vector.hpp"
#include "video/color.hpp"
+#include "video/drawing_context.hpp"
#include "video/font.hpp"
#include "video/glutil.hpp"
class Surface;
-// some constants for predefined layer values
-enum {
- // Image/gradient backgrounds (should cover entire screen)
- LAYER_BACKGROUND0 = -300,
- // Particle backgrounds
- LAYER_BACKGROUND1 = -200,
- // Tilemap backgrounds
- LAYER_BACKGROUNDTILES = -100,
- // Solid tilemaps
- LAYER_TILES = 0,
- // Ordinary objects
- LAYER_OBJECTS = 50,
- // Objects that pass through walls
- LAYER_FLOATINGOBJECTS = 150,
- //
- LAYER_FOREGROUNDTILES = 200,
- //
- LAYER_FOREGROUND0 = 300,
- //
- LAYER_FOREGROUND1 = 400,
- // Hitpoints, time, coins, etc.
- LAYER_HUD = 500,
- // Menus, mouse, console etc.
- LAYER_GUI = 600
-};
-
-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)
- {}
-};
-
-enum Target {
- NORMAL, LIGHTMAP
-};
-
enum RequestType
{
SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, DRAW_LIGHTMAP, GETLIGHT
#include "util/log.hpp"
#include "util/utf8_iterator.hpp"
#include "video/drawing_context.hpp"
+#include "video/drawing_request.hpp"
#include "video/font.hpp"
#include "video/renderer.hpp"
PHYSFS_freeList(rc);
}
-void
+void
Font::loadFontFile(const std::string &filename)
{
lisp::Parser parser;
if( !config_l->get("glyph-width",def_char_width) ) {
log_warning << "Font:"<< filename << ": misses default glyph-width" << std::endl;
}
-
+
if( !config_l->get("glyph-height",char_height) ) {
std::ostringstream msg;
msg << "Font:" << filename << ": misses glyph-height";
}
}
-void
+void
Font::loadFontSurface(
const std::string &glyphimage,
const std::string &shadowimage,
int row=0, col=0;
int wrap = glyph_surface->get_width() / char_width;
-
+
SDL_Surface *surface = NULL;
-
+
if( glyph_width == VARIABLE ) {
//this does not work:
// surface = ((SDL::Texture *)glyph_surface.get_texture())->get_texture();
int x = col * (char_width + 2*border) + border;
if( ++col == wrap ) { col=0; row++; }
if( *chr == 0x0020 && glyphs[0x20].surface_idx != -1) continue;
-
+
Glyph glyph;
glyph.surface_idx = surface_idx;
-
- if( glyph_width == FIXED )
+
+ if( glyph_width == FIXED )
{
glyph.rect = Rectf(x, y, x + char_width, y + char_height);
glyph.offset = Vector(0, 0);
glyph.advance = char_width;
}
- else
+ else
{
if (y + char_height > surface->h)
{
int right = x + char_width - 1;
while (right > left && vline_empty(surface, right, y, y + char_height, 64))
right -= 1;
-
- if (left <= right)
+
+ if (left <= right)
{
glyph.offset = Vector(x-left, 0);
glyph.advance = right - left + 1 + 1; // FIXME: might be useful to make spacing configurable
- }
- else
+ }
+ else
{ // glyph is completly transparent
glyph.offset = Vector(0, 0);
glyph.advance = char_width + 1; // FIXME: might be useful to make spacing configurable
glyphs[*chr] = glyph;
}
- if( col>0 && col <= wrap ) {
+ if( col>0 && col <= wrap ) {
col = 0;
row++;
}
{
if( glyphs.at(*it).surface_idx != -1 )
curr_width += glyphs[*it].advance;
- else
+ else
curr_width += glyphs[0x20].advance;
}
}
return s.substr(0, i);
}
}
-
+
// FIXME: hard-wrap at width, taking care of multibyte characters
if (overflow) *overflow = "";
return s;
DrawingEffect drawing_effect, Color color, float alpha) const
{
if(shadowsize > 0)
- draw_chars(renderer, false, text,
+ draw_chars(renderer, false, text,
pos + Vector(shadowsize, shadowsize), drawing_effect, Color(1,1,1), alpha);
draw_chars(renderer, true, text, pos, drawing_effect, color, alpha);
Glyph glyph;
if( glyphs.at(*it).surface_idx != -1 )
glyph = glyphs[*it];
- else
+ else
glyph = glyphs[0x20];
DrawingRequest request;
#include "video/surface.hpp"
#include "video/texture_manager.hpp"
+inline int next_po2(int val)
+{
+ int result = 1;
+ while(result < val)
+ result *= 2;
+
+ return result;
+}
+
GLLightmap::GLLightmap() :
lightmap(),
lightmap_width(),
void
GLLightmap::start_draw(const Color &ambient_color)
{
-
+
glGetFloatv(GL_VIEWPORT, old_viewport); //save viewport
glViewport(old_viewport[0], old_viewport[3] - lightmap_height + old_viewport[1], lightmap_width, lightmap_height);
glMatrixMode(GL_PROJECTION);
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, old_viewport[0], old_viewport[3] - lightmap_height + old_viewport[1], lightmap_width, lightmap_height);
-
+
glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
void
GLLightmap::draw_gradient(const DrawingRequest& request)
{
- const GradientRequest* gradientrequest
+ const GradientRequest* gradientrequest
= (GradientRequest*) request.request_data;
const Color& top = gradientrequest->top;
const Color& bottom = gradientrequest->bottom;
void
GLLightmap::get_light(const DrawingRequest& request) const
{
- const GetLightRequest* getlightrequest
+ const GetLightRequest* getlightrequest
= (GetLightRequest*) request.request_data;
float pixels[3];