comparison Renderer/Engine/sgchangeSDL.cc @ 692:50750b118116

add sgchangeFB,SDL
author hiroki@localhost.localdomain
date Tue, 08 Dec 2009 16:52:04 +0900
parents
children
comparison
equal deleted inserted replaced
691:9d1bcc07734b 692:50750b118116
1 #include "sgchangeSDL.h"
2 #include "Func.h"
3 #include "TaskManager.h"
4
5 extern void post2runLoop(void *);
6
7 extern
8
9 void
10 SgChangeSDL::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 SgChangeSDL::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 SgChangeSDL::run_loop(HTaskPtr task_next)
46 {
47 SDL_BlitSurface(bitmap, NULL, screen, NULL);
48 SDL_UpdateRect(screen, 0, 0, 0, 0);
49
50 SgChange::run_loop(task_next);
51 }
52
53 void
54 SgChangeSDL::run_finish()
55 {
56 free(bitmap->pixels);
57 SDL_FreeSurface(bitmap);
58
59 SgChange::run_finish();
60 }