diff options
-rw-r--r-- | src/resources/image.cpp | 28 | ||||
-rw-r--r-- | src/resources/image.h | 16 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp index d30d6c92..cefb9d88 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -44,6 +44,11 @@ Image::Image(GLuint image, int width, int height, int texWidth, int texHeight): alpha = 1.0f; } +Image::Image():image(image) +{ + alpha = 1.0f; +} + Image::~Image() { unload(); @@ -361,7 +366,30 @@ float Image::getAlpha() return alpha; } +bool Image::create(int width, int height) +{ + image = SDL_AllocSurface(SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0); + if ( image ) + return true; + else + return false; +} +void Image::fillWithColor(unsigned char red, unsigned char green, unsigned blue) +{ + Uint32 boxColor = SDL_MapRGB(SDL_GetVideoSurface()->format, red, green, blue); + if ( image ) + { + SDL_Rect sourceRect; + sourceRect.x = sourceRect.y = 0; + sourceRect.w = image->w; + sourceRect.h = image->h; + SDL_FillRect(image, &sourceRect, boxColor); + } +} + +//============================================================================ +// SubImage Class //============================================================================ #ifndef USE_OPENGL diff --git a/src/resources/image.h b/src/resources/image.h index 9102f62c..084bb211 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -58,6 +58,11 @@ class Image : public Resource #endif /** + * Two time intialization Contructor. For now : Only to be used with create. + */ + Image(); + + /** * Destructor. */ virtual ~Image(); @@ -143,6 +148,17 @@ class Image : public Resource */ float getAlpha(); + /** + * Creates a new empty image with given height and width. + */ + bool create(int width, int height); + + /** + * Fills the image with given color. + */ + void fillWithColor(unsigned char red, unsigned char green, unsigned blue); + + protected: #ifdef USE_OPENGL GLuint image; |