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 :

degrader vertical en SDL


Sujet :

SDL

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut degrader vertical en SDL
    bonjour je débute en programation
    et je bloque sur point suivant:
    j'arrive bien affaire un dégréder horisontal mai pas vertical
    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
    int main(int argc, char *argv[])
    {
        SDL_Surface *ecran = NULL, *lignes[256] = {NULL};
        SDL_Rect position;
        int i = 0;
     
        SDL_Init(SDL_INIT_VIDEO);
     
        ecran = SDL_SetVideoMode(640, 256, 32, SDL_HWSURFACE);
     
        for (i = 0 ; i <= 255 ; i++)
            lignes[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 640, 1, 32, 0, 0, 0, 0); 
     
        SDL_WM_SetCaption("Mon dégradé en SDL !", NULL);
     
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
     
        for (i = 0 ; i <= 255 ; i++)
        {
            position.x = 0; 
            position.y = i;
            SDL_FillRect(lignes[i], NULL, SDL_MapRGB(ecran->format, i, i, i)); 
            SDL_BlitSurface(lignes[i], NULL, ecran, &position);
        }
     
        SDL_Flip(ecran);
        pause();
     
        for (i = 0 ; i <= 255 ; i++) 
            SDL_FreeSurface(lignes[i]);
        SDL_Quit();
     
        return EXIT_SUCCESS;
    }
    pouvez vous m'aider ?

    merci

  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
    Bonjour,

    Pour faire en sorte que ton degradé soit horizontale et non verticale, il faut que tu inverse tout les X avec les Y et tout les W avec les H

    De plus, ton code peut facilement etre plus lisible.

    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <SDL/SDL.h>
     
     
     
    #define EPAISSEUR_LIGNE 3
     
    #define LARGEUR_ECRAN  640
    #define HAUTEUR_ECRAN  (256*EPAISSEUR_LIGNE)
     
     
    int main(int argc, char *argv[])
    {
        SDL_Surface *ecran = NULL;
        int i;
     
        /** Il faut verifier le retour des deux fonction ci dessous **/
        SDL_Init(SDL_INIT_VIDEO);
        ecran = SDL_SetVideoMode(LARGEUR_ECRAN, HAUTEUR_ECRAN, 32, SDL_HWSURFACE);
     
     
     
     
        for (i=0 ; i<256 ; i++)
        {
            SDL_Rect rectangle;
                rectangle.x = 0;
                rectangle.y = i*EPAISSEUR_LIGNE;
                rectangle.w = LARGEUR_ECRAN;
                rectangle.h = EPAISSEUR_LIGNE;
     
            SDL_FillRect(ecran, &rectangle, SDL_MapRGB(ecran->format, i, i, i));
        }
     
        SDL_Flip(ecran);
        pause();
     
        SDL_Quit();
     
        return EXIT_SUCCESS;
        /** Pour eviter deux warning **/
        argc=argc, argv=argv;
    }
    Tu peux t'amuser a changer le define EPAISSEUR_LIGNE.
    Bon courage pour la suite.

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    merci

    et dans mon code actuel y a t'il un moyen pour faire le degrader en vertical ?

    merci d'avance

    ton code est bien mais je voudrais bien savoire si c'est possible avec le mien et comment ,

  4. #4
    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
    Citation Envoyé par SofEvans Voir le message
    Pour faire en sorte que ton degradé soit horizontale et non verticale, il faut que tu inverse tout les X avec les Y et tout les W avec les H
    Y a t'il besoins d'explication plus precise ?

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    euh ba en faite

    dans ton code je voi bien ou son les x,y,h et w
    mais dans le mien je voi pas ou sont les w et h

  6. #6
    Expert éminent sénior
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 361
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 361
    Points : 20 381
    Points
    20 381
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    for (i=0 ; i<256 ; i++)
        {
            SDL_Rect rectangle;
                rectangle.x = i*EPAISSEUR_LIGNE;
                rectangle.y = 0;
                rectangle.w = EPAISSEUR_LIGNE;
                rectangle.h = HAUTEUR_ECRAN;
     
            SDL_FillRect(ecran, &rectangle, SDL_MapRGB(ecran->format, i, i, i));
        }
    et en plus j'ai pas bac +5 ni fait math sups math spé

  7. #7
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    pour Mat.M :

    dans

    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
    int main(int argc, char *argv[])
    {
        SDL_Surface *ecran = NULL, *lignes[256] = {NULL};
        SDL_Rect position;
        int i = 0;
     
        SDL_Init(SDL_INIT_VIDEO);
     
        ecran = SDL_SetVideoMode(640, 256, 32, SDL_HWSURFACE);
     
        for (i = 0 ; i <= 255 ; i++)
            lignes[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 640, 1, 32, 0, 0, 0, 0); 
     
        SDL_WM_SetCaption("Mon dégradé en SDL !", NULL);
     
        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
     
        for (i = 0 ; i <= 255 ; i++)
        {
            position.x = 0; 
            position.y = i;
            SDL_FillRect(lignes[i], NULL, SDL_MapRGB(ecran->format, i, i, i)); 
            SDL_BlitSurface(lignes[i], NULL, ecran, &position);
        }
     
        SDL_Flip(ecran);
        pause();
     
        for (i = 0 ; i <= 255 ; i++) 
            SDL_FreeSurface(lignes[i]);
        SDL_Quit();
     
        return EXIT_SUCCESS;
    }
    ou me trouve tu sa ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    for (i=0 ; i<256 ; i++)
        {
            SDL_Rect rectangle;
                rectangle.x = i*EPAISSEUR_LIGNE;
                rectangle.y = 0;
                rectangle.w = EPAISSEUR_LIGNE;
                rectangle.h = HAUTEUR_ECRAN;
     
            SDL_FillRect(ecran, &rectangle, SDL_MapRGB(ecran->format, i, i, i));
        }

  8. #8
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    c'est bon je vien de trouver pour Math.M
    voici la reponce que j'atendais:

    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
    int main(int argc, char *argv[])
    {
    SDL_Surface *ecran = NULL, *lignes[256] = {NULL};
    SDL_Rect position;
    int i = 0;
    
    SDL_Init(SDL_INIT_VIDEO);
    
    ecran = SDL_SetVideoMode(256, 640, 32, SDL_HWSURFACE);
    
    for (i = 0 ; i <= 255 ; i++)
    lignes[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 1 ,640, 32, 0, 0, 0, 0); 
    
    SDL_WM_SetCaption("Mon dégradé en SDL !", NULL);
    
    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
    
    for (i = 0 ; i <= 255 ; i++)
    {
    position.x = i; 
    position.y = 0;
    SDL_FillRect(lignes[i], NULL, SDL_MapRGB(ecran->format, i, i, i)); 
    SDL_BlitSurface(lignes[i], NULL, ecran, &position);
    }
    
    SDL_Flip(ecran);
    pause();
    
    for (i = 0 ; i <= 255 ; i++) 
    SDL_FreeSurface(lignes[i]);
    SDL_Quit();
    
    return EXIT_SUCCESS;
    }
    merci a toi SofEvans

  9. #9
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    une autre question pour actuellement je part dunoire (a gauche ) ver le blanc (a droite) comment faire pour l'invercer
    merci d'avance

  10. #10
    Membre éclairé
    Avatar de Pouet_forever
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    671
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 671
    Points : 842
    Points
    842
    Par défaut
    Si tu as bien compris ce que fait le code, tu comprends que c'est cette ligne là qui colorie ta surface : SDL_FillRect(lignes[i], NULL, SDL_MapRGB(ecran->format, i, i, i));
    Comme tu peux le voir, la couleur évolue en fonction de i pour les composantes rouge, verte et bleue. Il te suffit de faire varier ces valeurs.

    Note que tu as des balises de code pour présenter ton code, c'est le bouton # juste au dessus de là où tu écris.
    Plus tu pédales moins fort, moins t'avances plus vite.

  11. #11
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    merci cela je l'est deja vue merci a toi
    mai cela ne change en rien au fait que je du plus foncé a gauche vers le plus claire
    comment faire l'inverse ?
    merci d'avance

  12. #12
    Membre éclairé
    Avatar de Pouet_forever
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    671
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 671
    Points : 842
    Points
    842
    Par défaut
    C'est à toi de voir. Une solution est de raisonner à l'inverse. Tu as 256 couleurs, donc comme i va de 0 à 255 on utilise 255-i au lieux de i.
    Plus tu pédales moins fort, moins t'avances plus vite.

  13. #13
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 15
    Points : 0
    Points
    0
    Par défaut
    encore merci c'est bon j'ai réussi

Discussions similaires

  1. Réponses: 11
    Dernier message: 15/10/2003, 17h26
  2. Concaténation vertical ???
    Par loaded dans le forum Langage SQL
    Réponses: 10
    Dernier message: 07/05/2003, 15h44
  3. scrolling vertical et horizontal
    Par myriam dans le forum MFC
    Réponses: 2
    Dernier message: 24/01/2003, 17h06
  4. [TP]dégradé de couleur
    Par mikoeur dans le forum Turbo Pascal
    Réponses: 10
    Dernier message: 10/11/2002, 23h02
  5. vertex vertices
    Par gRRosminet dans le forum OpenGL
    Réponses: 2
    Dernier message: 05/11/2002, 03h04

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