comparison LoadSprite.c @ 115:31dd5c07f7c1

class OBJECT:SceanGraph
author e085768
date Wed, 15 Jun 2011 23:31:59 +0900
parents
children
comparison
equal deleted inserted replaced
113:8c96cadde050 115:31dd5c07f7c1
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5 #include <math.h>
6 #include <time.h>
7 #include <SDL.h>
8 #include "SDL_opengl.h"
9 #include "SDL_image.h"
10 #include "object.h"
11 #include "xml.h"
12 #include "tree_controll.h"
13 #include "LoadSprite.h"
14
15 //#define bmp_file "./s-dandy.bmp"
16
17 SDL_Surface *sprite;
18
19 SDL_Surface *LoadSprite(SURFACE *surfaces)
20 {
21 SDL_Surface *image;
22 SDL_Surface *temp;
23
24 /* Load the sprite image */
25 image = IMG_Load(surfaces->image_name);
26
27 if ( image == NULL ) {
28 fprintf(stderr, "Couldn't load %s: %s", surfaces->image_name, SDL_GetError());
29 printf("can't not load image_file\n");
30 return NULL;
31 }
32
33 /* Set transparent pixel as the pixel at (0,0) */
34 /* if ( image->format->palette ) {
35 SDL_SetColorKey(image, (SDL_SRCCOLORKEY|SDL_RLEACCEL), *(Uint8 *)image->pixels);
36 }*/
37 SDL_SetColorKey(image, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(image->format, 0, 0, 0));
38
39 /* Convert sprite to video format */
40 temp = SDL_DisplayFormat(image);
41 SDL_FreeSurface(image);
42 if ( temp == NULL ) {
43 fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError());
44 return NULL;
45 }
46 image = temp;
47 return image;
48
49 /* We're ready to roll. */
50 }