Mercurial > hg > Game > Cerium
annotate Renderer/Engine/viewerSDL.cc @ 988:da1cec21f0c9 draft akira
fix for double buffer
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 02 Oct 2010 03:48:39 +0900 |
parents | dbebc7afd08e |
children | d3b20d63057e |
rev | line source |
---|---|
539 | 1 #include "viewerSDL.h" |
2 #include "Func.h" | |
3 #include "TaskManager.h" | |
728 | 4 #include "viewer_types.h" |
539 | 5 |
984 | 6 #define UGA 1 |
7 | |
539 | 8 extern void post2runLoop(void *); |
9 | |
728 | 10 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
539 | 11 |
728 | 12 ViewerSDL::ViewerSDL() {} |
13 ViewerSDL::~ViewerSDL() {} | |
14 | |
15 Uint32 * | |
16 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height) | |
539 | 17 { |
18 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; | |
19 Uint32 *p; | |
20 | |
21 if (SDL_Init(sdl_flag) < 0) { | |
22 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); | |
23 exit(1); | |
24 } | |
25 | |
984 | 26 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE); |
539 | 27 if (screen == NULL) { |
28 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); | |
29 SDL_Quit(); | |
30 exit(1); | |
31 } | |
895
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
32 this->width = screen->w; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
33 this->height = screen->h; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
34 this->bpp = screen->format->BitsPerPixel; |
539 | 35 |
36 p = (Uint32*)manager->allocate(screen->pitch*height); | |
37 bitmap = SDL_CreateRGBSurfaceFrom((void *)p, | |
38 screen->w, screen->h, | |
39 screen->format->BitsPerPixel, | |
40 screen->pitch, | |
41 redMask, greenMask, blueMask, alphaMask); | |
42 | |
728 | 43 return p; |
539 | 44 } |
45 | |
46 void | |
47 ViewerSDL::clean_pixels() | |
48 { | |
49 //bzero(pixels, sizeof(int)*width*height); | |
50 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); | |
51 } | |
52 | |
53 void | |
728 | 54 ViewerSDL::clear_screen() |
539 | 55 { |
984 | 56 #if !UGA |
539 | 57 SDL_BlitSurface(bitmap, NULL, screen, NULL); |
58 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
984 | 59 #endif |
60 } | |
61 | |
62 uint32_t * | |
63 ViewerSDL::flip_screen(uint32_t *old) | |
64 { | |
65 #if UGA | |
66 SDL_BlitSurface(bitmap,NULL,screen,NULL); | |
67 SDL_UpdateRect(screen,0,0,0,0); | |
68 #endif | |
69 return old; | |
539 | 70 } |
71 | |
72 void | |
728 | 73 ViewerSDL::free_device() |
539 | 74 { |
75 free(bitmap->pixels); | |
76 SDL_FreeSurface(bitmap); | |
77 } |