the way I'm trying to draw it in SDL is having a SDL_Surface *tilemap; that I chop up, and render like this:
void apply_surface ( int sourceX, int sourceY, int sourceW, int sourceH, int x, int y, SDL_Surface* source, SDL_Surface* destination ){
// make a temporary rectangle to hold the offsets
SDL_Rect offset;
SDL_Rect sourceRect;
// give the offsets to the rectangle
offset.x = x;
offset.y = y;
sourceRect.x = sourceX;
sourceRect.y = sourceY;
sourceRect.h = sourceH;
sourceRect.w = sourceW;
// blit the surface
SDL_BlitSurface( source, &sourceRect, destination, &offset );
}
void render(){
for(int x = 0; x < lv.width; x++){
for(int y = 0; y < lv.height; y++){
if(x * lv.tileSize < 640 && y * lv.tileSize < 480){
int tileXCoord = 0;
int tileYCoord = 0;
int tileSheetWidth = tilemap->w / lv.tileSize;
if (lv.tile[x][y] != 0)
{
tileXCoord = lv.tile[x][y] % tileSheetWidth;
tileYCoord = lv.tile[x][y] / tileSheetWidth;
}
apply_surface(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, lv.tileSize, lv.tileSize, x * lv.tileSize, y * lv.tileSize, tilemap, screen);
}
}
}
}
This way brings my CPU way up, and drops my FPS.
I tried in SFML to draw the level to a Image, and than display that image (with cropping) but that made my ram go up to 50,000k.
so what I am asking is how can I draw a tilemap (in SDL) without making my cpu or ram go way up?