I'm making a simple tetris clone using SDL. I've used SDL in the past so I'm not new to this. But, I'm having a weird problem with the surfaces I'm using to store my blocks. Here's the relevant code blocks:
// Create a surface to store our blocks
SDL_Surface* g_BlockSource = NULL;
// An array of surfaces to hold the individual blocks
SDL_Surface* g_Blocks[NumberBlocks];
Then after my SDL initialization and all that I do the following:
// Load the bitmap that has our blocks on it
g_BlockSource = SDL_LoadBMP("data/blocks.bmp");
// Copy the individual blocks to the block array
SDL_Rect src;
int block;
for (block = 0; block < NumberBlocks; block++)
{
src.x = block * BlockWidth; // BlockWidth = 16
src.y = 0;
src.w = src.x + BlockHeight; // BlockHeight = 16
src.h = BlockHeight;
SDL_BlitSurface(g_BlockSource, &src, g_Blocks[block], NULL);
}
Then in my update function I use this to update the window
// Copy background image over to the Back surface
SDL_BlitSurface(g_Background, NULL, g_BackSurface, NULL);
// Draw the blocks to make sure they loaded right
SDL_BlitSurface(g_Blocks[1], NULL, g_BackSurface, NULL);
// Update the screen by copying the backsurface to the
// primary surface(actual window)
SDL_UpdateRect(g_BackSurface, 0, 0, 0, 0);
When I run it through VS, the background is displayed fine. But not the block that should be stored in g_Blocks[1]. None of the blocks are displayed.
Now, if instead of using a for loop to load the blocks, I split all the blocks up into seperate files and loaded them in by g_Blocks[0] = SDL_LoadBMP("block0.bmp");
It still doesn't workt that way,however if I run the exe from the folder, it displays the block fine.
What's wrong with my for loop or what am I missing here?
The bitmap contains 8 blocks(0-7) that are 16x16 in a horizontal row.