From c62f4f7c11116b2ba6d6a9dfdb74bc7f07e840d0 Mon Sep 17 00:00:00 2001 From: Wolfgang Becker Date: Wed, 9 Aug 2006 02:22:48 +0000 Subject: [PATCH] New sector attribute 'ambient-light'. SVN-Revision: 4133 --- src/object/ambient_light.hpp | 38 -------------------------------------- src/sector.cpp | 9 +++++++-- src/sector.hpp | 2 ++ src/video/drawing_context.cpp | 16 ++++++++++++---- src/video/drawing_context.hpp | 3 +++ 5 files changed, 24 insertions(+), 44 deletions(-) delete mode 100644 src/object/ambient_light.hpp diff --git a/src/object/ambient_light.hpp b/src/object/ambient_light.hpp deleted file mode 100644 index 0d5d9db66..000000000 --- a/src/object/ambient_light.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef __AMBIENT_LIGHT_HPP__ -#define __AMBIENT_LIGHT_HPP__ - -#include "game_object.hpp" -#include "lisp/lisp.hpp" - -class Sprite; - -class AmbientLight : public GameObject -{ -public: - AmbientLight(const lisp::Lisp& reader); - virtual ~AmbientLight(); - - void update(float elapsed_time); - void draw(DrawingContext& context); -}; - -#endif diff --git a/src/sector.cpp b/src/sector.cpp index 20ed7fc0b..027f17129 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -69,8 +69,8 @@ bool Sector::show_collrects = false; bool Sector::draw_solids_only = false; Sector::Sector(Level* parent) - : level(parent), currentmusic(LEVEL_MUSIC), gravity(10), - player(0), camera(0) + : level(parent), currentmusic(LEVEL_MUSIC), + ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gravity(10), player(0), camera(0) { add_object(new Player(player_status, "Tux")); add_object(new DisplayEffect("Effect")); @@ -185,6 +185,10 @@ Sector::parse(const lisp::Lisp& sector) spawnpoints.push_back(sp); } else if(token == "init-script") { iter.value()->get(init_script); + } else if(token == "ambient-light") { + std::vector vColor; + sector.get_vector( "ambient-light", vColor ); + ambient_light = Color( vColor ); } else { GameObject* object = parse_object(token, *(iter.lisp())); if(object) { @@ -697,6 +701,7 @@ Sector::try_unexpose(GameObject* object) void Sector::draw(DrawingContext& context) { + context.set_ambient_color( ambient_light ); context.push_transform(); context.set_translation(camera->get_translation()); diff --git a/src/sector.hpp b/src/sector.hpp index 57a26659a..8bd89669e 100644 --- a/src/sector.hpp +++ b/src/sector.hpp @@ -222,6 +222,8 @@ private: typedef std::vector ScriptList; ScriptList scripts; + Color ambient_light; + public: // TODO make this private again /// show collision rectangles of moving objects (for debugging) static bool show_collrects; diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 7bb36e41b..7fcb20580 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -45,7 +45,8 @@ static inline int next_po2(int val) return result; } -DrawingContext::DrawingContext() +DrawingContext::DrawingContext(): + ambient_color( 1.0f, 1.0f, 1.0f, 1.0f ) { screen = SDL_GetVideoSurface(); @@ -319,7 +320,9 @@ DrawingContext::do_drawing() transformstack.clear(); target_stack.clear(); - bool use_lightmap = lightmap_requests.size() != 0; + //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 ); // PART1: create lightmap if(use_lightmap) { @@ -330,8 +333,7 @@ DrawingContext::do_drawing() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - // FIXME: Add ambient light support here - glClearColor(0.3, 0.3, 0.4, 1); + glClearColor( ambient_color.red, ambient_color.green, ambient_color.blue, 1 ); glClear(GL_COLOR_BUFFER_BIT); handle_drawing_requests(lightmap_requests); lightmap_requests.clear(); @@ -476,3 +478,9 @@ DrawingContext::set_target(Target target) else requests = &drawing_requests; } + +void +DrawingContext::set_ambient_color( Color new_color ) +{ + ambient_color = new_color; +} diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index df312256d..08b4f1e23 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -130,6 +130,8 @@ public: void push_target(); void pop_target(); void set_target(Target target); + + void set_ambient_color( Color new_color ); private: class Transform @@ -225,6 +227,7 @@ private: DrawingRequests lightmap_requests; DrawingRequests* requests; + Color ambient_color; SDL_Surface* screen; Target target; -- 2.11.0