/** * 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); }
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); }
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); }
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; }
// 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; }
// 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; }
// 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; }
/* 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; }
void TileSet::loadGraphics(string filename) { if (sprites) SDL_FreeSurface(sprites); sprites = IMG_Load(("images/tilesets/" + filename).c_str()); if(!sprites) { fprintf(stderr, "Couldn't load image: %s\n", IMG_GetError()); SDL_Quit(); } SDL_SetColorKey( sprites, SDL_SRCCOLORKEY, SDL_MapRGB(sprites->format, 255, 0, 255) ); // optimize SDL_Surface *cleanup = sprites; sprites = SDL_DisplayFormatAlpha(sprites); SDL_FreeSurface(cleanup); }
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; }
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; }
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; }
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; }
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; }
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); }
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; }
/** * \brief The function that blits the sprite to dst (lowlevel) * \param SDL_Surface Surface where the sprite will be drawn * \param x X-Coordinate, indicating the position on dst * \param y Y-Coordinate, indicating the position on dst */ void CSprite::_drawBlinkingSprite( SDL_Surface *dst, Uint16 x, Uint16 y ) { SDL_Rect dst_rect, src_rect; dst_rect.x = x; dst_rect.y = y; dst_rect.w = m_xsize; dst_rect.h = m_ysize; src_rect.x = 0; src_rect.y = 0; src_rect.w = dst_rect.w; src_rect.h = dst_rect.h; SDL_Surface *blanksfc = SDL_DisplayFormatAlpha(mpSurface.get()); blitMaskedSprite(blanksfc, mpSurface.get(), 0xFFFFFF); SDL_BlitSurface( blanksfc, &src_rect, dst, &dst_rect ); SDL_FreeSurface(blanksfc); }
SDL_Surface* Sprite::loadImage( const std::string image_path ) { //load image SDL_Surface* image = NULL; image = IMG_Load( image_path.c_str() ); if ( !image ) std::cout << "Fehler: " << image_path << std::endl; else { if ( image->format->Amask == 0 ) { image = SDL_DisplayFormatAlpha( image ); } } return image; }
void API_SDLAGG::Gfx_Initialize() { // Open a screen with the specified properties int width = 320; int height = 240; int bpp = 32; // We stored our image in RGBA32 format. We have to create a mask // for this format to tell SDL about our data layout. Uint32 rmask = 0xff000000; Uint32 gmask = 0x00ff0000; Uint32 bmask = 0x0000ff00; Uint32 amask = 0x000000ff; #if SDL_BYTEORDER == SDL_LIL_ENDIAN // OpenGL RGBA masks rmask = 0x000000FF; gmask = 0x0000FF00; bmask = 0x00FF0000; amask = 0xFF000000; #else rmask = 0xFF000000; gmask = 0x00FF0000; bmask = 0x0000FF00; amask = 0x000000FF; #endif SurfaceContainer* targetCont = new SurfaceContainer; targetCont->sdl = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE); if (targetCont->sdl == NULL) { Log("[Error] Unable to set %ix%i video: %s\n", width,height, SDL_GetError()); exit(1); } _targetScreen = (GfxSurface*)targetCont; SurfaceContainer* gfxCont = new SurfaceContainer; gfxCont->sdl = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE,width, height, bpp, rmask, gmask, bmask, amask)); if (gfxCont->sdl == NULL) return; _gfxSurface = (GfxSurface*)gfxCont; SDL_WM_SetCaption("MGame",NULL); sge_TTF_Init(); font = sge_TTF_OpenFont("arial.ttf",10); sge_Update_OFF(); sge_TTF_AAOff(); //sge_TTF_AA_Alpha(); //void* rBuffer = ((SDL_Surface*)_gfxSurface)->sdl->pixels; //unsigned char* renderBuffer = (unsigned char*)rBuffer; //agg::rendering_buffer rbuf(renderBuffer, width, height, bpp/8); m_graphics.attach((unsigned char*)((SurfaceContainer*)_gfxSurface)->sdl->pixels, width, height, width*(bpp/8));//rbuf.buf() m_graphics.blendMode(Agg2D::BlendAlpha); _gfxImage.attach((unsigned char*)((SurfaceContainer*)_gfxSurface)->sdl->pixels, width, height, width*(bpp/8)); }
void WidgetInput::loadGraphics(string filename) { // load input background image background = IMG_Load((PATH_DATA + filename).c_str()); if(!background) { fprintf(stderr, "Couldn't load image: %s\n", IMG_GetError()); SDL_Quit(); } // optimize SDL_Surface *cleanup = background; background = SDL_DisplayFormatAlpha(background); SDL_FreeSurface(cleanup); }
/* Constructs a new font object. Loads a tiled font file from the given bitmap image file, using the given character width and height (the font is monospaced). The characters-per-line are used when extracting a character from the tiled bitmap file and corresponds to the number of characters per "line of characters" there are in the bitmap file. */ void font_init(Font *f, const char *bmp_filename, int char_width, int char_height, int bitmap_chars_per_line) { SDL_Surface *s; f->bitmap_chars_per_line = bitmap_chars_per_line; f->char_height = char_height; f->char_width = char_width; s = game_load_bmp(bmp_filename); SDL_SetColorKey(s, SDL_SRCCOLORKEY | SDL_RLEACCEL, 1); f->bitmap = SDL_DisplayFormatAlpha(s); assert(f->bitmap != NULL); SDL_FreeSurface(s); }
SDL_Surface *gfx_create_RGB_surface(SDL_Surface *src, uint32_t width, uint32_t height) { SDL_Surface *new_surface, *tmp; tmp = SDL_CreateRGBSurface(src->flags, width, height, src->format->BitsPerPixel, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask); new_surface = SDL_DisplayFormatAlpha(tmp); memset(new_surface->pixels, 0, new_surface->w * new_surface->h * new_surface->format->BytesPerPixel); SDL_FreeSurface(tmp); return (new_surface); }
void WidgetListBox::loadArt() { // load ListBox images listboxs = IMG_Load(fileName.c_str()); if(!listboxs) { fprintf(stderr, "Couldn't load image: %s\n", IMG_GetError()); SDL_Quit(); exit(1); // or abort ?? } // optimize SDL_Surface *cleanup = listboxs; listboxs = SDL_DisplayFormatAlpha(listboxs); SDL_FreeSurface(cleanup); }
SDL_Surface* SDLManager::loadImage(std::string filename) { SDL_Surface* tmpImage = NULL; tmpImage = IMG_Load(filename.c_str()); // Optimizing image to screen, while trying to mantain it's // transparency (alpha) SDL_Surface* image = NULL; if (tmpImage->format->Amask) image = SDL_DisplayFormatAlpha(tmpImage); else image = SDL_DisplayFormat(tmpImage); SDLManager::freeImage(tmpImage); return image; }
ImageView::ImageView(string path):ImageView() { SDL_Surface * tmp; tmp = IMG_Load(path.c_str()); if(tmp == NULL){ throw string("Error in: "+string(__PRETTY_FUNCTION__)+" details:"+SDL_GetError()); } img = SDL_DisplayFormatAlpha(tmp); SDL_FreeSurface( tmp ); if(img == NULL){ throw string("Error in: "+string(__PRETTY_FUNCTION__)+" details:"+SDL_GetError()); } height = img->h; width = img->w; surface=img; }
//============================================================================== 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; } Surf_Return = SDL_DisplayFormatAlpha(Surf_Temp); SDL_FreeSurface(Surf_Temp); Surf_Temp = NULL; return Surf_Return; }
void WidgetButton::loadArt() { // load button images buttons = IMG_Load(fileName.c_str()); if(!buttons) { fprintf(stderr, "Couldn't load image: %s\n", IMG_GetError()); SDL_Quit(); } // optimize SDL_Surface *cleanup = buttons; buttons = SDL_DisplayFormatAlpha(buttons); SDL_FreeSurface(cleanup); }
Bouton * creerBoutonTexte(char * nom, int x, int y, int actif) { Bouton * b; SDL_Rect r; int i; b = nouveauBouton(); r.x = 12; for (i = 0; i < NB_ETAT_BTN; i++) { SDL_Surface * tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, g_boutons[i]->w, g_boutons[i]->h, 32, 0, 0, 0, 0xFF000000); SDL_Surface * sfc; if (!tmp) eprintf("Erreur de création de la surface pour les boutons.\n"); b->s[i] = SDL_DisplayFormatAlpha(tmp); SDL_FreeSurface(tmp); if (!b->s[i]) eprintf("Erreur de création de la surface pour les boutons.\n"); blit32(g_boutons[i], NULL, b->s[i], NULL); sfc = creerTxtSurface(nom); r.y = (b->s[i]->h - sfc->h) / 2; r.h = sfc->h; r.w = sfc->w; if (i != BTN_ETAT_INACTIF) blit32(sfc, NULL, b->s[i], &r); else fillNBlitPerColor32(sfc, NULL, b->s[i], &r, 0xFFFFFF, 0xF0F0F0F0); setAlphaParCouleur32(b->s[i], 0); } b->r.x = x; b->r.y = y; b->r.h = b->s[0]->h; b->r.w = b->s[0]->w; if (!actif) b->etat = BTN_ETAT_INACTIF; else b->etat = BTN_ETAT_NORMAL; b->type = BTN_TYPE_TXT; b->actif = actif; b->majAff = 1; return b; }
/** * Try to load a sprite image file. * * @param fname * Sprite filename * @param flag * Flags * @param rwop * Pointer to memory for the image * @return * The sprite if success, NULL otherwise */ sprite_struct * sprite_tryload_file (char *fname, uint32_t flag, SDL_RWops *rwop) { SDL_Surface *bitmap; if (fname != NULL) { bitmap = IMG_Load_wrapper(fname); if (bitmap == NULL) { return NULL; } } else { bitmap = IMG_LoadPNG_RW(rwop); } sprite_struct *sprite = ecalloc(1, sizeof(*sprite)); if (sprite == NULL) { return NULL; } uint32_t ckflags = SDL_SRCCOLORKEY | SDL_ANYFORMAT | SDL_RLEACCEL; uint32_t ckey = 0; if (bitmap->format->palette) { ckey = bitmap->format->colorkey; SDL_SetColorKey(bitmap, ckflags, ckey); } else if (flag & SURFACE_FLAG_COLKEY_16M) { /* Force a true color png to colorkey. Default ckey is black (0). */ SDL_SetColorKey(bitmap, ckflags, 0); } surface_borders_get(bitmap, &sprite->border_up, &sprite->border_down, &sprite->border_left, &sprite->border_right, ckey); sprite->bitmap = bitmap; if (flag & SURFACE_FLAG_DISPLAYFORMATALPHA) { sprite->bitmap = SDL_DisplayFormatAlpha(bitmap); SDL_FreeSurface(bitmap); } else if (flag & SURFACE_FLAG_DISPLAYFORMAT) { sprite->bitmap = SDL_DisplayFormat(bitmap); SDL_FreeSurface(bitmap); } return sprite; }
static SDL_Surface * create_surface_from_data(void *data, int width, int height, int transparent) { int r; /* Create sprite surface */ SDL_Surface *surf8 = SDL_CreateRGBSurfaceFrom(data, (int)width, (int)height, 8, (int)(width*sizeof(uint8_t)), 0, 0, 0, 0); if (surf8 == NULL) { LOGE("sdl-video", "Unable to create sprite surface: %s.", SDL_GetError()); exit(EXIT_FAILURE); } /* Set sprite palette */ r = SDL_SetPalette(surf8, SDL_LOGPAL | SDL_PHYSPAL, pal_colors, 0, 256); if (r == 0) { LOGE("sdl-video", "Unable to set palette for sprite."); exit(EXIT_FAILURE); } /* Covert to screen format */ SDL_Surface *surf = NULL; if (transparent) { /* Set color key */ r = SDL_SetColorKey(surf8, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0); if (r < 0) { LOGE("sdl-video", "Unable to set color key for sprite."); exit(EXIT_FAILURE); } surf = SDL_DisplayFormatAlpha(surf8); } else { surf = SDL_DisplayFormat(surf8); } if (surf == NULL) { LOGE("sdl-video", "Unable to convert sprite surface: %s.", SDL_GetError()); exit(EXIT_FAILURE); } SDL_FreeSurface(surf8); return surf; }