void CEGALatch::loadTilemap(GsTilemap &Tilemap, CPlanes &Planes, const int episode, const std::string &path) { Tilemap.CreateSurface( gGraphics.Palette.m_Palette, SDL_SWSURFACE, m_num16tiles, 4, 13 ); SDL_Surface *sfc = Tilemap.getSDLSurface(); SDL_FillRect(sfc,NULL, 0); if(SDL_MUSTLOCK(sfc)) SDL_LockSurface(sfc); Uint8 *u_pixel = (Uint8*) sfc->pixels; for(int p=0;p<4;p++) Planes.readPlaneofTiles(p, u_pixel, 13, 16, m_num16tiles); if(SDL_MUSTLOCK(sfc)) SDL_UnlockSurface(sfc); // Load Hi-Colour, VGA, SVGA Tiles into the tilemap if(Tilemap.loadHiresTile("gfx/ck" + itoa(episode) + "tiles", path)) { gLogging.textOut(GREEN, "Additional VGA Bitmap for the Tileset has been loaded successfully!"); } // Adapt the tilemap to the display, so they are faster blit //Tilemap.optimizeSurface(); }
void CEGASprit::CreateYellowSpriteofTile( GsTilemap &tilemap, Uint16 tile, GsSprite& sprite ) { SDL_Rect tile_rect; tile_rect.x = 16*(tile%13); tile_rect.y = 16*(tile/13); tile_rect.w = tile_rect.h= 16; sprite.setSize(tile_rect.w, tile_rect.h); sprite.createSurface( gVideoDriver.mpVideoEngine->getBlitSurface()->flags, gGraphics.Palette.m_Palette ); sprite.optimizeSurface(); SDL_Surface *src_sfc = sprite.getSDLSurface(); BlitSurface(tilemap.getSDLSurface(), &tile_rect, src_sfc, NULL); if(SDL_MUSTLOCK(src_sfc)) SDL_LockSurface(src_sfc); if(src_sfc->format->BitsPerPixel == 8) return; // The first pixel is usually the transparent one on items. Use it! Uint8* pixel = (Uint8*)src_sfc->pixels; Uint32 transparent_colour; Uint32 colour; Uint8 r,g,b,a; memcpy(&transparent_colour, pixel, src_sfc->format->BytesPerPixel); for(Uint8 x=0 ; x<16 ; x++) { for(Uint8 y=0 ; y<16 ; y++) { memcpy(&colour, pixel, src_sfc->format->BytesPerPixel); SDL_GetRGBA( colour, src_sfc->format, &r, &g, &b, &a ); if( colour == transparent_colour ) a = 0; if( r!=0 && g!=0 && b!=0 && a!=0) r = g = 255; colour = SDL_MapRGBA( src_sfc->format, r, g, b, a ); memcpy( pixel, &colour ,src_sfc->format->BytesPerPixel); pixel += src_sfc->format->BytesPerPixel; } } if(SDL_MUSTLOCK(src_sfc)) SDL_UnlockSurface(src_sfc); }