539
|
1 #include "viewerSDL.h"
|
|
2 #include "Func.h"
|
|
3 #include "TaskManager.h"
|
728
|
4 #include "viewer_types.h"
|
539
|
5
|
|
6 extern void post2runLoop(void *);
|
|
7
|
728
|
8 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
|
539
|
9
|
728
|
10 ViewerSDL::ViewerSDL() {}
|
|
11 ViewerSDL::~ViewerSDL() {}
|
|
12
|
|
13 Uint32 *
|
|
14 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height)
|
539
|
15 {
|
|
16 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
|
|
17 Uint32 *p;
|
|
18
|
|
19 if (SDL_Init(sdl_flag) < 0) {
|
|
20 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
|
|
21 exit(1);
|
|
22 }
|
|
23
|
|
24 screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
|
|
25 if (screen == NULL) {
|
|
26 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
|
|
27 SDL_Quit();
|
|
28 exit(1);
|
|
29 }
|
|
30
|
|
31 p = (Uint32*)manager->allocate(screen->pitch*height);
|
|
32 bitmap = SDL_CreateRGBSurfaceFrom((void *)p,
|
|
33 screen->w, screen->h,
|
|
34 screen->format->BitsPerPixel,
|
|
35 screen->pitch,
|
|
36 redMask, greenMask, blueMask, alphaMask);
|
|
37
|
728
|
38 return p;
|
539
|
39 }
|
|
40
|
|
41 void
|
|
42 ViewerSDL::clean_pixels()
|
|
43 {
|
|
44 //bzero(pixels, sizeof(int)*width*height);
|
|
45 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
|
|
46 }
|
|
47
|
|
48 void
|
728
|
49 ViewerSDL::clear_screen()
|
539
|
50 {
|
|
51 SDL_BlitSurface(bitmap, NULL, screen, NULL);
|
|
52 SDL_UpdateRect(screen, 0, 0, 0, 0);
|
|
53 }
|
|
54
|
|
55 void
|
728
|
56 ViewerSDL::free_device()
|
539
|
57 {
|
|
58 free(bitmap->pixels);
|
|
59 SDL_FreeSurface(bitmap);
|
|
60 }
|