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