本文整理汇总了C++中SDL_DisplayFormat函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_DisplayFormat函数的具体用法?C++ SDL_DisplayFormat怎么用?C++ SDL_DisplayFormat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_DisplayFormat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_image
/**
* Lataa kuvat ja keymappaa RGB 0xFF, 0, 0xFF (255,0,255) värikoodin pois (pinkki)
*/
SDL_Surface* load_image(std::string filename, int r, int g, int b) {
SDL_Surface* loaded_image = NULL;
SDL_Surface* optimized_image = NULL;
loaded_image = IMG_Load(filename.c_str());
// tarkistetaan saatiinko ladattua kuva
if (loaded_image != NULL) {
// optimoidaan
optimized_image = SDL_DisplayFormat(loaded_image);
// poistetaan vanha kuva memorysta
SDL_FreeSurface( loaded_image );
if (optimized_image != NULL) {
// color key
Uint32 key = SDL_MapRGB(optimized_image->format, r, g, b);
SDL_SetColorKey(optimized_image, SDL_SRCCOLORKEY, key);
}
}
return optimized_image;
}
示例2: IMG_Load
// Optimize image on load to reduce processing.
SDL_Surface *load_image(const char *file)
{
SDL_Surface *image_format;
SDL_Surface *screen_format;
// Load image
image_format = IMG_Load(file);
/*
DOES THE FILE EVEN EXIST?
*/
if(image_format != 0)
{
// Optimize
screen_format = SDL_DisplayFormat(image_format);
// Release old image
SDL_FreeSurface(image_format);
}
return screen_format;
}
示例3: SDL_LoadBMP
SDL_Surface *load_image(std::string filename){
// Temporary storage for the image that's loaded
SDL_Surface* loadedImage = NULL;
// The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
// Load the image
loadedImage = SDL_LoadBMP( filename.c_str() );
// If nothing went wrong in loading the image
if( loadedImage != NULL )
{
// Create an optimized image
optimizedImage = SDL_DisplayFormat(loadedImage);
// Free the old image
SDL_FreeSurface(loadedImage);
}
// Return the optimized image
return optimizedImage;
}
示例4: IMG_Load
//load the file, convert it to the screen's display format
//apply the colorKey (i.e. make all magenta transparent)
//Then free the temp image and return the final
SDL_Surface* ImageCache::loadIMG(const std::string filename) const
{
SDL_Surface* tempImg = IMG_Load(filename.c_str());
if(!tempImg)
{
throw(SDL_GetError());
}
SDL_Surface* finalImg = SDL_DisplayFormat(tempImg);
if(!finalImg)
{
throw(SDL_GetError());
}
if( SDL_SetColorKey(finalImg, SDL_SRCCOLORKEY, SDL_MapRGB( finalImg->format, 255, 0, 255)) == -1)
{
throw(SDL_GetError());
}
SDL_FreeSurface(tempImg);
return finalImg;
}
示例5: surf_Load
int surf_Load(SDL_Surface **image, char *name, int autoFreeID)
{
char *imageLoc;
SDL_Surface *optimizedImage = NULL;
imageLoc = (char *)mem_Malloc(strlen(surf_C.surfacesDIR) + strlen(name) + 1, __LINE__, __FILE__);
strcpy(imageLoc, surf_C.surfacesDIR);
strcat(imageLoc, name);
*image = IMG_Load(imageLoc);
mem_Free(imageLoc);
if(*image == NULL)
{
printf("\nError - could not load image\n\t%s. (%s)\n", name, SDL_GetError());
file_Log(ker_Log(), 0, "\nError - could not load image\n\t%s. (%s)\n", name, SDL_GetError());
return 1;
}
optimizedImage = SDL_DisplayFormat(*image);
SDL_FreeSurface(*image);
if(optimizedImage == NULL)
return 2;
SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY | SDL_RLEACCEL, *ker_colourKey());
*image = optimizedImage;
if(autoFreeID == A_FREE)
list_Push(&surf_C.surfaceList, *image, autoFreeID);
return 0;
}
示例6: ChargerImages
Sprites* ChargerImages()
{
Sprites* S;
int i;
S = malloc(NbSprites*sizeof(Sprites));
S[0].sprite = IMG_Load("images/sky.png");
S[1].sprite = IMG_Load("images/sol.png");
S[2].sprite = IMG_Load("images/block.png");
S[3].sprite = IMG_Load("images/boite.png");
S[4].sprite = IMG_Load("images/tuyau1.png");
S[5].sprite = IMG_Load("images/tuyau2.png");
S[6].sprite = IMG_Load("images/tuyau3.png");
S[7].sprite = IMG_Load("images/tuyau4.png");
S[8].sprite = IMG_Load("images/fin1.png");
S[9].sprite = IMG_Load("images/fin2.png");
S[10].sprite = IMG_Load("images/pique.png");
for(i=0;i<NbSprites;i++){
S[i].sprite = SDL_DisplayFormat(S[i].sprite);
}
S[0].traverser = 0;
S[1].traverser = 1;
S[2].traverser = 1;
S[3].traverser = 1;
S[4].traverser = 1;
S[5].traverser = 1;
S[6].traverser = 1;
S[7].traverser = 1;
S[8].traverser = 0;
S[9].traverser = 0;
S[10].traverser = 1;
return S;
}
示例7: IMG_Load
static SDL_Surface *loadImage(char *name)
{
/* Load the image using SDL Image */
SDL_Surface *temp;
SDL_Surface *image;
temp = IMG_Load(name);
if (temp == NULL)
{
printf("Failed to load image %s", name);
exit(1);
}
/* Make the background transparent */
SDL_SetColorKey(temp, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB(temp->format, TRANS_R, TRANS_G, TRANS_B));
/* Convert the image to the screen's native format */
image = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
if (image == NULL)
{
printf("Failed to convert image %s to native format", name);
exit(1);
}
/* Return the processed image */
return image;
}
示例8: TTF_RenderUTF8_Solid
bool NXFont::InitChars(TTF_Font *font, uint32_t color)
{
SDL_Color fgcolor;
SDL_Surface *letter;
fgcolor.r = (uint8_t)(color >> 16);
fgcolor.g = (uint8_t)(color >> 8);
fgcolor.b = (uint8_t)(color);
#ifdef _L10N_CP1251
char utf8_str[2];
#endif
char str[2];
str[1] = 0;
for(int i=1;i<NUM_LETTERS_RENDERED;i++)
{
str[0] = i;
#ifndef _L10N_CP1251
letter = TTF_RenderUTF8_Solid(font, str, fgcolor);
#else
win1251_to_utf8(str, utf8_str);
letter = TTF_RenderUTF8_Solid(font, utf8_str, fgcolor);
#endif
if (!letter)
{
staterr("InitChars: failed to render character %d: %s", i, TTF_GetError());
return 1;
}
letters[i] = SDL_DisplayFormat(letter);
SDL_FreeSurface(letter);
}
return 0;
}
示例9: SDL_CreateRGBSurface
SDL_Surface *gfx_new_surface(int width, int height, int alpha)
{
Uint32 rmask, gmask, bmask;
SDL_Surface *tmp = NULL;
SDL_Surface *dispform = NULL;
if (width <= 0 || height <= 0)
return NULL;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
#endif
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE | (alpha ? SDL_SRCALPHA : 0),
width, height, 16, rmask, gmask, bmask, 0);
if (!tmp)
return NULL;
if (alpha)
{
SDL_SetAlpha(tmp, SDL_SRCALPHA, 0);
dispform = SDL_DisplayFormatAlpha(tmp);
}
else
dispform = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
return dispform;
}
示例10: loadOptimizedImage
SDL_Surface* loadOptimizedImage(char* fileName)
{
SDL_Surface* loadedImg = NULL;
SDL_Surface* optimizedImg = NULL;
loadedImg = IMG_Load(fileName);
if(loadedImg!=NULL)
{
//Create an optimized image
optimizedImg = SDL_DisplayFormat( loadedImg );
//Free the old image
SDL_FreeSurface( loadedImg );
if(optimizedImg!=NULL)
{
//Map the color key
Uint32 colorkey = SDL_MapRGB( optimizedImg->format, 0xFF,0xFF,0xFF);
//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
SDL_SetColorKey( optimizedImg, SDL_SRCCOLORKEY, colorkey );
}
}
else
{
printf("\n Loaded Img is null!");
}
return optimizedImg;
}
示例11: ChargeImage
SDL_Surface* ChargeImage(const char *fichier)
{
// Surface tampon qui nous servira pour charger l'image
SDL_Surface* loadedImage = NULL;
// L'image optimisee qu'on va utiliser
SDL_Surface* optimizedImage = NULL;
// Chargement de l'image
loadedImage = SDL_LoadBMP(fichier);
// Si le chargement se passe bien
if(loadedImage != NULL)
{
// Création de l'image optimisée
optimizedImage = SDL_DisplayFormat(loadedImage);
// Libération de l'ancienne image
SDL_FreeSurface(loadedImage);
}
// On retourne l'image optimisée
return optimizedImage;
}
示例12: Dune2Image
/** Constructor, load the cursorimage and set upp all surfaces to buffer
* background in etc.
*/
Cursor::Cursor()
{
SDL_Surface *tmp;
curimg = 0;
nimgs = 1;
cursorimg = new Dune2Image("mouse.shp", -1);
if (getConfig().gamenum == GAME_RA) {
transicn = new TemplateImage("trans.icn", mapscaleq, 1);
nsoff = CUR_RA_NOSCROLL_OFFSET;
} else {
transicn = new TemplateImage("trans.icn", mapscaleq);
nsoff = CUR_NOSCROLL_OFFSET;
}
image[curimg] = cursorimg->getImage(0);
/* All cursors loaded */
tmp = SDL_CreateRGBSurface (SDL_SWSURFACE, image[0]->w, image[0]->h, 16, 0xff, 0xff, 0xff, 0);
bg = SDL_DisplayFormat( tmp );
SDL_FreeSurface( tmp );
currentcursor = CUR_STANDARD;
x = 0;
y = 0;
cursor_offset = 0;
cursorpool = new CursorPool("cursors.ini");
ci = NULL;
transw = transicn->getImage(0);
transy = transicn->getImage(1);
transr = transicn->getImage(2);
}
示例13: IMG_Load
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
//If the image was optimized just fine
if( optimizedImage != NULL )
{
//Map the color key
Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );
//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
}
}
//Return the optimized image
return optimizedImage;
}
示例14: sprintf
CAnimdata::CAnimdata(const char* path)
{
mW = 0; mH = 0;
SDL_Surface* temp;
char buf[255],name[255];
int ppause = 0, r = 0, g = 0, b = 0, count = 0;
char FileName[255];
sprintf(FileName,"%s/info",path);
FILE* fp = fopen(FileName,"r");
if (!fp)
{
printf("Error: Can't open file: %s\n",FileName);
exit(1);
}
fgets(buf,255,fp);
sscanf(buf,"FILES: %d",&mNumFrames);
mBuilt = 1;
while(!feof(fp) && count<mNumFrames)
{
fgets(buf,255,fp);
if(buf[0]!='#' && buf[0]!='\r' && buf[0]!='\n' && buf[0]!='\0' && strlen(buf)!=0)
{
sscanf(buf,"%s %d %d %d %d",name,&ppause,&r,&g,&b);
sprintf(FileName,"%s/%s",path,name);
if((temp = SDL_LoadBMP(FileName)) == NULL) exit(1);
if(r>=0) SDL_SetColorKey(temp,SDL_SRCCOLORKEY,SDL_MapRGB(temp->format,r,g,b));
image.push_back(SDL_DisplayFormat(temp));
SDL_FreeSurface(temp);
pause.push_back(ppause);
if(!mW) mW = image[count]->w;
if(!mH) mH = image[count]->h;
++count;
}
}
fclose(fp);
}
示例15: SDL_LoadBMP
// Helper function to load and optimize graphics.
// Note to Students: This function has a "double pointer" as the first parameter!
// This was explained in the lecture when the game was announced.
bool COutputManagerNITHris::_LoadAndFormatBMP( SDL_Surface** r_ppoBitmapSurface,
const char* szBitmapName ) const
{
bool r_bRetVal = true;
// First we load the bitmap into a temporary storage.
SDL_Surface *poTempSurface = SDL_LoadBMP(szBitmapName);
if(!poTempSurface)
{
cout << "COutputManagerNITHris::Init - File not Found: " << szBitmapName << endl;
r_bRetVal = false;
}
else
{
// Then we convert the temporary stored bitmap to the ideal format and put it in the variable pointed to in the param list.
*r_ppoBitmapSurface = SDL_DisplayFormat(poTempSurface);
// Finally, we free the dynamically created temporary storage again.
SDL_FreeSurface(poTempSurface);
}
return r_bRetVal;
} // END _LoadAndFormatBMP