view TaskManager/Test/test_render/viewerSDL.cpp @ 174:559b48b69b76

getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
author gongo@localhost.localdomain
date Fri, 12 Dec 2008 12:23:20 +0900
parents d1f2ce3bdb2f
children 897aeb144569
line wrap: on
line source

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

extern void post2runLoop(void *);

extern

void
ViewerSDL::video_init()
{
    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->malloc(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);
}

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

    Viewer::run_loop();
}

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

    Viewer::run_finish();
}