Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4259746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:49:36+00:00 2026-05-21T05:49:36+00:00

Okay, so I’m trying to draw a tilemap on the screen with SDL, and

  • 0

Okay, so I’m trying to draw a tilemap on the screen with SDL, and my fps is really bad cause of it. And I’ve tried doing it in SFML a different way, but that way makes my ram useage go way up.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:49:36+00:00Added an answer on May 21, 2026 at 5:49 am
    • Make sure that when you load tilemap, that you convert it to the same format as the screen, so that blitting doesn’t have to perform any conversion. SDL_DisplayFormat does this for you.
    • Where are you calling render()? Make sure it’s called once per frame, no more, no less.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.