LAYER_HUD and above ignore lightmap
authorWolfgang Becker <uafr@gmx.de>
Wed, 9 Aug 2006 15:28:04 +0000 (15:28 +0000)
committerWolfgang Becker <uafr@gmx.de>
Wed, 9 Aug 2006 15:28:04 +0000 (15:28 +0000)
SVN-Revision: 4139

src/console.cpp
src/mainloop.cpp
src/player_status.cpp
src/video/drawing_context.cpp
src/video/drawing_context.hpp

index c972a23..2b4df37 100644 (file)
@@ -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();
 }
 
index 9f8be24..72b3eed 100644 (file)
@@ -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
index 95f994e..95a1c11 100644 (file)
@@ -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();
 }
index 7fcb205..6f570d0 100644 (file)
@@ -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<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
@@ -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;
     }
   }
 }
index 08b4f1e..fee4981 100644 (file)
@@ -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;