5 #include <SDL/SDL_image.h>
14 #include <yaml-cpp/yaml.h>
40 for(
unsigned int j=0, end = frame->
collisionData.size(); j < end; ++j)
52 string buffer,file, filename;
53 Uint8 transparency[3];
55 animFile=
"ArtAssets/Sprites/"+animFile;
58 ifstream fin(animFile.c_str());
62 printf(
"Error opening %s\n\n",animFile.c_str());
67 YAML::Parser parser(fin);
70 while(parser.GetNextDocument(doc)) {
72 Frames = vector<SpriteFrame*>();
75 for(
unsigned int i=0, count = doc.size(); i<count; i++) {
79 file=doc[i][
"file"].to<
string>();
80 filename =
"Textures/"+file;
83 pause=doc[i][
"pause"].to<
unsigned int>();
86 transparency[0]=doc[i][
"transparency"][
"r"].to<
unsigned int>();
87 transparency[1]=doc[i][
"transparency"][
"g"].to<
unsigned int>();
88 transparency[2]=doc[i][
"transparency"][
"b"].to<
unsigned int>();
91 double x=doc[i][
"offset"][
"x"].to<
double>();
92 double y=doc[i][
"offset"][
"y"].to<
double>();
94 for(
unsigned int j=0; j<doc[i][
"collision"].size();j++) {
95 if(doc[i][
"collision"][j][
"type"].to<string>()==
"circle") {
96 double xOffset = doc[i][
"collision"][j][
"offset"][
"x"].to<
double>();
97 double yOffset = doc[i][
"collision"][j][
"offset"][
"y"].to<
double>();
98 double radius = doc[i][
"collision"][j][
"radius"].to<
double>();
99 string name = doc[i][
"collision"][j][
"name"].to<
string>();
102 else if(doc[i][
"collision"][j][
"type"].to<string>()==
"rectangle") {
103 double xOffset = doc[i][
"collision"][j][
"offset"][
"x"].to<
double>();
104 double yOffset = doc[i][
"collision"][j][
"offset"][
"y"].to<
double>();
105 double width = doc[i][
"collision"][j][
"width"].to<
double>();
106 double height = doc[i][
"collision"][j][
"height"].to<
double>();
107 string name = doc[i][
"collision"][j][
"name"].to<
string>();
112 SDL_Surface *temp=NULL;
113 if((temp =
LoadImage(filename)) == NULL)
return false;
116 SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, transparency[0], transparency[1], transparency[2]));
119 SDL_Surface* surface = SDL_DisplayFormatAlpha(temp);
120 SDL_FreeSurface(temp);
121 frame->
width=surface->w;
125 if(surface->w <= 0 || surface->h <= 0 ){
126 cout<<
"Error, "+file+
" loaded improperly"<<endl;
131 if ( (surface->w & (surface->w - 1)) != 0 ) {
132 cout<<
"warning: "<<file<<
"'s width is not a power of 2"<<endl;
136 if ( (surface->h & (surface->h - 1)) != 0 ) {
137 cout<<
"warning: "<<file<<
"'s height is not a power of 2"<<endl;
142 GLint nofcolors=surface->format->BytesPerPixel;
144 GLenum texture_format=0;
147 if(surface->format->Rmask==0x000000ff)
148 texture_format=GL_RGBA;
150 texture_format=GL_BGRA;
151 if(!(nofcolors==4 || nofcolors==3))
153 cout<<
"warning: the image is not truecolor...this will break "<<endl;
160 glBindTexture( GL_TEXTURE_2D, frame->
tex.
image );
163 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
166 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
168 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
171 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
172 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
174 glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface->w, surface->h, 0,
175 texture_format, GL_UNSIGNED_BYTE, surface->pixels );
177 SDL_FreeSurface(surface);
180 frame->
pause = pause;
181 unsigned int mW = frame->
width;
182 unsigned int mH = frame->
height;
196 }
catch(YAML::ParserException& e) {
197 std::cout << e.what() <<
"\n";