Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
authorEli Gottlieb <eligottlieb@gmail.com>
Sun, 18 Jul 2010 23:51:47 -0400
changeset 4804b33752266d8f
parent 4803 a4c1df880690
child 4805 de3b3455f8ec
Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
test/testshape.c
     1.1 --- a/test/testshape.c	Sun Jul 18 23:36:39 2010 -0400
     1.2 +++ b/test/testshape.c	Sun Jul 18 23:51:47 2010 -0400
     1.3 @@ -11,6 +11,19 @@
     1.4  #define SHAPED_WINDOW_Y 150
     1.5  #define SHAPED_WINDOW_DIMENSION 640
     1.6  
     1.7 +void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions) {
     1.8 +	SDL_SelectRenderer(window);
     1.9 +	
    1.10 +	//Clear render-target to blue.
    1.11 +	SDL_SetRenderDrawColor(0x00,0x00,0xff,0xff);
    1.12 +	SDL_RenderClear();
    1.13 +	
    1.14 +	//Render the texture.
    1.15 +	SDL_RenderCopy(texture,&texture_dimensions,&texture_dimensions);
    1.16 +	
    1.17 +	SDL_RenderPresent();
    1.18 +}
    1.19 +
    1.20  int main(int argc,char** argv) {
    1.21          if(argc < 2) {
    1.22          	printf("SDL_Shape requires at least one bitmap file as argument.\n");
    1.23 @@ -93,6 +106,7 @@
    1.24  	SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.25  	SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    1.26  	SDL_SetWindowShape(window,pictures[current_picture],&mode);
    1.27 +	render(window,textures[current_picture],texture_dimensions);
    1.28  	while(should_exit == 0) {
    1.29  		event_pending = SDL_PollEvent(&event);
    1.30  		if(event_pending == 1) {
    1.31 @@ -109,22 +123,13 @@
    1.32  				SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.33  				SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    1.34  				SDL_SetWindowShape(window,pictures[current_picture],&mode);
    1.35 +				render(window,textures[current_picture],texture_dimensions);
    1.36 +				
    1.37  			}
    1.38  			if(event.type == SDL_QUIT)
    1.39  				should_exit = 1;
    1.40  			event_pending = 0;
    1.41  		}
    1.42 -		
    1.43 -		SDL_SelectRenderer(window);
    1.44 -	
    1.45 -		//Clear render-target to blue.
    1.46 -		SDL_SetRenderDrawColor(0x00,0x00,0xff,0xff);
    1.47 -		SDL_RenderClear();
    1.48 -		
    1.49 -		//Render the texture.
    1.50 -		SDL_RenderCopy(textures[current_picture],&texture_dimensions,&texture_dimensions);
    1.51 -		
    1.52 -		SDL_RenderPresent();
    1.53  	}
    1.54  	
    1.55  	//Free the textures.