if (py < -9) break;
context.draw_text(font.get(), *i, Vector(4, py), LEFT_ALLIGN, layer);
}
-
- //add some light. Problem: can be abused as lightsource.
- context.push_target();
- context.set_target(DrawingContext::LIGHTMAP);
- context.draw_filled_rect( Vector( 0 ,0 ), Vector( SCREEN_WIDTH, height), Color( 1, 1, 1) , layer );
- context.pop_target();
-
context.pop_transform();
}
char str[60];
snprintf(str, sizeof(str), "%3.1f", fps_fps);
const char* fpstext = "FPS";
- context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
- context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1);
+ context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_HUD);
+ context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_HUD);
}
void
Surface* coin_surf = coin_surface.get();
if (coin_surf) {
- context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - gold_text->get_text_width(coins_text), BORDER_Y + 1), LAYER_FOREGROUND1);
+ context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - gold_text->get_text_width(coins_text), BORDER_Y + 1), LAYER_HUD);
}
- context.draw_text(gold_text, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1);
+ context.draw_text(gold_text, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_HUD);
context.pop_transform();
}
return result;
}
-DrawingContext::DrawingContext():
- ambient_color( 1.0f, 1.0f, 1.0f, 1.0f )
+DrawingContext::DrawingContext()
+ : ambient_color( 1.0f, 1.0f, 1.0f, 1.0f )
{
screen = SDL_GetVideoSurface();
}
void
+DrawingContext::draw_lightmap(DrawingRequest& request)
+{
+ const Texture* texture = reinterpret_cast<Texture*> (request.request_data);
+
+ // multiple the lightmap with the framebuffer
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
+
+ glBindTexture(GL_TEXTURE_2D, texture->get_handle());
+ glBegin(GL_QUADS);
+
+ glTexCoord2f(0, lightmap_uv_bottom);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(lightmap_uv_right, lightmap_uv_bottom);
+ glVertex2f(SCREEN_WIDTH, 0);
+
+ glTexCoord2f(lightmap_uv_right, 0);
+ glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
+
+ glTexCoord2f(0, 0);
+ glVertex2f(0, SCREEN_HEIGHT);
+
+ glEnd();
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
+void
DrawingContext::do_drawing()
{
#ifdef DEBUG
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
+
+ // add a lightmap drawing request into the queue
+ DrawingRequest request;
+ request.type = LIGHTMAPREQUEST;
+ request.layer = LAYER_HUD - 1;
+ request.request_data = lightmap;
+ requests->push_back(request);
}
//glClear(GL_COLOR_BUFFER_BIT);
handle_drawing_requests(drawing_requests);
drawing_requests.clear();
-
- if(use_lightmap) {
- // multiple the lightmap with the framebuffer
- glBlendFunc(GL_DST_COLOR, GL_ZERO);
-
- glBindTexture(GL_TEXTURE_2D, lightmap->get_handle());
- glBegin(GL_QUADS);
-
- glTexCoord2f(0, lightmap_uv_bottom);
- glVertex2f(0, 0);
-
- glTexCoord2f(lightmap_uv_right, lightmap_uv_bottom);
- glVertex2f(SCREEN_WIDTH, 0);
-
- glTexCoord2f(lightmap_uv_right, 0);
- glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
-
- glTexCoord2f(0, 0);
- glVertex2f(0, SCREEN_HEIGHT);
-
- glEnd();
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
-
assert_gl("drawing");
SDL_GL_SwapBuffers();
case FILLRECT:
draw_filled_rect(*i);
break;
+ case LIGHTMAPREQUEST:
+ draw_lightmap(*i);
+ break;
}
}
}
LAYER_FOREGROUNDTILES = 200,
LAYER_FOREGROUND0 = 300,
LAYER_FOREGROUND1 = 400,
- LAYER_GUI = 500
+ LAYER_HUD = 500,
+ LAYER_GUI = 600
};
class Blend
enum RequestType
{
- SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT
+ SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, LIGHTMAPREQUEST
};
struct SurfacePartRequest
void draw_text_center(DrawingRequest& request);
void draw_gradient(DrawingRequest& request);
void draw_filled_rect(DrawingRequest& request);
+ void draw_lightmap(DrawingRequest& request);
DrawingRequests drawing_requests;
DrawingRequests lightmap_requests;