From: Wolfgang Becker Date: Wed, 9 Aug 2006 15:28:04 +0000 (+0000) Subject: LAYER_HUD and above ignore lightmap X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f7659d1e6e1268e6fec002e806a8a469408aa335;p=supertux.git LAYER_HUD and above ignore lightmap SVN-Revision: 4139 --- diff --git a/src/console.cpp b/src/console.cpp index c972a2311..2b4df37b2 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -494,13 +494,6 @@ Console::draw(DrawingContext& context) 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(); } diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 9f8be24e8..72b3eed93 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -114,8 +114,8 @@ MainLoop::draw_fps(DrawingContext& context, float fps_fps) 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 diff --git a/src/player_status.cpp b/src/player_status.cpp index 95f994e71..95a1c11c0 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -152,9 +152,9 @@ PlayerStatus::draw(DrawingContext& context) 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(); } diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 7fcb20580..6f570d018 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -45,8 +45,8 @@ static inline int next_po2(int val) 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(); @@ -311,6 +311,34 @@ DrawingContext::draw_filled_rect(DrawingRequest& request) } void +DrawingContext::draw_lightmap(DrawingRequest& request) +{ + const Texture* texture = reinterpret_cast (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 @@ -349,36 +377,18 @@ DrawingContext::do_drawing() 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(); @@ -413,6 +423,9 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) case FILLRECT: draw_filled_rect(*i); break; + case LIGHTMAPREQUEST: + draw_lightmap(*i); + break; } } } diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index 08b4f1e23..fee498186 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -49,7 +49,8 @@ enum { LAYER_FOREGROUNDTILES = 200, LAYER_FOREGROUND0 = 300, LAYER_FOREGROUND1 = 400, - LAYER_GUI = 500 + LAYER_HUD = 500, + LAYER_GUI = 600 }; class Blend @@ -161,7 +162,7 @@ private: enum RequestType { - SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT + SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, LIGHTMAPREQUEST }; struct SurfacePartRequest @@ -222,6 +223,7 @@ private: 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;