test/testshape.c
changeset 4802 f14a8c05f5bb
parent 4800 6d4be626225f
child 4803 a4c1df880690
     1.1 --- a/test/testshape.c	Sun Jul 18 22:24:52 2010 -0400
     1.2 +++ b/test/testshape.c	Sun Jul 18 23:05:40 2010 -0400
     1.3 @@ -27,8 +27,8 @@
     1.4  	for(i=0;i<num_pictures;i++)
     1.5  		pictures[i] = NULL;
     1.6  	for(i=0;i<num_pictures;i++) {
     1.7 -		SDL_Surface *original = SDL_LoadBMP(argv[i+1]);
     1.8 -		if(original == NULL) {
     1.9 +		pictures[i] = SDL_LoadBMP(argv[i+1]);
    1.10 +		if(pictures[i] == NULL) {
    1.11  			int j = 0;
    1.12  			for(j=0;j<num_pictures;j++)
    1.13  				if(pictures[j] != NULL)
    1.14 @@ -38,43 +38,6 @@
    1.15  			printf("Could not load surface from named bitmap file.\n");
    1.16  			exit(-3);
    1.17  		}
    1.18 -		//THIS CONVERSION ROUTINE IS FRAGILE!  It relies in the fact that only certain portions of the format structure must be filled in to use it.
    1.19 -		SDL_PixelFormat format = {NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    1.20 -		int bpp = 0;
    1.21 -		SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&bpp,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask);
    1.22 -		format.BitsPerPixel = bpp;
    1.23 -		format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0);
    1.24 -		pictures[i] = SDL_ConvertSurface(original,&format,0);
    1.25 -		//We have no more need of the original now that we have our desired format.
    1.26 -		SDL_FreeSurface(original);
    1.27 -		if(pictures[i] == NULL) {
    1.28 -			int j = 0;
    1.29 -			for(j=0;j<num_pictures;j++)
    1.30 -				if(pictures[j] != NULL)
    1.31 -					SDL_FreeSurface(pictures[j]);
    1.32 -			free(pictures);
    1.33 -			SDL_VideoQuit();
    1.34 -			printf("Could not convert bitmap surface to desired format.\n");
    1.35 -			exit(-3);
    1.36 -		}
    1.37 -		
    1.38 -		if(SDL_MUSTLOCK(pictures[i]))
    1.39 -			SDL_LockSurface(pictures[i]);
    1.40 -			
    1.41 -		void* pixels = pictures[i]->pixels;
    1.42 -		unsigned int pitch = pictures[i]->pitch;
    1.43 -		int y =0,x = 0;
    1.44 -		for(y=0;y<pictures[i]->h;y++)
    1.45 -			for(x=0;x<pictures[i]->w;x++) {
    1.46 -				Uint32* pixel = pixels + y * pitch + x * pictures[i]->format->BytesPerPixel;
    1.47 -				Uint8 r = 0,g = 0,b = 0;
    1.48 -				SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b);
    1.49 -				//if(r == g == b == 0xff)
    1.50 -				//	*pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0);
    1.51 -			}
    1.52 -			
    1.53 -		if(SDL_MUSTLOCK(pictures[i]))
    1.54 -			SDL_UnlockSurface(pictures[i]);
    1.55  	}
    1.56  	
    1.57  	SDL_Window *window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
    1.58 @@ -123,12 +86,12 @@
    1.59  	event_pending = SDL_PollEvent(&event);
    1.60  	unsigned int current_picture = 0;
    1.61  	SDL_WindowShapeMode mode = {ShapeModeDefault,1};
    1.62 -	SDL_SetWindowShape(window,pictures[current_picture],&mode);
    1.63  	int mouse_down = 0;
    1.64 -	Uint32 format,access;
    1.65 +	Uint32 format = 0,access = 0;
    1.66  	SDL_Rect texture_dimensions = {0,0,0,0};
    1.67  	SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h);
    1.68  	SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
    1.69 +	SDL_SetWindowShape(window,pictures[current_picture],&mode);
    1.70  	while(should_exit == 0) {
    1.71  		event_pending = SDL_PollEvent(&event);
    1.72  		if(event_pending == 1) {