#include <findlocale.h>
}
+#include "video/renderer.hpp"
#include "supertux/main.hpp"
#ifdef MACOSX
void
Main::init_video()
{
- // FIXME: Add something here
SCREEN_WIDTH = 800;
SCREEN_HEIGHT = 600;
PHYSICAL_SCREEN_WIDTH = SCREEN_WIDTH;
PHYSICAL_SCREEN_HEIGHT = SCREEN_HEIGHT;
- context_pointer->init_renderer();
+ SDL_SetWindowTitle(Renderer::instance()->get_window(), PACKAGE_NAME " " PACKAGE_VERSION);
-#ifdef OLD_SDL1
- // SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
-
- /* // set icon -- Original part B4 SDL2
-#ifdef MACOSX
const char* icon_fname = "images/engine/icons/supertux-256x256.png";
-#else
- const char* icon_fname = "images/engine/icons/supertux.xpm";
-#endif
- SDL_Surface* icon;
- try {
- icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
- } catch (const std::runtime_error& err) {
- icon = 0;
- log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
+ SDL_Surface* icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
+ if (!icon)
+ {
+ log_warning << "Couldn't load icon '" << icon_fname << "': " << SDL_GetError() << std::endl;
}
- if(icon != 0) {
- SDL_WM_SetIcon(icon, 0); //now SDL_SetWindowIcon(window, surface); if needed
+ else
+ {
+ SDL_SetWindowIcon(Renderer::instance()->get_window(), icon);
SDL_FreeSurface(icon);
}
- else {
- log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
- }
- */
-
- // SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
-
- // set icon
-#ifdef MACOSX
- const char* icon_fname = "images/engine/icons/supertux-256x256.png";
-#else
- const char* icon_fname = "images/engine/icons/supertux.xpm";
-#endif
- SDL_Window* icon = 0;
- try {
- //icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
- } catch (const std::runtime_error& err) {
- log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
- }
- if(icon != 0) {
- // SDL_SetWindowIcon(icon, 0); //now SDL_SetWindowIcon(window, surface); if needed
- // SDL_FreeSurface(icon);
- }
- else {
- log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
- }
-
-
- /* // set icon
-#ifdef MACOSX
- const char* icon_fname = "images/engine/icons/supertux-256x256.png";
-#else
- const char* icon_fname = "images/engine/icons/supertux.xpm";
-#endif
-
- SDL_Window icon = SDL_CreateWindow(PACKAGE_NAME " " PACKAGE_VERSION,
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
- 640, 480,
- SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
- // not sure of that */
-#endif
SDL_ShowCursor(0);
log_info << (g_config->use_fullscreen?"fullscreen ":"window ")
return 0;
timelog("video");
- DrawingContext context;
+ std::auto_ptr<Renderer> renderer(VideoSystem::new_renderer());
+ std::auto_ptr<Lightmap> lightmap(VideoSystem::new_lightmap());
+ DrawingContext context(*renderer, *lightmap);
context_pointer = &context;
init_video();
#include "video/texture_manager.hpp"
#include "video/video_systems.hpp"
-DrawingContext::DrawingContext() :
- renderer(0),
- lightmap(0),
+DrawingContext::DrawingContext(Renderer& renderer, Lightmap& lightmap) :
+ renderer(renderer),
+ lightmap(lightmap),
transformstack(),
transform(),
blend_stack(),
DrawingContext::~DrawingContext()
{
- delete renderer;
- delete lightmap;
-
obstack_free(&obst, NULL);
}
void
-DrawingContext::init_renderer()
-{
- delete renderer;
- delete lightmap;
-
- renderer = VideoSystem::new_renderer();
- lightmap = VideoSystem::new_lightmap();
-}
-
-void
DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
float angle, const Color& color, const Blend& blend,
int layer)
// PART1: create lightmap
if(use_lightmap) {
- lightmap->start_draw(ambient_color);
+ lightmap.start_draw(ambient_color);
handle_drawing_requests(lightmap_requests);
- lightmap->end_draw();
+ lightmap.end_draw();
DrawingRequest* request = new(obst) DrawingRequest();
request->target = NORMAL;
// if a screenshot was requested, take one
if (screenshot_requested) {
- renderer->do_take_screenshot();
+ renderer.do_take_screenshot();
screenshot_requested = false;
}
- renderer->flip();
+ renderer.flip();
}
class RequestPtrCompare
case NORMAL:
switch(request.type) {
case SURFACE:
- renderer->draw_surface(request);
+ renderer.draw_surface(request);
break;
case SURFACE_PART:
- renderer->draw_surface_part(request);
+ renderer.draw_surface_part(request);
break;
case GRADIENT:
- renderer->draw_gradient(request);
+ renderer.draw_gradient(request);
break;
case TEXT:
{
const TextRequest* textrequest = (TextRequest*) request.request_data;
- textrequest->font->draw(renderer, textrequest->text, request.pos,
+ textrequest->font->draw(&renderer, textrequest->text, request.pos,
textrequest->alignment, request.drawing_effect, request.color, request.alpha);
}
break;
case FILLRECT:
- renderer->draw_filled_rect(request);
+ renderer.draw_filled_rect(request);
break;
case INVERSEELLIPSE:
- renderer->draw_inverse_ellipse(request);
+ renderer.draw_inverse_ellipse(request);
break;
case DRAW_LIGHTMAP:
- lightmap->do_draw();
+ lightmap.do_draw();
break;
case GETLIGHT:
- lightmap->get_light(request);
+ lightmap.get_light(request);
break;
}
break;
case LIGHTMAP:
switch(request.type) {
case SURFACE:
- lightmap->draw_surface(request);
+ lightmap.draw_surface(request);
break;
case SURFACE_PART:
- lightmap->draw_surface_part(request);
+ lightmap.draw_surface_part(request);
break;
case GRADIENT:
- lightmap->draw_gradient(request);
+ lightmap.draw_gradient(request);
break;
case TEXT:
{
const TextRequest* textrequest = (TextRequest*) request.request_data;
- textrequest->font->draw(renderer, textrequest->text, request.pos,
+ textrequest->font->draw(&renderer, textrequest->text, request.pos,
textrequest->alignment, request.drawing_effect, request.color, request.alpha);
}
break;
case FILLRECT:
- lightmap->draw_filled_rect(request);
+ lightmap.draw_filled_rect(request);
break;
case INVERSEELLIPSE:
assert(!"InverseEllipse doesn't make sense on the lightmap");
break;
case DRAW_LIGHTMAP:
- lightmap->do_draw();
+ lightmap.do_draw();
break;
case GETLIGHT:
- lightmap->get_light(request);
+ lightmap.get_light(request);
break;
}
break;
class DrawingContext
{
public:
- DrawingContext();
+ DrawingContext(Renderer& renderer, Lightmap& lightmap);
~DrawingContext();
- void init_renderer();
-
/// Adds a drawing request for a surface into the request list.
void draw_surface(SurfacePtr surface, const Vector& position,
int layer);
};
private:
- Renderer *renderer;
- Lightmap *lightmap;
+ Renderer& renderer;
+ Lightmap& lightmap;
/// the transform stack
std::vector<Transform> transformstack;
void apply_config();
void apply_video_mode(const Size& size, bool fullscreen);
void set_gamma(float gamma);
+ SDL_Window* get_window() const { return window; }
};
#endif
virtual void resize(int w, int h) = 0;
virtual void apply_config() = 0;
virtual void set_gamma(float gamma) = 0;
+ virtual SDL_Window* get_window() const = 0;
static Renderer* instance() { assert(instance_); return instance_; }
log_info << "Max Texture Height: " << info.max_texture_height << std::endl;
}
- SDL_SetWindowTitle(window, "SuperTux");
if(texture_manager == 0)
texture_manager = new TextureManager();
}
void resize(int w, int h);
void apply_config() {}
void set_gamma(float gamma);
+ SDL_Window* get_window() const { return window; }
SDL_Renderer* get_sdl_renderer() const { return renderer; };