mmm the atachments are in te email to the mailing list… here’s the code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<SDL/SDL.h>
#include<SDL/SDL_image.h>
#include<SDL/SDL_mixer.h>
#define screen_w 800
#define screen_h 480
#define screen_bpp 16
SDL_Window *window;
int main (int argc, char * argv[])
{
/* INIT STARTS*/
if((SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0))
{
fprintf(stderr,“Could not Initialize SDL.\nError: %s\n”, SDL_GetError());
exit (-1);
}
if(Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
fprintf(stderr,“Warning: Couldn’t set 44100 Hz 16-bit audio\n: %s\n”, SDL_GetError());
window = SDL_CreateWindow("Dragon Memory", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_w, screen_h, (SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL));
fprintf(stderr,"Warning: Couldn't set 44100 Hz 16-bit audio\n: %s\n", SDL_GetError());
if(!window) exit(2);
if (SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTFLIP2) != 0)
printf("Unable to create renderer: %s\n", SDL_GetError());
SDL_SelectRenderer(window);
SDL_ShowCursor(1);
/* INIT ENDS*/
SDL_Surface *Ssprite;
SDL_Texture *Tsprite;
Ssprite = IMG_Load("sprite.png");
SDL_Rect RspriteSrc;
RspriteSrc.x = 0;
RspriteSrc.y = 0;
RspriteSrc.w = Ssprite->w;
RspriteSrc.h = Ssprite->h;
SDL_Color color;
SDL_GetRGB(*(Uint32 *)Ssprite->pixels, Ssprite->format, &color.r, &color.g, &color.b);
SDL_SetColorKey(Ssprite, SDL_SRCCOLORKEY, SDL_MapRGB(Ssprite->format, color.r, color.g, color.b));
Tsprite = SDL_CreateTextureFromSurface(0, Ssprite);
SDL_RenderCopy(Tsprite, &RspriteSrc, NULL);
SDL_RenderPresent();
SDL_Delay(2000);
SDL_Quit();
fprintf(stderr,"\nBye bye.\n");
return 0;
}
i compile it with
Code:
g++ -c -g dragon.cpp
g++ -o dragon $(sdl-config --libs --cflags) -lSDL_image -lSDL_mixer dragon.o
and the sprite uses the firts pixel color as a colorkey