只要是有緣到此BLOG的閒人請投個票吧!給LINUX GAME一個機會!

2007年12月14日 星期五

第二個  SDL WINDOW 哈有圖了

//TEST_WINDOW2 source code.c

#include "stdio.h"
#include "stdlib.h"
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

int main(void)
{
SDL_Surface *screen;
SDL_Surface *image;
SDL_Surface *image2;
SDL_Rect src, dest;
//////////////開始///////////////////////////////
if(SDL_Init(SDL_INIT_VIDEO)!=0)
return 0;
SDL_WM_SetCaption ("TEST_WINDOW",NULL);
atexit(SDL_Quit);

screen=SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if(screen == NULL)
return 0;

image = IMG_Load("/home/byonk/Image/black.bmp");
if (image == NULL) {
printf("Unable to load bitmap.\n");
return 1;
}
image2 = IMG_Load("/home/byonk/Image/green.bmp");
if(image2 == NULL){
printf("Unable to load bitmap.\n");
return 1;
}
/* 背black*/
src.x = 0;
src.y = 0;
dest.w = image->w;
dest.h = image->h;
dest.x = 0;
dest.y = 0;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface(image, &src, screen, &dest);
/*前green*/
src.x=0;
src.y=0;
src.w = image2->w;
src.h = image2->h;
dest.x=30;
dest.x=90;
src.w = image2->w;
src.h = image2->h;

SDL_BlitSurface(image2, &src, screen, &dest);

/////////////////////////////////////////////////////////
///////////粉///紅色 是看不到的 碼是 255,0,255///////////////
/////////////////////////////////////////////////////////
Uint32 colorkey = SDL_MapRGB(image->format, 255, 0, 255);

SDL_SetColorKey(image2, SDL_SRCCOLORKEY, colorkey);
src.x = 0;
src.y = 0;
src.w = image2->w;
src.h = image2->h;
dest.x = screen->w - image->w - 30;
dest.y = 90;
dest.w = image2->w;
dest.h = image2->h;
SDL_BlitSurface(image2, &src, screen, &dest);



SDL_UpdateRect(screen, 0, 0, 0, 0);

SDL_Delay(10000);

}
\\和圖不太一樣 不過還是有效果

沒有留言: