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 :

Alpha sur une fraction d'image


Sujet :

SDL

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2008
    Messages
    308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Février 2008
    Messages : 308
    Points : 622
    Points
    622
    Par défaut Alpha sur une fraction d'image
    Salut a tous!

    Simple question, y'a t'il un moyen d'appliquer de la transparence alpha seulement sur une fraction d'image, sans créer une nouvelle surface?

    j'ai une surface en mémoire contenant plusieurs sprites :

    comment faire pour que seul l'image 4 soit transparente par exemple.

  2. #2
    Membre émérite Avatar de SofEvans
    Homme Profil pro
    Développeur C
    Inscrit en
    Mars 2009
    Messages
    1 076
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur C

    Informations forums :
    Inscription : Mars 2009
    Messages : 1 076
    Points : 2 328
    Points
    2 328
    Par défaut
    Et bien a premiere vu, je dirai non.
    La fonction pour activer la transparence alpha est celle ci :

    Tiré de la doc :
    SDL_SetAlpha
    Name
    SDL_SetAlpha -- Adjust the alpha properties of a surface
    Synopsis

    #include "SDL.h"

    int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);

    Description

    Note: This function and the semantics of SDL alpha blending have changed since version 1.1.4. Up until version 1.1.5, an alpha value of 0 was considered opaque and a value of 255 was considered transparent. This has now been inverted: 0 (SDL_ALPHA_TRANSPARENT) is now considered transparent and 255 (SDL_ALPHA_OPAQUE) is now considered opaque.

    SDL_SetAlpha is used for setting the per-surface alpha value and/or enabling and disabling alpha blending.

    Thesurface parameter specifies which surface whose alpha attributes you wish to adjust. flags is used to specify whether alpha blending should be used (SDL_SRCALPHA) and whether the surface should use RLE acceleration for blitting (SDL_RLEACCEL). flags can be an OR'd combination of these two options, one of these options or 0. If SDL_SRCALPHA is not passed as a flag then all alpha information is ignored when blitting the surface. The alpha parameter is the per-surface alpha value; a surface need not have an alpha channel to use per-surface alpha and blitting can still be accelerated with SDL_RLEACCEL.

    Note: The per-surface alpha value of 128 is considered a special case and is optimised, so it's much faster than other per-surface values.

    Alpha effects surface blitting in the following ways:

    RGBA->RGB with SDL_SRCALPHA

    The source is alpha-blended with the destination, using the alpha channel. SDL_SRCCOLORKEY and the per-surface alpha are ignored.
    RGBA->RGB without SDL_SRCALPHA

    The RGB data is copied from the source. The source alpha channel and the per-surface alpha value are ignored.
    RGB->RGBA with SDL_SRCALPHA

    The source is alpha-blended with the destination using the per-surface alpha value. If SDL_SRCCOLORKEY is set, only the pixels not matching the colorkey value are copied. The alpha channel of the copied pixels is set to opaque.
    RGB->RGBA without SDL_SRCALPHA

    The RGB data is copied from the source and the alpha value of the copied pixels is set to opaque. If SDL_SRCCOLORKEY is set, only the pixels not matching the colorkey value are copied.
    RGBA->RGBA with SDL_SRCALPHA

    The source is alpha-blended with the destination using the source alpha channel. The alpha channel in the destination surface is left untouched. SDL_SRCCOLORKEY is ignored.
    RGBA->RGBA without SDL_SRCALPHA

    The RGBA data is copied to the destination surface. If SDL_SRCCOLORKEY is set, only the pixels not matching the colorkey value are copied.
    RGB->RGB with SDL_SRCALPHA

    The source is alpha-blended with the destination using the per-surface alpha value. If SDL_SRCCOLORKEY is set, only the pixels not matching the colorkey value are copied.
    RGB->RGB without SDL_SRCALPHA

    The RGB data is copied from the source. If SDL_SRCCOLORKEY is set, only the pixels not matching the colorkey value are copied.

    Note: Note that RGBA->RGBA blits (with SDL_SRCALPHA set) keep the alpha of the destination surface. This means that you cannot compose two arbitrary RGBA surfaces this way and get the result you would expect from "overlaying" them; the destination alpha will work as a mask.

    Also note that per-pixel and per-surface alpha cannot be combined; the per-pixel alpha is always used if available

    Return Value

    This function returns 0, or -1 if there was an error.
    Comme on peut le voir, il n'y a aucune notion de "portion" de surface. C'est toute la surface qui est mise a niveau.

    Cependant, une class/structure pourrait tout a fait regler ca.

    Si il y a une autre fonction pour activer la transparence alpha ou la modifier, il faudrait s'orienter dans cette direction.

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2008
    Messages
    308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Février 2008
    Messages : 308
    Points : 622
    Points
    622
    Par défaut
    je ne vois pas comment une classe pourrait gérer ça sans créer une nouvelle surface pour chaque sprite, ou refaire un SetAlpha a chaque blit ( ce qui est a évité, il me semble que le SetAlpha doit être fait avant de DisplayFormat)

  4. #4
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Points : 12 462
    Points
    12 462
    Par défaut
    Une autre solution est de découper ton image
    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

  5. #5
    Membre émérite Avatar de SofEvans
    Homme Profil pro
    Développeur C
    Inscrit en
    Mars 2009
    Messages
    1 076
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur C

    Informations forums :
    Inscription : Mars 2009
    Messages : 1 076
    Points : 2 328
    Points
    2 328
    Par défaut
    Et bien, il est evident que tu ne pourra pas user une SDL_Surface avec une portion en transparence alpha. (du moins, d'apres mes connaissance).
    Sinon, il faut s'orienter vers classe/structure.

    MP pour plus de precision, car je ne veux pas mettre un gros paté si cela ne correspond pas a tes attente.

  6. #6
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2008
    Messages
    308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Février 2008
    Messages : 308
    Points : 622
    Points
    622
    Par défaut
    mouai, jvai voir comment je peut modifier mon image_manager pour gérer ça.
    je vais surement être obliger de créer une surface par sprite.

Discussions similaires

  1. Effet d'alpha sur une HWND , sauf une couleurs
    Par crealinks dans le forum Visual C++
    Réponses: 1
    Dernier message: 02/05/2007, 16h46
  2. Écrire un copyright sur une liste d'image
    Par starr dans le forum Langage
    Réponses: 2
    Dernier message: 23/01/2007, 10h02
  3. fondu sur une séquence d'image
    Par seb2406 dans le forum Flash
    Réponses: 12
    Dernier message: 17/07/2006, 00h23
  4. [JAVA3D] Comment active-t-on l'alpha sur une texture?
    Par SuperCed dans le forum OpenGL
    Réponses: 3
    Dernier message: 08/06/2005, 10h50

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