Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

graphics.h

Go to the documentation of this file.
00001 #ifndef __GRAPHICS_H
00002 #define __GRAPHICS_H
00003 
00004 #include <SDL/SDL.h>
00005 #include <string>
00006 #include <SDL/SDL_opengl.h>
00007 
00008 //typedef SDL_Surface   Surface;        // bleh
00009 typedef struct _Surface {
00010         GLuint w, h;    
00011         GLuint tx, ty;  
00012         GLuint tex;     
00013         GLuint ts;      
00014         SDL_Surface *surface;
00015 } Surface;
00016         
00017 typedef SDL_Rect        Rect;           // bleh
00018 
00019 using namespace std;
00020 
00021 class Graphics {
00022 public:
00024 
00033         Graphics(string title = "", int w = 1024, int h = 768, bool opengl = true);
00034 
00036 
00041         ~Graphics();
00042         
00044 
00047         void PreOpenGLInit();
00048 
00050 
00053         void PostOpenGLInit();
00054 
00056 
00060         void toggleFullscreen() { SDL_WM_ToggleFullScreen (hwSurface->surface); }
00061 
00063 
00067         bool isFullscreen() { return (hwSurface->surface->flags & SDL_FULLSCREEN) ? true : false; }
00068 
00070 
00074         bool isMouseLocked() { return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON); }
00075 
00077 
00081         static bool lockMouse(bool lock);
00082         
00084 
00087         bool isHWSurface() { return (hwSurface->surface->flags & (SDL_HWSURFACE|SDL_OPENGL)) ? true : false; }
00088 
00090 
00094         void hideMouse(bool f) { SDL_ShowCursor(!f); }
00095         
00097 
00100         Surface *getMainSurface() const { return hwSurface; }   
00101 
00103 
00107         void flip();
00108 
00109 
00111 
00118         void update(int x, int y, int w, int h);
00119 
00121 
00125         void update(Rect &r);   
00126         
00128 
00136         void blit(Surface *src, int dx = 0, int dy = 0);
00137 
00139 
00145         static void blit(Surface *target, int tx, int ty, Surface *src);
00146         
00148 
00154         static void blit(Surface *target, Rect &t, Surface *src, Rect &s);
00155         
00157 
00165         Surface *newSurface(int w, int h);
00166 
00168 
00174         static Surface *CreateSurfaceFrom(Surface *s);  // This will Copy old pixels
00175 
00177 
00185         static Surface *CreateSurfaceFrom(Surface *s, int nw, int nh);  // This won't.
00186         
00188 
00191         void deleteSurface(Surface *n);
00192 
00194 
00200         void fillSurface(Surface *n, int color);
00201 
00202         
00204 
00214         int color(int r, int g, int b, Surface *n = NULL);
00215         
00217 
00223         static Surface *loadImage(const char *fname);
00224 
00226 
00232         static Surface *loadImage(string fname);
00233         
00235 
00239         static Surface *freeImage(Surface *surf);
00240 
00242 
00249         static Surface *displayFormat(Surface *surf, bool alpha = false);
00250                 
00252 
00255         int getWidth() const { return width; }
00256 
00258 
00261         int getHeight() const { return height; }
00262 
00264         /*
00265          * Takes a surface pointer and creates a surface
00266          * suitable for OpenGL texture memory. The information
00267          * for the blit is stored within the surface.
00268          *
00269          * \param s the surface to be texturized.
00270          */
00271         static void TexturizeSurface (Surface *s);
00272 
00274 
00278         static void UntexturizeSurface (Surface *s);
00279 
00281 
00286         void RotateZ (float degrees);
00287 private:
00289 
00294         static void blitclip(Surface *dest, int drx, int dry, int drw, int drh,
00295                              Surface *src,  int srx, int sry, int srw, int srh);
00296 
00298 
00302         static void blitGLtexture (Surface *src, int srx, int sry, int srw, int srh,
00303                                           int drx, int dry, int drw, int drh);
00304 
00306         Surface *hwSurface;
00307 
00309         int width, height;
00310 };
00311 
00312 #endif

Generated on Sun Dec 8 12:02:19 2002 for nnc by doxygen1.3-rc1