7 static SDL_Surface *fbsurf;
9 static Rect screen_rect = {0, 0, 1024, 768};
10 static Rect clipping_rect;
12 static int color_depth = 32; // bits per pixel
14 static Pixmap *pixmap;
18 if(SDL_Init(SDL_INIT_VIDEO) == -1) {
19 fprintf(stderr, "failed to initialize SDL\n");
23 if(!(fbsurf = SDL_SetVideoMode(screen_rect.width, screen_rect.height, color_depth, 0))) {
24 fprintf(stderr, "failed to set video mode\n");
30 pixmap->width = screen_rect.width;
31 pixmap->height = screen_rect.height;
32 pixmap->pixels = (unsigned char*)fbsurf->pixels;
34 set_clipping_rect(screen_rect);
46 unsigned char *get_framebuffer()
48 return (unsigned char*)fbsurf->pixels;
51 Pixmap *get_framebuffer_pixmap()
56 Rect get_screen_size()
66 /*void set_clipping_rect(const Rect &rect)
68 clipping_rect = rect_intersection(rect, screen_rect);
71 sdl_rect.x = clipping_rect.x;
72 sdl_rect.y = clipping_rect.y;
73 sdl_rect.w = clipping_rect.width;
74 sdl_rect.h = clipping_rect.height;
76 SDL_SetClipRect(fbsurf, &sdl_rect);
79 const Rect &get_clipping_rect()
84 void clear_screen(int r, int g, int b)
86 fill_rect(screen_rect, r, g, b);
89 void fill_rect(const Rect &rect, int r, int g, int b)
91 uint32_t color = ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
96 sdl_rect.w = rect.width;
97 sdl_rect.h = rect.height;
99 SDL_FillRect(fbsurf, &sdl_rect, color);
102 void set_cursor_visibility(bool visible)
108 SDL_UpdateRect(fbsurf, 0, 0, 0, 0);