Rectangles demo (SDL_RenderFill) gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Fri, 18 Jul 2008 20:52:18 +0000
branchgsoc2008_iphone
changeset 23850705e8ebe951
parent 2384 6a946f3155d8
child 2386 c5cbbba41c65
Rectangles demo (SDL_RenderFill)
XCodeiPhoneOS/Demos/src/rectangles.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/XCodeiPhoneOS/Demos/src/rectangles.c	Fri Jul 18 20:52:18 2008 +0000
     1.3 @@ -0,0 +1,76 @@
     1.4 +/*
     1.5 + *	rectangles.c
     1.6 + *	written by Holmes Futrell
     1.7 + *	use however you want
     1.8 +*/
     1.9 +
    1.10 +#include "SDL.h"
    1.11 +#include <time.h>
    1.12 +#include "common.h"
    1.13 +
    1.14 +void render(void) {
    1.15 +	
    1.16 +	Uint8 r, g, b;
    1.17 +	/*  Come up with a random rectangle */
    1.18 +	SDL_Rect rect;
    1.19 +	rect.w = randomInt(64, 128);
    1.20 +	rect.h = randomInt(64, 128);
    1.21 +	rect.x = randomInt(0, SCREEN_WIDTH);
    1.22 +	rect.y = randomInt(0, SCREEN_HEIGHT);
    1.23 +	
    1.24 +	/* Come up with a random color */
    1.25 +	r = randomInt(50, 255);
    1.26 +	g = randomInt(50, 255);
    1.27 +	b = randomInt(50, 255);
    1.28 +
    1.29 +	/*  Fill the rectangle in the color */
    1.30 +	SDL_RenderFill(r, g, b, 255, &rect);
    1.31 +	
    1.32 +	/* update screen */
    1.33 +	SDL_RenderPresent();
    1.34 +	
    1.35 +}
    1.36 +
    1.37 +int main(int argc, char *argv[]) {
    1.38 +	
    1.39 +	SDL_WindowID windowID;
    1.40 +	int done;
    1.41 +	SDL_Event event;
    1.42 +	
    1.43 +	/* initialize SDL */
    1.44 +	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.45 +		fatalError("Could not initialize SDL");
    1.46 +	}
    1.47 +		
    1.48 +	/* seed random number generator */
    1.49 +	srand(time(NULL));
    1.50 +	
    1.51 +	/* create window and renderer */
    1.52 +	windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    1.53 +	if (windowID == 0) {
    1.54 +		fatalError("Could not initialize Window");
    1.55 +	}
    1.56 +	if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
    1.57 +		fatalError("Could not create renderer");
    1.58 +	}
    1.59 +			
    1.60 +	/* Fill screen with black */
    1.61 +	SDL_RenderFill(0,0,0,0, NULL);
    1.62 +				
    1.63 +    /* Enter render loop, waiting for user to quit */
    1.64 +	done = 0;
    1.65 +	while(!done) {
    1.66 +        while (SDL_PollEvent(&event)) {
    1.67 +            if (event.type == SDL_QUIT) {
    1.68 +				done = 1;
    1.69 +            }
    1.70 +        }
    1.71 +		render();
    1.72 +		SDL_Delay(1);
    1.73 +	}
    1.74 +	
    1.75 +	/* shutdown SDL */
    1.76 +	SDL_Quit();
    1.77 +	
    1.78 +	return 0;
    1.79 +}