IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SDL Discussion :

Transparence fichier png


Sujet :

SDL

  1. #1
    Membre éclairé Avatar de guitz
    Homme Profil pro
    Webdesigner
    Inscrit en
    Juillet 2006
    Messages
    717
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juillet 2006
    Messages : 717
    Points : 741
    Points
    741
    Par défaut Transparence fichier png
    Bonjour,

    Je blit un fichier .png et je ne sais pas comment obtenir la transparence ( à la place j'ai un fond blanc)

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    ...
     
    bool init()
    {
    	//Initialization flag
    	bool success = true;
     
    	//Initialize SDL
    	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    	{
    		printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
    		success = false;
    	}
    	else
    	{
    		//Create window
    		gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    		if( gWindow == NULL )
    		{
    			printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
    			success = false;
    		}
    		else
    		{
    			//Initialize PNG loading
    			int imgFlags = IMG_INIT_PNG;
    			if( !( IMG_Init( imgFlags ) & imgFlags ) )
    			{
    				printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
    				success = false;
    			}
    			else
    			{
    				//Get window surface
    				gScreenSurface = SDL_GetWindowSurface( gWindow );
    			}
    		}
    	}
     
    	return success;
    }
     
     
    bool loadMedia()
    {
    	//Loading success flag
    	bool success = true;
     
    	//Load PNG surface
    	gPNGSurface = loadSurface( "images/ball1.png" );
    	if( gPNGSurface == NULL )
    	{
    		printf( "Failed to load PNG image!\n" );
    		success = false;
    	}
     
    	return success;
    }
     
    void close()
    {
    	//Free loaded image
    	SDL_FreeSurface( gPNGSurface );
    	gPNGSurface = NULL;
     
    	//Destroy window
    	SDL_DestroyWindow( gWindow );
    	gWindow = NULL;
     
    	//Quit SDL subsystems
    	IMG_Quit();
    	SDL_Quit();
    }
     
    SDL_Surface* loadSurface( std::string path )
    {
    	//The final optimized image
    	SDL_Surface* optimizedSurface = NULL;
     
    	//Load image at specified path
    	SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
    	if( loadedSurface == NULL )
    	{
    		printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
    	}
    	else
    	{
    		//Convert surface to screen format
    		optimizedSurface = SDL_ConvertSurface( loadedSurface, gScreenSurface->format, NULL );
    		if( optimizedSurface == NULL )
    		{
    			printf( "Unable to optimize image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
    		}
     
    		//Get rid of old loaded surface
    		SDL_FreeSurface( loadedSurface );
    	}
     
    	return optimizedSurface;
    }
     
    int main( int argc, char* args[] )
    {
    	//Start up SDL and create window
    	if( !init() )
    	{
    		printf( "Failed to initialize!\n" );
    	}
    	else
    	{
    		//Load media
    		if( !loadMedia() )
    		{
    			printf( "Failed to load media!\n" );
    		}
    		else
    		{
    			//Main loop flag
    			bool quit = false;
     
    			//Event handler
    			SDL_Event e;
     
    			//While application is running
    			while( !quit )
    			{
    				//Handle events on queue
    				while( SDL_PollEvent( &e ) != 0 )
    				{
    					//User requests quit
    					if( e.type == SDL_QUIT )
    					{
    						quit = true;
    					}
    				}
     
    				//Apply the PNG image
    				SDL_BlitSurface( gPNGSurface, NULL, gScreenSurface, NULL );
     
    				//Update the surface
    				SDL_UpdateWindowSurface( gWindow );
    			}
    		}
    	}
     
    	//Free resources and close SDL
    	close();
     
    	return 0;
    }
    Merci de me mettre sur la voie

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Le SDL_ConvertSurface a tendance à enlevé la transparence. Pouvez vous tester sans ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  3. #3
    Membre éclairé Avatar de guitz
    Homme Profil pro
    Webdesigner
    Inscrit en
    Juillet 2006
    Messages
    717
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Webdesigner

    Informations forums :
    Inscription : Juillet 2006
    Messages : 717
    Points : 741
    Points
    741
    Par défaut
    Merci LittleWhite.

    mais en fait j'ai pu utiliser du png-8 au lieu de png-24 avec mon code. Bon la qualité est pas extra, mais en phase de dev pour le moment ça convient

    Bonne soirée

Discussions similaires

  1. [Compatibilité] transparence des png avec IE
    Par webrider dans le forum Webdesign & Ergonomie
    Réponses: 3
    Dernier message: 16/08/2006, 09h46
  2. Réponses: 13
    Dernier message: 01/12/2005, 05h34
  3. Comment utiliser les fichiers *.PNG avec Delphi ?
    Par HopeLeaves dans le forum Composants VCL
    Réponses: 2
    Dernier message: 17/09/2005, 20h59
  4. Réponses: 2
    Dernier message: 13/12/2004, 23h32
  5. [SWT] Problème avec la transparence des PNG
    Par sirjuh dans le forum SWT/JFace
    Réponses: 1
    Dernier message: 02/08/2004, 08h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo