00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef IMAGE_H
00023 #define IMAGE_H
00024
00025 #include "main.h"
00026
00027 #include "resources/resource.h"
00028
00029 #include <SDL.h>
00030
00031 #ifdef USE_OPENGL
00032
00033
00034
00035
00036
00037 #define NO_SDL_GLEXT
00038
00039 #include <SDL_opengl.h>
00040 #endif
00041
00042 class Dye;
00043 class Position;
00044
00048 class Image : public Resource
00049 {
00050 friend class Graphics;
00051 #ifdef USE_OPENGL
00052 friend class OpenGLGraphics;
00053 #endif
00054
00055 public:
00059 virtual ~Image();
00060
00070 static Resource *load(void *buffer, unsigned bufferSize);
00071
00082 static Resource *load(void *buffer, unsigned bufferSize,
00083 Dye const &dye);
00084
00088 static Image *load(SDL_Surface *);
00089
00093 virtual void unload();
00094
00098 virtual int getWidth() const
00099 { return mBounds.w; }
00100
00104 virtual int getHeight() const
00105 { return mBounds.h; }
00106
00113 virtual Image *getSubImage(int x, int y, int width, int height);
00114
00118 virtual void setAlpha(float alpha);
00119
00123 float getAlpha() const;
00124
00125 #ifdef USE_OPENGL
00126
00130 static void setLoadAsOpenGL(bool useOpenGL);
00131
00132 int getTextureWidth() const { return mTexWidth; }
00133 int getTextureHeight() const { return mTexHeight; }
00134 static int getTextureType() { return mTextureType; }
00135 #endif
00136
00144 Image *merge(Image *image, int x, int y);
00145
00146 protected:
00150 #ifdef USE_OPENGL
00151 Image(GLuint glimage, int width, int height,
00152 int texWidth, int texHeight);
00153
00157 static int powerOfTwo(int input);
00158 #endif
00159 Image(SDL_Surface *image);
00160
00161 SDL_Rect mBounds;
00162 bool mLoaded;
00163
00164 #ifdef USE_OPENGL
00165 GLuint mGLImage;
00166 int mTexWidth, mTexHeight;
00167
00168 static bool mUseOpenGL;
00169 static int mTextureType;
00170 static int mTextureSize;
00171 #endif
00172 SDL_Surface *mImage;
00173 float mAlpha;
00174 };
00175
00179 class SubImage : public Image
00180 {
00181 public:
00185 SubImage(Image *parent, SDL_Surface *image,
00186 int x, int y, int width, int height);
00187 #ifdef USE_OPENGL
00188 SubImage(Image *parent, GLuint image, int x, int y,
00189 int width, int height, int texWidth, int textHeight);
00190 #endif
00191
00195 ~SubImage();
00196
00203 Image *getSubImage(int x, int y, int width, int height);
00204
00205 private:
00206 Image *mParent;
00207 };
00208
00209 #endif