view Renderer/Engine/viewerSDL.cc @ 895:bed529c55eda

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 4f77768d7a7f
children df5185513c2d
line wrap: on
line source

#include "viewerSDL.h"
#include "Func.h"
#include "TaskManager.h"
#include "viewer_types.h"

extern void post2runLoop(void *);

#define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK

ViewerSDL::ViewerSDL() {}
ViewerSDL::~ViewerSDL() {}

Uint32 *
ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height)
{
    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);
    }
    this->width = screen->w;
    this->height = screen->h;
    this->bpp = screen->format->BitsPerPixel;
    
    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);

    return p;
}

void
ViewerSDL::clean_pixels()
{
    //bzero(pixels, sizeof(int)*width*height);
    SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
}

void
ViewerSDL::clear_screen()
{
    SDL_BlitSurface(bitmap, NULL, screen, NULL);
    SDL_UpdateRect(screen, 0, 0, 0, 0);        
}

void
ViewerSDL::free_device()
{
    free(bitmap->pixels);
    SDL_FreeSurface(bitmap);
}