Problem bei SDL color key



  • Hallo!

    Ich versuche grad den Hintergrund von geladenen Bitmaps
    mit color key zu entfernen, aber es funktioniert nicht 😮

    Hier der Code:

    #include <string>
    #include <iostream>
    #include "SDL.h"
    #include <Windows.h>
    #include <conio.h>
    #include "SDL_image.h"
    
    using namespace std;
    
    const int widht=640;
    const int hight=420;
    const int bpp=32;
    
    SDL_Surface *screen=NULL;
    SDL_Surface *background=NULL;
    SDL_Surface *hello=NULL;
    
    SDL_Surface *loadimage(std::string filename);
    void applysurface(int,int,SDL_Surface*,SDL_Surface*);
    
    int main (int argc,char* args[])
    {
    	if (SDL_Init(SDL_INIT_EVERYTHING)==-1)
    	{
    		return 1;
    	}
    
    	screen=SDL_SetVideoMode(widht,hight,bpp,SDL_SWSURFACE);
    
    	if (screen==NULL)
    	{
    		return 1;
    	}
    
    	background=loadimage("Background.bmp");
    	hello=loadimage("Picture.bmp");
    
        applysurface(0,0,background,screen);
    	applysurface(170,120,hello,screen);
    
    	if (SDL_Flip(screen)==-1)
    	{
    		return 1;
    	}
    
    	SDL_FreeSurface(background);
        SDL_FreeSurface(hello);
    
    	SDL_Delay(15000);
    
    	SDL_Quit();
    
    	return 0;
    }
    
    SDL_Surface *loadimage(std::string filename)
    {
    	SDL_Surface *loadedimage=NULL;
    	SDL_Surface *optimizedimage=NULL;
    
    	loadedimage=IMG_Load(filename.c_str());
    
    	if (loadedimage!=NULL)
    	{
    		optimizedimage=SDL_DisplayFormat(loadedimage);
    
    		SDL_FreeSurface(loadedimage);
    
    	if (optimizedimage!=NULL)
    	{
    		Uint32 colorkey = SDL_MapRGB(optimizedimage->format,255,0,198);
    		SDL_SetColorKey (optimizedimage,SDL_RLEACCEL | SDL_SRCCOLORKEY,colorkey);
    	}
    
    	}
    
    	return optimizedimage;
    }
    
    void applysurface(int x,int y,SDL_Surface* source,SDL_Surface* destination)
    {
    	SDL_Rect offset;
    
    	offset.x=x;
    	offset.y=y;
    
    	SDL_BlitSurface(source,NULL,destination,&offset);
    }
    

    Hoffentlich kann mir jemand helfen! 😞
    Danke



  • Die Frage stellst du besser in einem Forum, das sich mit SDL beschäftigt. Eine C++-Frage ist das jedenfalls nicht.[c]





  • Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x) in das Forum Spiele-/Grafikprogrammierung verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.


Anmelden zum Antworten