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

DirectX Discussion :

Effet Fade In / Fade Out sur une surface DirectDraw


Sujet :

DirectX

  1. #1
    Membre régulier
    Profil pro
    Ingénieur R&D
    Inscrit en
    Juillet 2002
    Messages
    81
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2002
    Messages : 81
    Points : 74
    Points
    74
    Par défaut Effet Fade In / Fade Out sur une surface DirectDraw
    Au début de mon programme, j'affiche 3 images consecutives (images plein écran). Seulement, passer brutalement de l'une à l'autre, ce n'est pas très joli. Il faut que je fasse un effet Fade In / Fade Out. Donc, j'aurais surtout besoin de savoir comment on fait si l'on veut rendre une image plus sombre (ou plus claire) lors du Blit vers le backbuffer.

  2. #2
    Membre régulier
    Inscrit en
    Mars 2002
    Messages
    97
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 97
    Points : 71
    Points
    71
    Par défaut
    voici ce que j'ai trouvé sur google, va voir sur www.gamedev.net, tu trouveras surement ton bonheur

    Citation Envoyé par www.gamedev.net
    So why would you want to use the Gamma Control function which is included in Direct Draw to do a fade? Well there are two main reasons the first of which is Simplicity, and the second is the fact that by using a Gamma fade you don't lose any information which is stored on your primary surface.

    Now that that's out of the way there are a few things we must take into consideration before implementing this technique. First your primary surface has to be at least 16 bit or greater. Second this fade can only be preformed on your primary surface due to the fact that what your doing here is manipulating your video cards gamma settings.

    Let's get down to business. Included in the Direct Draw library is a structure called DDGAMMARAMP. This structure consists of 3 arrays of 256 WORDs. It the three arrays are called Red, Green, and Blue. It looks like the following:

    typedef struct DDGAMMARAMP {

    WORD red[256];
    WORD green[256];
    WORD blue[256];
    } DDGAMMARAMP, FAR * LPDDGAMMARAMP;

    This structure will hold all the current values of our video cards current gamma settings. So lets declare a few variables that we can use in our program shall we?

    //initialize the gamma control so that we can use it.
    LPDIRECTDRAWGAMMACONTROL lpDDGammaControl = NULL;

    //this structure will be the ramp value that we modify
    DDGAMMARAMP DDGammaRamp;

    //this structure will hold the old gamma values so that we can reset our video card after our fade is complete.
    DDGAMMARAMP DDGammaOld;

    Now that that's all done we need to find out of your video card supports gamma control (although direct X will simulate the fade even if your video card doesn't support gamma control.) So let's query the primary surface:

    lpddsprimary->QueryInterface(IID_IDirectDrawGammaControl,(void **)&lpDDGammaControl);

    Next we need to find out what the current gamma settings are on your video card right now and store it in our DDGAMMAOLD structure:

    lpDDGammaControl->GetGammaRamp(0, &DDGammaOld);

    Let's perform that task one more time and save the values to our DDGAMMARAMP structure so that we can modify the values:

    lpDDGammaControl->GetGammaRamp(0, &DDGammaRamp);

    Now unless a user changes the values of the gamma on their computer the values should go up as you reach the 256th value in your DDGammaRamp structure. Now because each value of Red, Blue and Green can be anywhere from 0 to 65535 we wouldn't want to decrement our values by 1. Instead I decided to make the code as fast as possible so I set all 256 values to 0 and update the screen after each. Here is how the code looks:

    for(int blackloop=0;blackloop<256;blackloop++)
    {

    //we wouldn't want to decrement a value unless it's greater than 0
    if(DDGammaRamp.red[blackloop] > 0)
    {
    //set the current value of DDGammaRamp.Red to 0.
    DDGammaRamp.red[blackloop]=0;
    //now let's update our primary
    lpDDGammaControl->SetGammaRamp(0, &DDGammaRamp);
    surface with the new gamma setting

    } //end if

    //the routine was a little too fast so this slows it down a bit….
    Sleep(1);

    //we wouldn't want to decrement a value unless it's greater than 0
    if(DDGammaRamp.green[blackloop] > 0)
    {
    //set the current value of DDGammaRamp.yellow to 0.
    DDGammaRamp.green[blackloop]=0;
    lpDDGammaControl->SetGammaRamp(DDSGR_CALIBRATE, &DDGammaRamp);
    } //end if

    //the routine was a little too fast so this slows it down a bit….
    Sleep(1);

    //we wouldn't want to decrement a value unless it's greater than 0
    if(DDGammaRamp.blue[blackloop] > 0)
    {
    //set the current value of DDGammaRamp.Blue to 0.
    DDGammaRamp. blue [blackloop]=0;
    lpDDGammaControl->SetGammaRamp(DDSGR_CALIBRATE, &DDGammaRamp);

    } //end if

    //the routine was a little too fast so this slows it down a bit….
    Sleep(1);

    } //end for

    Now that the fade is complete, we need to restore all the old gamma values or our screen will stay black as the rest of your game continues.

    lpDDGammaControl->SetGammaRamp(0, &DDGammaOld);

    Well that wraps it up. There are a few other things you can do with the code. You can modify the code to Flash the screen Red when your player gets hit by something, Green when your swimming in toxic waste, blue if your drowning. And you can even modify the code to fade in, but I'm leaving that to everyone else to figure out.

  3. #3
    Membre régulier
    Profil pro
    Ingénieur R&D
    Inscrit en
    Juillet 2002
    Messages
    81
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur R&D
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2002
    Messages : 81
    Points : 74
    Points
    74
    Par défaut
    En fait, j'ai trouvé cet article (en réponse à un message sur un autre forum). Mais j'ai beaucoup modifié le code donné pour que ça fonctionne. Maintenant, j'ai 4 fonctions:

    FadeIn();
    FadeOut();
    InstantFadeIn();
    InstantFadeOut();

    Leur utilisation est évidente... Ce que je pourrais rajouter aux fonctions FadeIn et FadeOut, c'est de combien incrémenter / décrémenter la gamma à chaque appel (normalement, la fonction devrait être appellée 60 fois par seconde).0 chaque image, le gamme diminue / augmente -> Bingo ! Mon Fade In / Fade Out ! Je vais dailleurs donner le code... Il y a cependant un dernier détail. Le Gamma est spécifique à la carte graphique, et sur certaines, DX doit l'émuler. Est-ce que dans ce cas la baisse de prefromance est significative ?

  4. #4
    Membre du Club Avatar de Freakazoid
    Profil pro
    Inscrit en
    Mars 2002
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2002
    Messages : 116
    Points : 65
    Points
    65
    Par défaut
    Je crois qu'avec le SDK de DirectX tu peux choisir d'émuler certaines choses pour voir les performances. Tu doit surement pourvoir le faire avec la gestion du gama.

Discussions similaires

  1. Fade in / out sur une page chargée dans un Div ..
    Par Kelplant dans le forum Général JavaScript
    Réponses: 0
    Dernier message: 24/07/2010, 20h21
  2. Background Fade-In / Fade-Out sur une div
    Par isa28 dans le forum Général JavaScript
    Réponses: 0
    Dernier message: 24/10/2008, 21h51
  3. SDL_SetClipRect sur une surface "source"
    Par valefor dans le forum SDL
    Réponses: 1
    Dernier message: 12/08/2007, 13h40
  4. Réponses: 2
    Dernier message: 30/03/2007, 13h17
  5. [VMR9][D3D9]ecrire un texte sur une surface
    Par drizztfr dans le forum DirectX
    Réponses: 2
    Dernier message: 13/11/2003, 15h06

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