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

add sgchangeFB,SDL
author hiroki@localhost.localdomain
date Tue, 08 Dec 2009 16:52:04 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
692
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
1 #include "sgchangeSDL.h"
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
2 #include "Func.h"
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
3 #include "TaskManager.h"
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
4
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
5 extern void post2runLoop(void *);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
6
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
7 extern
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
8
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
9 void
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
10 SgChangeSDL::video_init(TaskManager *manager)
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
11 {
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
12 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
13 Uint32 *p;
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
14
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
15 if (SDL_Init(sdl_flag) < 0) {
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
16 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
17 exit(1);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
18 }
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
19
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
20 screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
21 if (screen == NULL) {
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
22 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
23 SDL_Quit();
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
24 exit(1);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
25 }
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
26
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
27 p = (Uint32*)manager->allocate(screen->pitch*height);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
28 bitmap = SDL_CreateRGBSurfaceFrom((void *)p,
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
29 screen->w, screen->h,
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
30 screen->format->BitsPerPixel,
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
31 screen->pitch,
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
32 redMask, greenMask, blueMask, alphaMask);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
33
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
34 pixels = p;
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
35 }
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
36
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
37 void
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
38 SgChangeSDL::clean_pixels()
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
39 {
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
40 //bzero(pixels, sizeof(int)*width*height);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
41 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
42 }
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
43
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
44 void
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
45 SgChangeSDL::run_loop(HTaskPtr task_next)
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
46 {
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
47 SDL_BlitSurface(bitmap, NULL, screen, NULL);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
48 SDL_UpdateRect(screen, 0, 0, 0, 0);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
49
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
50 SgChange::run_loop(task_next);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
51 }
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
52
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
53 void
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
54 SgChangeSDL::run_finish()
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
55 {
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
56 free(bitmap->pixels);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
57 SDL_FreeSurface(bitmap);
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
58
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
59 SgChange::run_finish();
50750b118116 add sgchangeFB,SDL
hiroki@localhost.localdomain
parents:
diff changeset
60 }