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 :

Creer une surface transparente en SDL


Sujet :

SDL

  1. #1
    Membre régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut Creer une surface transparente en SDL
    Salut,

    J'ai un petit soucis que je n'arrive pas a resoudre.

    Je souhaite creer une surface transparente afin ensuite, d'y blitter plusieurs textes dans plusieurs endroits.
    Le soucis que je rencontre est qu'il me reste un liseré autour de chaque lettre de mes polices blittées, et ce, de la couleur du fond original de la surface (ici 0,0,0 donc noir)
    Ce qui me donne un texte moche.

    Je ne sais pas comment m'en sortir !

    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
        VariablesSDL->SurfDecoJoueur = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, 800, 300, 32, 0, 0, 0, 0);
        SDL_SetColorKey(VariablesSDL->SurfDecoJoueur, SDL_SRCCOLORKEY, SDL_MapRGB(VariablesSDL->SurfDecoJoueur->format, 0, 0, 0));
        VariablesSDL->CouleurRouge.r = 229;
        VariablesSDL->CouleurRouge.g = 0;
        VariablesSDL->CouleurRouge.b = 0;
     
        VariablesSDL->PolicePerteConnexion = TTF_OpenFont("polices/Fontastique.ttf", 40);
     
        TTF_SetFontStyle(VariablesSDL->PolicePerteConnexion, TTF_STYLE_BOLD | TTF_STYLE_UNDERLINE);
        strcpy(ChainePerteConnexion1,"Attention !");
        VariablesSDL->TextePerteConnexion1 = TTF_RenderText_Blended(VariablesSDL->PolicePerteConnexion, ChainePerteConnexion1, VariablesSDL->CouleurRouge);
        VariablesSDL->PositionPerteConnexion1.x = (VariablesSDL->SurfDecoJoueur)->w / 2 - VariablesSDL->TextePerteConnexion1->w / 2;
        VariablesSDL->PositionPerteConnexion1.y = 0;
     
        TTF_SetFontStyle(VariablesSDL->PolicePerteConnexion, TTF_STYLE_NORMAL);
        strcpy(ChainePerteConnexion2,"La connexion avec l'autre joueur a été perdue !");
        VariablesSDL->TextePerteConnexion2 = TTF_RenderText_Blended(VariablesSDL->PolicePerteConnexion, ChainePerteConnexion2, VariablesSDL->CouleurRouge);
        VariablesSDL->PositionPerteConnexion2.x = (VariablesSDL->SurfDecoJoueur)->w / 2 - VariablesSDL->TextePerteConnexion2->w / 2;
        VariablesSDL->PositionPerteConnexion2.y = 50;
        strcpy(ChainePerteConnexion3,"Les scores vont bientôt s'afficher...");
        VariablesSDL->TextePerteConnexion3 = TTF_RenderText_Blended(VariablesSDL->PolicePerteConnexion, ChainePerteConnexion3, VariablesSDL->CouleurBlanche);
        VariablesSDL->PositionPerteConnexion3.x = (VariablesSDL->SurfDecoJoueur)->w / 2 - VariablesSDL->TextePerteConnexion3->w / 2;
        VariablesSDL->PositionPerteConnexion3.y = 150;
     
        SDL_BlitSurface(VariablesSDL->TextePerteConnexion1, NULL, VariablesSDL->SurfDecoJoueur, &VariablesSDL->PositionPerteConnexion1);
        SDL_BlitSurface(VariablesSDL->TextePerteConnexion2, NULL, VariablesSDL->SurfDecoJoueur, &VariablesSDL->PositionPerteConnexion2);
        SDL_BlitSurface(VariablesSDL->TextePerteConnexion3, NULL, VariablesSDL->SurfDecoJoueur, &VariablesSDL->PositionPerteConnexion3);
    Merci!!!

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


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    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 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    (Notez qu'il y a un forum SDL, dans la section 2D / 3D / Jeux Videos )

    La technique est de dire à SDL que le noir est une couleur de transparence.
    SDL_SetColorKey(VariablesSDL->SurfDecoJoueur, SDL_SRCCOLORKEY, SDL_MapRGB(VariablesSDL->SurfDecoJoueur->format, 0, 0, 0));
    Comme ça, mais pour chaque surface ou on en a besoin.
    Après, l'histoire est que ... si un pixel n'est pas parfaitement de cette couleur, il ne va pas être transparent. Je pense que c'est votre cas.
    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 régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut
    Oui ca doit surement etre ca!

    Ce que je ne comprend pas c'est que :
    - Je cree ma surface (pleine de noir)
    - J'enleve le noir (du moins je le rend transparent)
    - Ensuite je blitte mon texte en Blended, il devrait donc le blitter sur du transparent, sauf que si j'ai un liseré noir, cela veut dire quil le blitte sur du noir !

    C'est quand meme etonnant qu'il n'y ait pas de solution non?

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


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    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 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Citation Envoyé par theclem35 Voir le message
    Oui ca doit surement etre ca!

    Ce que je ne comprend pas c'est que :
    - Je cree ma surface (pleine de noir)
    - J'enleve le noir (du moins je le rend transparent)
    - Ensuite je blitte mon texte en Blended, il devrait donc le blitter sur du transparent, sauf que si j'ai un liseré noir, cela veut dire quil le blitte sur du noir !

    C'est quand meme etonnant qu'il n'y ait pas de solution non?
    Le truc, c'est que ce n'est pas la surface destination qui doit être mise en transparente, mais les surfaces blitter.
    Dans le sens que, lors du blit, SDL, si la couleur est totalement transparente (comme avec le COLOR_KEY), il va juste ne rien faire.
    Mais cela dépend que de la surface source, et non de celle de destination :p
    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.

  5. #5
    Membre régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut
    Euh j'ai pas tout compris !

    Dans l'ordre ca donne quoi ?

    Je cree ma surface carrée en noir,
    Je fais un SDL colorkey
    Je cree mon texte
    Je refais un SDL colorkey
    Je blitte le texte sur la surface ?

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


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    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 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Ou plus simple.

    Création de la fenetre destination
    Création du texte
    Application de la couleur de transparence sur la surface du texte
    Blit
    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.

  7. #7
    Membre régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut
    Salut,

    J'ai essayé de suivre ce que tu m'as dit et j'ai toujours le liseré noir

    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
    /* Message de déconnexion d'un joueur */
        VariablesSDL->SurfDecoJoueur = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, 800, 300, 32, 0, 0, 0, 0);
     
        VariablesSDL->CouleurRouge.r = 229;
        VariablesSDL->CouleurRouge.g = 0;
        VariablesSDL->CouleurRouge.b = 0;
     
        VariablesSDL->PolicePerteConnexion = TTF_OpenFont("polices/Fontastique.ttf", 40);
     
        TTF_SetFontStyle(VariablesSDL->PolicePerteConnexion, TTF_STYLE_BOLD | TTF_STYLE_UNDERLINE);
        strcpy(ChainePerteConnexion1,"Attention !");
        VariablesSDL->TextePerteConnexion1 = TTF_RenderText_Blended(VariablesSDL->PolicePerteConnexion, ChainePerteConnexion1, VariablesSDL->CouleurRouge);
        VariablesSDL->PositionPerteConnexion1.x = (VariablesSDL->SurfDecoJoueur)->w / 2 - VariablesSDL->TextePerteConnexion1->w / 2;
        VariablesSDL->PositionPerteConnexion1.y = 0;
     
    SDL_SetColorKey(VariablesSDL->TextePerteConnexion1, SDL_SRCCOLORKEY, SDL_MapRGB(VariablesSDL->TextePerteConnexion1->format, 0, 0, 0));
     
        TTF_SetFontStyle(VariablesSDL->PolicePerteConnexion, TTF_STYLE_NORMAL);
        strcpy(ChainePerteConnexion2,"La connexion avec l'autre joueur a été perdue !");
        VariablesSDL->TextePerteConnexion2 = TTF_RenderText_Blended(VariablesSDL->PolicePerteConnexion, ChainePerteConnexion2, VariablesSDL->CouleurRouge);
        VariablesSDL->PositionPerteConnexion2.x = (VariablesSDL->SurfDecoJoueur)->w / 2 - VariablesSDL->TextePerteConnexion2->w / 2;
        VariablesSDL->PositionPerteConnexion2.y = 50;
     
    SDL_SetColorKey(VariablesSDL->TextePerteConnexion2, SDL_SRCCOLORKEY, SDL_MapRGB(VariablesSDL->TextePerteConnexion2->format, 0, 0, 0));
     
        strcpy(ChainePerteConnexion3,"Les scores vont bientôt s'afficher...");
        VariablesSDL->TextePerteConnexion3 = TTF_RenderText_Blended(VariablesSDL->PolicePerteConnexion, ChainePerteConnexion3, VariablesSDL->CouleurBlanche);
        VariablesSDL->PositionPerteConnexion3.x = (VariablesSDL->SurfDecoJoueur)->w / 2 - VariablesSDL->TextePerteConnexion3->w / 2;
        VariablesSDL->PositionPerteConnexion3.y = 150;
     
    SDL_SetColorKey(VariablesSDL->TextePerteConnexion3, SDL_SRCCOLORKEY, SDL_MapRGB(VariablesSDL->TextePerteConnexion3->format, 0, 0, 0));
     
        SDL_BlitSurface(VariablesSDL->TextePerteConnexion1, NULL, VariablesSDL->SurfDecoJoueur, &VariablesSDL->PositionPerteConnexion1);
        SDL_BlitSurface(VariablesSDL->TextePerteConnexion2, NULL, VariablesSDL->SurfDecoJoueur, &VariablesSDL->PositionPerteConnexion2);
        SDL_BlitSurface(VariablesSDL->TextePerteConnexion3, NULL, VariablesSDL->SurfDecoJoueur, &VariablesSDL->PositionPerteConnexion3);
     
    SDL_SetColorKey(VariablesSDL->SurfDecoJoueur, SDL_SRCCOLORKEY, SDL_MapRGB(VariablesSDL->SurfDecoJoueur->format, 0, 0, 0));
     
        VariablesSDL->PositionDecoJoueur.x = 0;
        VariablesSDL->PositionDecoJoueur.y = 150;
    /* Fin */

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


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    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 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Je rappelle que j'avais émis une autre hypothèse:
    Après, l'histoire est que ... si un pixel n'est pas parfaitement de cette couleur, il ne va pas être transparent. Je pense que c'est votre cas.
    EDIT:

    Et après vérification, c'est bien votre problème.
    Pour le résoudre, il faut utiliser TTF_RenderText_Solid à la place de TTF_RenderText_Blended.
    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.

  9. #9
    Membre régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut
    Bonjour,

    Effectivement c'est le cas, mais du coup avec Solid c'est super moche, surtout pour un texte écrire un texte en 40pt :/

    Au final il n'y a pas d'autre solution pour faire appaitre une multitude de texte, juste en appellant une seule surface au lieu de toutes les blitter à chaque fois ?

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


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    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 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    En fait, si vous voulez avoir du Blended, il faudrai faire le blit directement sur la surface finale.

    Sinon, si vous tenez tant à votre surface intermédiaire ... il faut peut être essayé de blitter en Blended mais sur une surface de destination complètement transparante ... enfin ... c'est une idée, je n'en suis pas sur.
    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.

  11. #11
    Membre régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut
    Ce n'est pas ce que j'ai fait au debut en creeant une surface completement noire et en applicant la transparence avec setKeyColor ??

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


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    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 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Citation Envoyé par theclem35 Voir le message
    Ce n'est pas ce que j'ai fait au debut en creeant une surface completement noire et en applicant la transparence avec setKeyColor ??
    Euh non ...
    Car le setKeyColor n'est utilisé que lorsque la surface est source.
    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.

  13. #13
    Membre régulier Avatar de theclem35
    Homme Profil pro
    Technicien Réseaux & Télécommunications
    Inscrit en
    Décembre 2007
    Messages
    148
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien Réseaux & Télécommunications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 148
    Points : 86
    Points
    86
    Par défaut
    J'ai aussi essayer de creer ma surface, puis de la rendre transparente comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SDL_FillRect(VariablesSDL->SurfDecoJoueur, NULL, SDL_MapRGBA(VariablesSDL->SurfDecoJoueur->format, 0, 0, 0, 0)); 
    SDL_SetAlpha(VariablesSDL->SurfDecoJoueur, SDL_SRCALPHA, 0);
    Mais lorsque j'essaye de blitter n'importe quoi dessus après, tout est rendu transparent (je suppose) car on ne voit rien dans l'application principale.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [FAQ][SDL] Comment récupérer les pixels d'une surface ?
    Par Fiquet dans le forum Contribuez
    Réponses: 2
    Dernier message: 19/09/2010, 11h24
  2. [SDL] Effacer une surface (image)
    Par 0nn2belle dans le forum C++
    Réponses: 1
    Dernier message: 10/02/2010, 11h40
  3. Rendre une surface un peu transparente
    Par christophe_halgand dans le forum MATLAB
    Réponses: 2
    Dernier message: 23/09/2009, 13h57
  4. Réponses: 5
    Dernier message: 17/04/2008, 18h44
  5. Changement de la taille d'une surface SDL
    Par Kerwando dans le forum SDL
    Réponses: 4
    Dernier message: 06/06/2006, 21h34

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