Mercurial > hg > Game > Cerium
diff Renderer/Engine/viewerSDL.cc @ 539:3bc98f6d31ff draft
Reorganization..
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 12 Oct 2009 09:39:35 +0900 |
parents | |
children | c7afc21e448d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/viewerSDL.cc Mon Oct 12 09:39:35 2009 +0900 @@ -0,0 +1,60 @@ +#include "viewerSDL.h" +#include "Func.h" +#include "TaskManager.h" + +extern void post2runLoop(void *); + +extern + +void +ViewerSDL::video_init(TaskManager *manager) +{ + Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; + Uint32 *p; + + if (SDL_Init(sdl_flag) < 0) { + fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); + exit(1); + } + + screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE); + if (screen == NULL) { + fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); + SDL_Quit(); + exit(1); + } + + p = (Uint32*)manager->allocate(screen->pitch*height); + bitmap = SDL_CreateRGBSurfaceFrom((void *)p, + screen->w, screen->h, + screen->format->BitsPerPixel, + screen->pitch, + redMask, greenMask, blueMask, alphaMask); + + pixels = p; +} + +void +ViewerSDL::clean_pixels() +{ + //bzero(pixels, sizeof(int)*width*height); + SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); +} + +void +ViewerSDL::run_loop(HTaskPtr task_next) +{ + SDL_BlitSurface(bitmap, NULL, screen, NULL); + SDL_UpdateRect(screen, 0, 0, 0, 0); + + Viewer::run_loop(task_next); +} + +void +ViewerSDL::run_finish() +{ + free(bitmap->pixels); + SDL_FreeSurface(bitmap); + + Viewer::run_finish(); +}