I am new to SDL but have used C++ a fair bit over the years. I'm struggling with displaying sprites with a scale. EG. Here I am trying to draw a grid of squares (ie. Tetris) but the source BMP is 32x32 and I wish to display it at 16x16. The CELL_SIZE is const int =16;

It seems to me from looking at the function to the best of my ability that the dstrect parameter is for the location AND size. The location works (ie. the squares are drawn into the grid at the correct x,y but the width/height remains 32 for some reason.

void TetrisSDL::Update()
        //draw filled squares:
        std::vector<SDL_Rect*> rects;
        for(unsigned int x=0; x<GRID_WIDTH; x++)
            for(unsigned int y=0; y<GRID_HEIGHT; y++)
                if(Grid[x + (y*GRID_WIDTH)]!=0)
                    SDL_Rect* rect=new SDL_Rect();
        for(unsigned int i=0; i<rects.size(); i++)
            int blit = SDL_BlitSurface(BlockSprite, NULL, winSurface, rects[i]);
            printf("Drawing Rect (blit result=%d) %d / %d,%d,%d,%d '\n'", blit, i, rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h);

But my printf log at the end tells me that Rect[i].w and h is actually 32 (ie. the size of the source and NOT the CELL_SIZE)

  • \$\begingroup\$ According to the doc, you are getting the expected behaviour, "Only the position is used in the dstrect (the width and height are ignored)." \$\endgroup\$
    – Vaillancourt
    May 3 at 15:16
  • 1
    \$\begingroup\$ Thank you. I found out I should actually use BlitScaled() instead of BlitSurface() \$\endgroup\$
    – DaveGold
    May 3 at 18:29


You must log in to answer this question.

Browse other questions tagged .