本文整理汇总了C++中SDL_DisplayFormatAlpha函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_DisplayFormatAlpha函数的具体用法?C++ SDL_DisplayFormatAlpha怎么用?C++ SDL_DisplayFormatAlpha使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_DisplayFormatAlpha函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IMG_Load
/**
* Icon set shared by all menus
*/
void MenuManager::loadIcons() {
icons = IMG_Load(mods->locate("images/icons/icons_small.png").c_str());
if(!icons) {
fprintf(stderr, "Couldn't load icons: %s\n", IMG_GetError());
SDL_Quit();
std::exit(1);
}
// optimize
SDL_Surface *cleanup = icons;
icons = SDL_DisplayFormatAlpha(icons);
SDL_FreeSurface(cleanup);
}
示例2: SDL_FreeSurface
void GameStateLoad::loadPortrait(int slot) {
SDL_FreeSurface(portrait);
portrait = NULL;
if (stats[slot].name == "") return;
portrait = IMG_Load((PATH_DATA + "images/portraits/" + stats[slot].portrait + ".png").c_str());
if (!portrait) return;
// optimize
SDL_Surface *cleanup = portrait;
portrait = SDL_DisplayFormatAlpha(portrait);
SDL_FreeSurface(cleanup);
}
示例3: IMG_Load
void Splash::loadTexture(void)
{
SDL_Surface *image = IMG_Load("data/foka logo.png");
SDL_DisplayFormatAlpha(image);
SDL_Rect imageRect;
imageRect.x = 0;
imageRect.y = 0;
imageRect.w = 700;
imageRect.h = 700;
this->texture = this->loadModel(image, imageRect);
SDL_FreeSurface(image);
}
示例4: IMG_Load
Image Graphic::newImage(const char* filename) {
Image image;
SDL_Surface* surface_temp = NULL;
surface_temp = IMG_Load(filename);
image.onInit(SDL_DisplayFormatAlpha(surface_temp));
if (surface_temp)
SDL_FreeSurface(surface);
surface_temp = NULL;
return image;
}
示例5: Crop
// crop one surface to a new one, with tiling when needed
extern SDL_Surface* Crop(SDL_Surface *base, long int ox, long int oy, long int nw, long int nh)
{
SDL_Surface *tform = NULL;
SDL_Surface *ttmp = SDL_CreateRGBSurface(SDL_SWSURFACE,nw,nh,base->format->BitsPerPixel,base->format->Rmask,base->format->Gmask,base->format->Bmask,base->format->Amask);
tform = SDL_DisplayFormatAlpha(ttmp);
SDL_FreeSurface(ttmp);
while ( ox < 0 )
ox += base->w;
while ( oy < 0 )
oy += base->h;
while ( ox >= base->w )
ox -= base->w;
while ( oy >= base->h )
oy -= base->h;
if ( nw <= 0 || nh <= 0 )
return tform;
long int px, py, nx, ny;
uint32_t pux, pnx;
uint8_t R,G,B,A;
px = ox;
py = oy;
nx = 0;
ny = 0;
SDL_LockSurface(base);
SDL_LockSurface(tform);
do
{
pux = getpixel(base,px,py);
SDL_GetRGBA(pux,base->format,&R,&G,&B,&A);
pnx = SDL_MapRGBA(tform->format,R,G,B,A);
putpixel(tform,nx,ny,pnx);
nx++;
px++;
if ( px >= base->w )
px = ox;
if ( nx >= nw )
{
nx = 0;
px = ox;
ny++;
py++;
if ( py >= base->h )
py = oy;
}
}
while ( (nx < nw) && (ny < nh) );
SDL_UnlockSurface(tform);
SDL_UnlockSurface(base);
return tform;
}
示例6: initInterface
// Loads initial interface data
void initInterface()
{
FILE *hud; // config file
Sprite *temp;
SDL_Surface *menu;
// Open the config file, load defaults if it fails
hud = fopen("config/hud.txt","r");
if(hud == NULL)
{
fprintf(stderr,"HUD.txt failed to open, using defaults\n");
loadDefHUD();
}
else
{
loadHUD(hud);
}
// Load menu sprite
temp = LoadSprite("hud/menu.png",640,480);
menu = IMG_Load("hud/menu.png");
SDL_SetColorKey(menu, 0, 0);
temp->image = SDL_DisplayFormatAlpha(menu);
SDL_FreeSurface(menu);
// set HUD transparency slider info
aSlider.x = ORIGIN_X + 65;
aSlider.y = ORIGIN_Y - 180;
aSlider.w = 50;
aSlider.h = 24;
aSlide = false;
// set scroll speed slider info
sSlider.x = ORIGIN_X + 65;
sSlider.y = ORIGIN_Y - 180;
sSlider.w = 50;
sSlider.h = 24;
HUD.sSlide = false;
// start invisible
alpha = SDL_ALPHA_TRANSPARENT;
// Load button info
initButtons();
HUD.grabPanel = 0;
HUD.menu = 1;
HUD.ttips = true;
}
示例7: SDL_DisplayFormatAlpha
// simple static function that will load a surface for us
SDL_Surface* CSurface::OnLoad(char* File) {
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;
if((Surf_Temp = IMG_Load(File)) == NULL) {
return NULL;
}
// here we're optimizing the image - using "SDL_DisplayFormatAlpha" instead of "SDL_DisplayFormat" because the former allows us to designate a color channel, in our case bright pink, as transparent. This helps a lot when rendering our sprites
Surf_Return = SDL_DisplayFormatAlpha(Surf_Temp);
SDL_FreeSurface(Surf_Temp);
return Surf_Return;
}
示例8: newsurface
/* Create a new surface containing a single tile with transparent
* pixels, as indicated by the mask tile.
*/
static SDL_Surface *extractmaskedtile(SDL_Surface *src,
int ximg, int yimg, int wimg, int himg,
int xmask, int ymask)
{
SDL_Surface *dest;
SDL_Surface *temp;
SDL_Rect rect;
unsigned char *s, *d;
Uint32 transp, black;
int x, y;
rect.x = ximg;
rect.y = yimg;
rect.w = wimg;
rect.h = himg;
dest = newsurface(rect.w, rect.h, TRUE);
SDL_BlitSurface(src, &rect, dest, NULL);
black = SDL_MapRGB(src->format, 0, 0, 0);
transp = SDL_MapRGBA(dest->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
if (SDL_MUSTLOCK(src))
SDL_LockSurface(src);
if (SDL_MUSTLOCK(dest))
SDL_LockSurface(dest);
d = (Uint8*)dest->pixels;
s = (Uint8*)src->pixels + ymask * src->pitch
+ xmask * src->format->BytesPerPixel;
for (y = 0 ; y < dest->h ; ++y) {
for (x = 0 ; x < dest->w ; ++x) {
if (pixelat(src, xmask + x, ymask + y) == black)
((Uint32*)d)[x] = transp;
}
s += src->pitch;
d += dest->pitch;
}
if (SDL_MUSTLOCK(src))
SDL_UnlockSurface(src);
if (SDL_MUSTLOCK(dest))
SDL_UnlockSurface(dest);
temp = dest;
dest = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);
if (!dest)
die("%s", SDL_GetError());
SDL_SetAlpha(dest, SDL_SRCALPHA | SDL_RLEACCEL, 0);
return dest;
}
示例9: TTF_RenderText_Blended
Image Graphic::newImageFromText(const char* text) {
Image image;
SDL_Surface* surface_temp = NULL;
surface_temp = TTF_RenderText_Blended(System::getInstance()->getFont(), text, System::getInstance()->getColor());
image.onInit(SDL_DisplayFormatAlpha(surface_temp));
if (surface_temp)
SDL_FreeSurface(surface);
surface_temp = NULL;
return image;
}
示例10: loadedImage
boost::shared_ptr<SDL_Surface> CGViewer::loadImage(const std::string& filename)
{
boost::shared_ptr<SDL_Surface> loadedImage(
IMG_Load(filename.c_str()),
boost::bind(&SafeFreeSurface, _1));
if (!loadedImage.get())
throw std::runtime_error(IMG_GetError());
//dostosowanie grafiki do wyswietlenia z kanalem przezroczystosci
boost::shared_ptr<SDL_Surface> optimizedImage(
SDL_DisplayFormatAlpha(loadedImage.get()),
boost::bind(&SafeFreeSurface, _1) );
return optimizedImage;
}
示例11: IMG_Load
SDL_Surface* Render::assignImage(const char* file){
if (file == NULL)
return NULL;
SDL_Surface* newImage;
SDL_Surface* tempImage = IMG_Load(file);
if (tempImage == NULL)
return NULL;
newImage = SDL_DisplayFormatAlpha(tempImage);
SDL_FreeSurface(tempImage);
return newImage;
}
示例12: IMG_Load
SDL_Surface *load_image(const char* filename,Uint8 r, Uint8 g, Uint8 b)
{
SDL_Surface* loadedImage=NULL;
SDL_Surface* optimizedImage=NULL;
loadedImage = IMG_Load(filename);
if(loadedImage!=NULL)
{
optimizedImage=SDL_DisplayFormatAlpha(loadedImage);
Uint32 colorkey=SDL_MapRGB(loadedImage->format,r,g,b);
SDL_SetColorKey(optimizedImage,SDL_SRCCOLORKEY,colorkey);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
示例13: IMG_Load
int Img::loadImage(char* sFile)
{
SDL_Surface* loadedImage = NULL;
loadedImage = IMG_Load(sFile);
if(loadedImage != NULL)
{
_pImg = SDL_DisplayFormatAlpha(loadedImage);
SDL_FreeSurface(loadedImage);
}
else
return -1;
return 0;
}
示例14: IMG_Load
void MenuCharacter::loadGraphics() {
background = IMG_Load("images/menus/character.png");
proficiency = IMG_Load("images/menus/character_proficiency.png");
upgrade = IMG_Load("images/menus/upgrade.png");
if(!background || !proficiency || !upgrade) {
fprintf(stderr, "Couldn't load image: %s\n", IMG_GetError());
SDL_Quit();
}
// optimize
SDL_Surface *cleanup = background;
background = SDL_DisplayFormatAlpha(background);
SDL_FreeSurface(cleanup);
cleanup = proficiency;
proficiency = SDL_DisplayFormatAlpha(proficiency);
SDL_FreeSurface(cleanup);
cleanup = upgrade;
upgrade = SDL_DisplayFormatAlpha(upgrade);
SDL_FreeSurface(cleanup);
}
示例15:
struct SDL_Surface *load_image(const char *file_name)
{
SDL_Surface *surface;
if ((surface = IMG_Load(file_name)) == NULL)
return NULL;
SDL_Surface *optimized_surface;
if ((optimized_surface = SDL_DisplayFormatAlpha(surface)) == NULL) {
SDL_FreeSurface(surface);
return NULL;
}
SDL_FreeSurface(surface);
return optimized_surface;
}