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

2007年12月15日 星期六

第三個 SDL WINDOW 有透明~

//TEST_WINDOW 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(image2->format, 255, 0, 255);
////////////////////////////////////////////////////////
/////SDL_SetAlpha(surface, flage, alpha);////////
////////////////alpha透明度//////////////////////////
//////////////////0到255////////////////////////////////
///////////////////////////////////////////////////////
SDL_SetAlpha(image2, SDL_SRCALPHA, 100);
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);
}

//和第二個沒什麽差 只是改了 有透明度~~哈

沒有留言: