Mercurial > hg > Game > Cerium
annotate Renderer/Engine/viewerSDL.cc @ 895:b662e9dd26b0 draft
add alignment of classes in SPU
width and height are automatically set in frame buffer API
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Jul 2010 17:23:49 +0900 |
parents | c7afc21e448d |
children | dbebc7afd08e |
rev | line source |
---|---|
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 } | |
895
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
30 this->width = screen->w; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
31 this->height = screen->h; |
b662e9dd26b0
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
32 this->bpp = screen->format->BitsPerPixel; |
539 | 33 |
34 p = (Uint32*)manager->allocate(screen->pitch*height); | |
35 bitmap = SDL_CreateRGBSurfaceFrom((void *)p, | |
36 screen->w, screen->h, | |
37 screen->format->BitsPerPixel, | |
38 screen->pitch, | |
39 redMask, greenMask, blueMask, alphaMask); | |
40 | |
728 | 41 return p; |
539 | 42 } |
43 | |
44 void | |
45 ViewerSDL::clean_pixels() | |
46 { | |
47 //bzero(pixels, sizeof(int)*width*height); | |
48 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); | |
49 } | |
50 | |
51 void | |
728 | 52 ViewerSDL::clear_screen() |
539 | 53 { |
54 SDL_BlitSurface(bitmap, NULL, screen, NULL); | |
55 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
56 } | |
57 | |
58 void | |
728 | 59 ViewerSDL::free_device() |
539 | 60 { |
61 free(bitmap->pixels); | |
62 SDL_FreeSurface(bitmap); | |
63 } |