diff --git a/src/Makefile.am b/src/Makefile.am index 02940ee0..be1580e6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,7 @@ liblol_a_SOURCES = \ timer.cpp timer.h bitfield.h profiler.cpp profiler.h input.h input.cpp \ world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \ - worldentity.cpp worldentity.h shader.cpp shader.h \ + worldentity.cpp worldentity.h shader.cpp shader.h image.cpp image.h \ \ sdlapp.cpp sdlapp.h sdlinput.cpp sdlinput.h \ \ diff --git a/src/core.h b/src/core.h index bd6a41e6..5cb696eb 100644 --- a/src/core.h +++ b/src/core.h @@ -44,6 +44,7 @@ #include "map.h" #include "layer.h" #include "shader.h" +#include "image.h" // Managers #include "ticker.h" diff --git a/src/image.cpp b/src/image.cpp new file mode 100644 index 00000000..d5df4ff5 --- /dev/null +++ b/src/image.cpp @@ -0,0 +1,99 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#if defined USE_SDL +# include +# include +#endif + +#include "core.h" +#include "lolgl.h" + +namespace lol +{ + +/* + * Image implementation class + */ + +class ImageData +{ + friend class Image; + +private: + vec2i size; + Image::format_t format; + +#if defined USE_SDL + SDL_Surface *img; +#endif +}; + +/* + * Public Image class + */ + +Image::Image(char const *path) + : data(new ImageData()) +{ +#if defined USE_SDL + for (char const *name = path; *name; name++) + if ((data->img = IMG_Load(name))) + break; + + if (!data->img) + { +#if !LOL_RELEASE + fprintf(stderr, "ERROR: could not load %s\n", path); +#endif + SDL_Quit(); + exit(1); + } + + data->size = vec2i(data->img->w, data->img->h); + data->format = data->img->format->Amask ? FORMAT_RGBA : FORMAT_RGB; +#else + data->size = 0; + data->format = FORMAT_UNKNOWN; +#endif +} + +vec2i Image::GetSize() const +{ + return data->size; +} + +Image::format_t Image::GetFormat() const +{ + return data->format; +} + +void * Image::GetData() const +{ + return data->img->pixels; +} + +Image::~Image() +{ +#if defined USE_LOL + SDL_FreeSurface(data->img); +#endif + delete data; +} + +} /* namespace lol */ + diff --git a/src/image.h b/src/image.h new file mode 100644 index 00000000..3ea00c6c --- /dev/null +++ b/src/image.h @@ -0,0 +1,51 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The Image class +// --------------- +// + +#if !defined __DH_IMAGE_H__ +#define __DH_IMAGE_H__ + +#include "matrix.h" + +namespace lol +{ + +class ImageData; + +class Image +{ +public: + Image(char const *path); + ~Image(); + + typedef enum + { + FORMAT_RGBA = 0, + FORMAT_RGB, + FORMAT_UNKNOWN, + } + format_t; + + vec2i GetSize() const; + format_t GetFormat() const; + void *GetData() const; + +private: + ImageData *data; +}; + +} /* namespace lol */ + +#endif // __DH_IMAGE_H__ + diff --git a/win32/deushax.vcxproj b/win32/deushax.vcxproj index fe1ccc55..3918a538 100644 --- a/win32/deushax.vcxproj +++ b/win32/deushax.vcxproj @@ -26,6 +26,7 @@ + @@ -63,6 +64,7 @@ + diff --git a/win32/deushax.vcxproj.filters b/win32/deushax.vcxproj.filters index 155a856b..c8a37aae 100644 --- a/win32/deushax.vcxproj.filters +++ b/win32/deushax.vcxproj.filters @@ -42,6 +42,9 @@ lolengine + + lolengine + lolengine @@ -142,6 +145,9 @@ lolengine + + lolengine + lolengine diff --git a/win32/editor.vcxproj b/win32/editor.vcxproj index 799f4368..4235a670 100644 --- a/win32/editor.vcxproj +++ b/win32/editor.vcxproj @@ -26,6 +26,7 @@ + @@ -63,6 +64,7 @@ + diff --git a/win32/editor.vcxproj.filters b/win32/editor.vcxproj.filters index f0da3856..900a13e7 100644 --- a/win32/editor.vcxproj.filters +++ b/win32/editor.vcxproj.filters @@ -42,6 +42,9 @@ lolengine + + lolengine + lolengine @@ -142,6 +145,9 @@ lolengine + + lolengine + lolengine diff --git a/win32/monsterz.vcxproj b/win32/monsterz.vcxproj index 4155a973..a72cd57b 100644 --- a/win32/monsterz.vcxproj +++ b/win32/monsterz.vcxproj @@ -31,6 +31,7 @@ + @@ -72,6 +73,7 @@ + diff --git a/win32/monsterz.vcxproj.filters b/win32/monsterz.vcxproj.filters index bf7de2c2..a625ef04 100644 --- a/win32/monsterz.vcxproj.filters +++ b/win32/monsterz.vcxproj.filters @@ -42,6 +42,9 @@ lolengine + + lolengine + lolengine @@ -147,6 +150,9 @@ lolengine + + lolengine + lolengine