diff LoadSprite.c @ 0:435ac1cdb64e

create task dandy directry.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Sat, 11 Dec 2010 21:25:28 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoadSprite.c	Sat Dec 11 21:25:28 2010 +0900
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <math.h>
+#include <time.h>
+#include <SDL.h>
+#include "SDL_opengl.h"
+#include "SDL_image.h"
+#include "object.h"
+#include "xml.h"
+#include "tree_controll.h"
+#include "LoadSprite.h"
+
+//#define bmp_file "./s-dandy.bmp"
+
+SDL_Surface *sprite;
+
+SDL_Surface *LoadSprite(SURFACE *surfaces)
+{
+  SDL_Surface *image;
+  SDL_Surface *temp;
+  
+  /* Load the sprite image */
+  image = IMG_Load(surfaces->image_name);
+  
+  if ( image == NULL ) {
+    fprintf(stderr, "Couldn't load %s: %s", surfaces->image_name, SDL_GetError());
+    printf("can't not load image_file\n");
+    return NULL;
+  }
+  
+  /* Set transparent pixel as the pixel at (0,0) */
+  /* if ( image->format->palette ) {
+    SDL_SetColorKey(image, (SDL_SRCCOLORKEY|SDL_RLEACCEL), *(Uint8 *)image->pixels);
+    }*/
+  SDL_SetColorKey(image, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(image->format, 0, 0, 0));
+  
+  /* Convert sprite to video format */
+  temp = SDL_DisplayFormat(image);
+  SDL_FreeSurface(image);
+  if ( temp == NULL ) {
+    fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError());
+    return NULL;
+  }
+  image = temp;
+  return image;
+
+  /* We're ready to roll. */
+}