Repeat an image for background

Hi everybody,
I have a answer for you.

I have a small image, 4x4 all black, and I want use thet for my
background, 320x240.

How can I repeat this image for all the screen?

tnx

-------------- next part --------------
An embedded message was scrubbed…From: nightiger_spp@libero.it (NighTiger)
Subject: Repeat an image for background
Date: 07 Jul 2003 17:25:43 +0200
Size: 516
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030708/c2b7c4c0/attachment.eml

I have a small image, 4x4 all black, and I want use thet for my
background, 320x240.

How can I repeat this image for all the screen?

The following snippet is taken directly from my work-in-progress game.
It draws a tile with specifig offsets to a surface ‘bmp’.

You could use it like this:
draw_tiled(screen, your_4x4_tile, 0, 0);

Manipulating the offsets realtime result in rolling background.
And if your resolution is 320x240, you should define those
SCREEN_W and SCREEN_H vars.

Like this:
#define SCREEN_W 320
#define SCREEN_H 240

Here’s the snippet:

// Draw a tiled graphic
void draw_tiled(SDL_Surface *bmp, SDL_Surface *tile, int offset_x, int
offset_y) {

// Draw the background tiles
int x = offset_x, y = offset_y;
int w = tile->w;
int h = tile->h;
while(1) {
	// Draw a tile to the current position
	SDL_Rect r;
	r.x = x;
	r.y = y;
	r.w = w;
	r.h = h;
	
	SDL_BlitSurface(tile, NULL, bmp, &r);
	
	// Advance
	x += w;
	if(x >= SCREEN_W) {
		x = offset_x;
		y += h;
		if(y >= SCREEN_H)
			break;
	}
}

}

Hope this helps.

Ps. I don’t understand why you want to use 4x4 pure black surface all
over the screen, as you could simply SDLFillRect the screen to black.
But perhaps you manipulate the 4x4 surface runtime or somethin’…–
Mika Halttunen
@Mika_Halttunen