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

C++ Discussion :

PB de passage d'argument dasn une classe


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 55
    Par défaut PB de passage d'argument dasn une classe
    Bonsoir à tous,

    Mon application affiche une scene openGL toute simple.
    J'aimerais afficher des fenetres (surface 2D texturée)
    dont l'apparition est commandé par certaines touches du
    clavier.
    Chaque fenetre peut contenir un certain nombre de ligne texte.

    Pour ca j'ai créé une class "fenetre" contenant un tableau de
    pointeur sur une class "ligneTexte" (dont l'une des fonctions membres
    crée des textures à partir de surface "SDL TTF").

    En réalité tout cela marchait très bien avant que je decide de progresser
    et d'essayer de mettre tout cela dasn des classes.

    Mes problemes (j'y suis depuis 2 jours, je craque...) :

    1. Je n'arrive pas à affecter l'identifiant de ma texture de fenetre,
    à la variable membre '_texture' de la class "fenetre".
    Résultat ma fenetre s'affiche sans la texture.
    J'ai essayé de comprendre ce qui se passait en affichant dans le fichier
    'stderr' les valeurs des variables.

    Malgrè :

    this->_texture = textureFenetre;

    dans le constructeur "C_fenetre::C_fenetre()

    stderr => textureFenetre 7 this->_texture 196806224

    Si dans la fonction membre _afficheFentre() je remplace this->_texture
    par la valeur qu'elle devrait avoir (7) la texture s'affiche bien.

    Voici les classes :

    2. Idem pour le nom de la fenetre de type 'string'.
    Elle ne prend pas la valeurde l'argument passé au constructeur.
    Et est l'objet d'un plantage de l'application lors de la creation d'une seconde fenetre
    si je cherche à afficher sa valeur dans 'stderr' ??? (pour l'affichage de fenetre1
    "this->_nom" rien n'est affiché dans 'stderr' et pour fenetre2 "this->_nom" => plantage).

    Je n'y comprends rien.
    Merci d'avance pour els eclaircisements.

    [EDIT] cf code ci dessous.

  2. #2
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 55
    Par défaut
    PS : Si besoin de plus de code ou d'explication n'hesitez pas.

  3. #3
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Par défaut
    J'ai l'impression que ton code ne compile pas. L'histoire pour ton string, ça ne s'utilise pas tout à fait comme ça :

    Mais comme ceci :

    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
    void testure(string s)
    {
     
     cerr<<s[0];
     return;
     
    }
     
    int main()
    {
     string s = "machin";
     
     testure(s); // ou testure("truc");
     return EXIT_SUCCESS;
    }
    Ou :

    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
    void testure(string* s)
    {
     
     cerr<<(*s)[0];
     return;
     
    }
     
    int main()
    {
     string s = "machin";
     
     testure(&s);
     
     
     return EXIT_SUCCESS;
    }
    A noter que dans le premier cas, s sera mis sur la pile, donc sera temporaire.

    Pour éviter le problème tu peux faire aussi :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    void testure(string & s)
    {
     cerr<<s[0];
     return;
    }
     
    int main()
    {
     string s = "machin";
     
     testure(s);
     
     return EXIT_SUCCESS;
    }

  4. #4
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 55
    Par défaut
    Ah merci, pour String j'ai decouvert ca que aujourd'hui
    Jusque là j'utilisais les char, mais string semble bien plus commode

    Bon j'essaye une version epurée du code qui compile, je la poste des que c'est pret.

  5. #5
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 55
    Par défaut
    Voici donc un code compilable épuré du surperflue
    Tout n'est pas la le reste sur le post suivant.

    Merci d'avance.
    1. define.h // les constante et includes
    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
     
    #ifndef H_DEFINE
    #define H_DEFINE
     
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <SDL/SDL_ttf.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <time.h>
    #include <math.h>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    #include <string>
     
    using namespace std;
     
    #define FPS 50
     
    /* Taille de la fenêtre */
    #define FCT_TAILLE            100	
    #define LARGEUR_FENETRE       1280 * FCT_TAILLE/100
    #define HAUTEUR_FENETRE       960 * FCT_TAILLE/100
    #define LARGEUR_TERRAIN       500	
    #define PROFONDEUR_TERRAIN    500
    #define NBRE_RESOLUTION       1
    #define NBRE_LIGNE_MAX        50
    #define INTERLIGNE            16
     
    #define ARIAL                 "ressources/arial.ttf"
     
    #endif
    2. main.cpp
    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
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
     
    #include "define.h"
    #include "model.h"
    #include "sdlglutils.h"
    #include "class.h"
     
     
    bool debug = true;
    GLuint modelTexture, solTexture; // Texture des models de la scene
    GLuint idBarreOutil, idBarrePerso;//, idInventaire
    int x,y,z=-5,filt,tex=1,zbuff=1,fog,rot;
    int cube1FaceTexture[6] = {3, 2, 3, 2, 1, 1}; // Tab de choix de texture pour une face
    int cube2FaceTexture[6] = {1, 1, 1, 1, 1, 1};
    int pyramide1FaceTexture[6] = {4, 4, 4, 4, 4, 0};
    float fogcolor[4] = {0.5f,0.5f,0.5f,1};
    bool afficherFenetre1 = false, afficherFenetre2 = false;
     
    // polices
    C_police* arial_16;
    C_police* arial_12;
     
    C_fenetre* fenetre1;
    C_fenetre* fenetre2;
     
    void DessinerSol();
     
     
     
    int main(int argc, char *argv[])
    {
     
        SDL_Event event;
    	SDL_Color couleurTexte = {0, 0, 0}, couleurFond = {155, 155, 155};
     
    	C_model *Pmodel[3];
     
    	GLuint fenetre1Texture;
        GLuint fenetre2Texture;
     
        bool afficheFenetre1 = false;
        bool afficheFenetre2 = false;
     
    	//void DessinerMenu(GLunint *textGL[], GLunint *menuFondGL, SDL_Rect *positionTexte[]);
     
        if(TTF_Init() == -1)
    	{
    		fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
    		exit(EXIT_FAILURE);
    	}
        if (SDL_Init(SDL_INIT_VIDEO) == -1) // Initialisation de la SDL avec gestion d'echec
        {
            fprintf(stderr, "Erreur d'initialisation de la SDL");
            exit(EXIT_FAILURE);
        }
        atexit(SDL_Quit);
        SDL_WM_SetCaption("SDL GL Application", NULL);
        SDL_SetVideoMode( LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_OPENGL | SDL_FULLSCREEN);
     
     
        arial_16 = new C_police(ARIAL, 16);
        arial_12 = new C_police(ARIAL, 12);
     
     
    // Données pour "fenetre1"
        string nomFenetre1 = "Fenetre1";
    	int nbreLigneFenetre1 = 4;
        string tabTexteFenetre1[] = { "TITRE 1",
                                       	"Sous-titre 1",
                                       	"blablabla",
                                       	"mais tu sais dire que bla" };
        int tabXFenetre1[] = {115, 115, 270, 270};
        int tabYFenetre1[] = {462, 446, 123, 123};
        C_police *tabPoliceFenetre1[] = { arial_16, arial_16, arial_12, arial_12};
    // Données pour "fenetre2"
        string nomFenetre2 = "Fenetre2";
    	int nbreLigneFenetre2 = 6;
        string tabTexteFenetre2[] = { "TITRE 2",
                                   "Sous-titre 2",
                                   "riri", "fifi", "loulou",
       	                           "et le reste de la bande"};
        int tabXFenetre2[] = {115, 115, 270, 270, 270, 270};
        int tabYFenetre2[] = {462, 446, 364, 348, 332, 316};
        C_police *tabPoliceFenetre2[] = { arial_16, arial_16, arial_12, arial_12,
                                       	    arial_12, arial_12 };
     
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluPerspective(70,(double)LARGEUR_FENETRE/HAUTEUR_FENETRE,1,1000);
     
        glEnable(GL_DEPTH_TEST); // Active le Z_Buffer
        glEnable(GL_TEXTURE_2D);
     
    	// Chargement des textures de models
        modelTexture = loadTexture("images/maTexture.jpg",0);
        solTexture = loadTexture("images/herbe.jpg",0);
        // Chargement des textures d'interface
        fenetre1Texture = loadTexture("images/fenetre1.png",0);
        fenetre2Texture = loadTexture("images/fenetre2.png",0);
     
     
        // Initialisation fenetres 1 et 2
        fenetre1 = new C_fenetre( nomFenetre1, fenetre1Texture, 0.9f,
                                  tabTexteFenetre1, nbreLigneFenetre1, 0, 0,
                                  tabPoliceFenetre1, tabXFenetre1, tabYFenetre1);
        fenetre2 = new C_fenetre( nomFenetre2, fenetre2Texture, 0.9f,
                                  tabTexteFenetre2, nbreLigneFenetre2, 0, 0,
                                  tabPoliceFenetre2, tabXFenetre2, tabYFenetre2);                          
     
     
        // boucle infinie
        for (;;)
        {
          // Boucle d'evenement  
          while(SDL_PollEvent(&event))
          {
            switch(event.type)
            {
                case SDL_QUIT:
                    exit(0);
                    break;
                case SDL_KEYDOWN:
                    switch (event.key.keysym.sym)
                    {
                        case SDLK_c:
                            afficherFenetre1 = !afficherFenetre1;
                            if (afficherFenetre2) afficherFenetre2 = 0;
                            break;
                        case SDLK_v:
                            afficherFenetre2 = !afficherFenetre2;
                            if (afficherFenetre1) afficherFenetre1 = 0;
                            break;
                        case SDLK_ESCAPE:
                            exit(0);
                            break;
                        default :
                            break; 
                    }
                    break;
            }
     
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Reinitialise Pixel_Buffer et Z_buffer
     
            glMatrixMode( GL_MODELVIEW );
            glLoadIdentity( );
     
     
            gluLookAt(0,-50,20,0,0,0,0,0,1);
            // Affichage de tous les elements
            DessinerSol();
            //DessinerObjets(Pmodel);
     
    		if (afficherFenetre1)
            {
                fenetre1->_afficheFenetre();            
            }
    		if (afficherFenetre2)
            {
                fenetre2->_afficheFenetre();
            }
     
        	// Mise à jour affichage
        	glFlush();
        	SDL_GL_SwapBuffers();
     
          }
        }
     
     
        fenetre1->~C_fenetre();
        fenetre2->~C_fenetre();
        arial_16->~C_police();
    	arial_12->~C_police();
    	glDeleteTextures(1, &modelTexture);
    	glDeleteTextures(1, &solTexture);
        glDeleteTextures(1, &fenetre1Texture);
        glDeleteTextures(1, &fenetre2Texture);
        TTF_Quit();
    	SDL_Quit();
     
        return 0;
    }
     
     
    void DessinerSol()
    {    
    // SOL
        glBindTexture(GL_TEXTURE_2D, solTexture); // Appel de la texture pour le sol
        glBegin(GL_QUADS);
        glTexCoord2i(0,0);
        glVertex3i(LARGEUR_TERRAIN/-2,PROFONDEUR_TERRAIN/-2,-1);
        glTexCoord2i(LARGEUR_TERRAIN,0);
        glVertex3i(LARGEUR_TERRAIN/2,PROFONDEUR_TERRAIN/-2,-1);
        glTexCoord2i(LARGEUR_TERRAIN,PROFONDEUR_TERRAIN);
        glVertex3i(LARGEUR_TERRAIN/2,PROFONDEUR_TERRAIN/2,-1);
        glTexCoord2i(0,PROFONDEUR_TERRAIN);
        glVertex3i(LARGEUR_TERRAIN/-2,PROFONDEUR_TERRAIN/2,-1);
        glEnd();
        if (debug) fprintf(stderr,"affichage sol : ok\n");
    }
    3. class.h
    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
     
     
    #ifndef H_CLASS
    #define H_CLASS
     
    #include "define.h"
     
    class C_police
    {
      public:
        // Font SDL - TTF
        TTF_Font *_font;
        // Taille
        int _tailleFont;
        // Choix de Font
        string _fileFont;
     
      public :
        // Constructeur
        C_police(string fileFont, int tailleFont);
        // Destructeur
        ~C_police(void);
      private :
        // Cree la font
        TTF_Font* _creerFont();
     
    };
     
    class C_ligneTexte
    {
      public:
        // Texte à afficher
        string _text;
        // Pointeur sur surface GL
        GLuint _textGL;
        // Position
        SDL_Rect _positionTexte;
        // Choix de Font et couleurs
        C_police *_police;
        SDL_Color _couleurTexte;
        SDL_Color _couleurFond;
     
      public :
        // Pas de Constructeur, pour pouvoir créer les tab de "C_ligneText" et Positions
        C_ligneTexte(string text, int tx, int ty, C_police *police, SDL_Rect positionFenetre);
        // Destructeur
        ~C_ligneTexte(void);
        // Creation de la ligne de texte affichable
        GLuint _creerLigneTexte();
     
    };
     
    // Classe Interface comprendra toute les fenetres ou surfaces s'affichant en 
    // avant de la scene 3D (uniquement des surfaces 2D texturées)
    class C_fenetre
    {
      public :
        // Position x, y (angle inf G)
        SDL_Rect _positionFenetre;
        // Nombre de lignes de texte
        int _nbreLigne;
        // Contenu texte defini par 'nbreLigne' lignes de texte
        C_ligneTexte *_lignesFenetre[];
        // Choix des textures
        int _texture; // Texture
        //Nom
        string _nom;
     
      private:
        // Alpha de la Texture
        float _alphaBase;
        // indice de liste d'affichage
        GLuint _idFenetre;
        GLuint _idTexte;
        // Savoir si le model a deja ete cree
        bool _cree;
     
      public :
        // Constructeur
        C_fenetre( string nom, int textureFenetre, float alphaBase,
                   string tabTexte[], int nbreLigne, int fx, int fy, 
                   C_police *tabPolice[], int tabX[], int tabY[]  );
        // Destructeur
        ~C_fenetre(void);
        // Création de la fenetre
        GLuint _buildFenetre(); //GLuint C_fenetre::_buildTextes()
        GLuint _buildTextes();
        // Fonction d'affichage
        void _afficheFenetre();
        void _afficheTexte();
    };
     
    #endif
    4. class.cpp
    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
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
     
     
    #include "define.h"
    #include "sdlglutils.h"
    #include "class.h"
     
    // Initialise les Fonts
    C_police::C_police(string fileFont, int tailleFont)
    {
       TTF_Font *valRetour;
     
       this->_fileFont = fileFont; 		// chemein d'acces au fichier TTF
       this->_tailleFont = tailleFont; 	// Taille de la police voulue
       this->_font = NULL; 				// Pointeur sur TTF_Font
       valRetour = this->_creerFont();
       if(!valRetour) cerr << "PB de Font : " << this->_fileFont << "\n";
       else this->_font = valRetour;
       cout << "construction font : " << this->_font << "\n\n";
    }
     
    C_police::~C_police()
    {
       TTF_CloseFont(this->_font);
       delete this;
    }
     
    TTF_Font* C_police::_creerFont()
    {
       TTF_Font *p_font;
     
       p_font = TTF_OpenFont(this->_fileFont.c_str(), this->_tailleFont);
       if(!p_font) cerr << "Impossible de charger la Font : " << TTF_GetError() << "\n";
     
       return p_font;
    }
     
    // Initialise un element de type "C_ligneText" appelés par la class "C_contenuText"
    C_ligneTexte::C_ligneTexte(string text, int x, int y, C_police *police, SDL_Rect positionFenetre) // tabTexte[i], tabX[i], tabY[i], tabPolice[i]
    {
       int w, h;
       SDL_Surface *surfaceTexte = NULL;
     
       this->_text = text;
       // Position, Dimensions
       this->_positionTexte.x = x + positionFenetre.x; // largeur du texte
       this->_positionTexte.y = y + positionFenetre.y; // hauteur du texte
       this->_positionTexte.w = 0; // largeur du texte
       this->_positionTexte.h = 0; // hauteur du texte
       // Choix de Font
       this->_police = police;
       this->_couleurTexte.r = (Uint8) 255;
       this->_couleurTexte.g = (Uint8) 255;
       this->_couleurTexte.b = (Uint8) 255;
       this->_couleurFond.r = (Uint8) 0;
       this->_couleurFond.g = (Uint8) 0;
       this->_couleurFond.b = (Uint8) 0;
       this->_textGL = 0;
       cerr << "ligneText id : " << this->_textGL << "\n";
       this->_textGL = this->_creerLigneTexte();
       cerr << "ligneText id : " << this->_textGL << ", text = " << this->_text 
       		<< ", police : " << this->_police->_font << " | " << police->_font << "\n";
     
    }
     
    C_ligneTexte::~C_ligneTexte()
    {
       delete this;
    }
     
    GLuint C_ligneTexte::_creerLigneTexte()
    {
       int w, h;
       SDL_Surface *surfaceTexte = NULL;
       GLuint idTextGL; // Adresse d'un texture de texte
     
       cerr << "\n\n === DEBUT SDL TTF to GL ===\n\n";
       // Creation des "surface TTF" pour chaque ligne de texte
       surfaceTexte = TTF_RenderText_Shaded( this->_police->_font, this->_text.c_str(), 
                                             this->_couleurTexte, this->_couleurFond );
       SDL_SetColorKey(surfaceTexte, SDL_SRCCOLORKEY, SDL_MapRGB(surfaceTexte->format, 0, 0, 0));
       TTF_SizeText( this->_police->_font, this->_text.c_str(), &w, &h );
       this->_positionTexte.w = w;
       this->_positionTexte.h = h;
       cerr << "ligneText = ok, text = " << this->_text << "\n";
       // Conversion de la "surface TTF" en "Texture GL"
       idTextGL = convertSurfaceTTF2GL(surfaceTexte);
       cerr << "Convertion Surface Texte, id : " << idTextGL << ", dimensions : " 
       		<< this->_positionTexte.w << " | " << this->_positionTexte.h << "\n";
       if (!this->_textGL) this->_textGL = idTextGL;
       cerr << "\n\n === FIN SDL TTF to GL ===\n\n";
     
       return idTextGL;                          
    }
     
    // Contructeur de la classe "C_interface"
    C_fenetre::C_fenetre( string nom, int textureFenetre, float alphaBase,
                          string tabTexte[], int nbreLigne, int fx, int fy, 
                          C_police *tabPolice[], int tabX[], int tabY[] )
    {
        int i;
     
        cerr << "\n\n ============= DEBUT INIT FENETRE =============\n\n";
    	cerr << "nom : " << nom[0] << " = ok , nbreLigne : " << nbreLigne 
    		 << ", texture : " << textureFenetre << " | " << &textureFenetre << "\n";
     
        this->_nom = nom;
     
        this->_nbreLigne = nbreLigne;
     
        this->_texture = textureFenetre; 
     
        this->_positionFenetre.w = 512;
        this->_positionFenetre.h = 512;
        this->_positionFenetre.x = ( LARGEUR_FENETRE - this->_positionFenetre.w )/2;
        this->_positionFenetre.y = 200;
     
        this->_alphaBase = alphaBase;
     
        this->_idFenetre = 0;
        cerr << "\n\n ======= DEBUT INIT TEXTE =======\n\n";
    	for (i = 0; i < this->_nbreLigne; i++)
        {
            this->_lignesFenetre[i] = new C_ligneTexte( tabTexte[i], tabX[i], tabY[i], 
    							   	 	 			   	tabPolice[i], 
    												   	this->_positionFenetre);
        }
        cerr << "\n\n ======= FIN INIT TEXTE =======\n\n";
     
        this->_cree = 0;
        this->_idFenetre = 0;
        this->_idTexte = 0;
    	if(!this->_cree)
        {
            this->_idFenetre = this->_buildFenetre();
            //this->_idTexte = this->_buildTextes(); // <= PB avec appel de la liste d'affichage
        }
        cerr << "INIT FENETRE = ok , nbreLigne : " << this->_nbreLigne 
    		 << ", texture : " << this->_texture << " | " << &this->_texture << "\n"; 
    /*    cerr << "INIT FENETRE : " << this->_nom << " = ok , nbreLigne : " 
    		 << this->nbreLigne << ", texture : " << this->texture << "\n"; 
    */    cerr << "\n\n ============= FIN INIT FENETRE ============= \n\n";
    }
     
    C_fenetre::~C_fenetre()
    {
       int i;
     
       for (i = 0; i < this->_nbreLigne; i++)
       {
            this->_lignesFenetre[i]->~C_ligneTexte();
       }
       delete this;
    }
     
    GLuint C_fenetre::_buildFenetre()
    {
       GLuint idAffFenetre = 0;
     
    	cerr << "\n\n ======= DEBUT CREATION FENETRE =======\n\n";
    	// Creation de la "surface GL" pour la fenetre
        idAffFenetre = glGenLists(1);
        glNewList(idAffFenetre,GL_COMPILE);				        // Start Building A List
    		glBindTexture(GL_TEXTURE_2D, this->_texture);		 // Selection Texture Fenetre
            glColor4f(1.0f,1.0f,1.0f,1.0f);                          
        	glBegin(GL_QUADS);
    			glTexCoord2f(0.0,0.0);
    			glVertex2i( this->_positionFenetre.x,this->_positionFenetre.y);
    			glTexCoord2f(1.0,0.0);	
    			glVertex2i( this->_positionFenetre.x + this->_positionFenetre.w,
                            this->_positionFenetre.y);	
    			glTexCoord2f(1.0,1.0);
    			glVertex2i( this->_positionFenetre.x + this->_positionFenetre.w, 
                            this->_positionFenetre.y + this->_positionFenetre.h);
    			glTexCoord2f(0.0,1.0);	
    			glVertex2i( this->_positionFenetre.x, this->_positionFenetre.y + 
                            this->_positionFenetre.h);	
    		glEnd();	
    		glColor4f(1.0f,1.0f,1.0f,1.0f);    	
    	glEndList();
        this->_cree = 1;
        cerr << "id : " << idAffFenetre << ", texture  : " << this->_texture << "\n";
    	cerr << "\n\n ======= FIN CREATION FENETRE =======\n\n";
    	return idAffFenetre;
    }
     
    GLuint C_fenetre::_buildTextes()
    {
        GLuint idAffTextes[12]; // Indice de Liste d'affichage
        int i;
     
        cerr << "\n\n ======= DEBUT CREATION TEXTES =======\n\n";
        cerr << "id fenetre : " << this->_idFenetre << ", nbre ligne : " 
    		 << this->_nbreLigne << "\n";
     
    	for (i = 0; i < this->_nbreLigne; i++)
        {
          idAffTextes[i] = glGenLists(1);
          // Creation des "surface GL" pour chaque ligne de texte
    	  glNewList(idAffTextes[i], GL_COMPILE);
            glBindTexture(GL_TEXTURE_2D, this->_lignesFenetre[i]->_textGL);
            glBegin(GL_QUADS);
    			glTexCoord2f(0.0,0.0);
    			glVertex2i( this->_lignesFenetre[i]->_positionTexte.x,
                            this->_lignesFenetre[i]->_positionTexte.y);
    			glTexCoord2f(1.0,0.0);	
    			glVertex2i( this->_lignesFenetre[i]->_positionTexte.x + 
                            this->_lignesFenetre[i]->_positionTexte.w,
                            this->_lignesFenetre[i]->_positionTexte.y);	
    			glTexCoord2f(1.0,1.0);
    			glVertex2i( this->_lignesFenetre[i]->_positionTexte.x + 
                            this->_lignesFenetre[i]->_positionTexte.w, 
                            this->_lignesFenetre[i]->_positionTexte.y + 
                            this->_lignesFenetre[i]->_positionTexte.h);
    			glTexCoord2f(0.0,1.0);	
    			glVertex2i( this->_lignesFenetre[i]->_positionTexte.x, 
                            this->_lignesFenetre[i]->_positionTexte.y + 
                            this->_lignesFenetre[i]->_positionTexte.h);	
    		glEnd();
          glEndList();	
          cerr << "CREATION Texte fenetre = ok, id : " << idAffTextes[i] 
    	  	   << ", pos : " << this->_lignesFenetre[i]->_positionTexte.x 
    	 	   << " | " << this->_lignesFenetre[i]->_positionTexte.y 
    		   << ", Dimensions : " << this->_lignesFenetre[i]->_positionTexte.w 
    		   << " x " << this->_lignesFenetre[i]->_positionTexte.h << "\n";
        }
        cerr << "\n\n ======= FIN CREATION TEXTES =======\n\n";
        return idAffTextes[0];
    }
     
    void C_fenetre::_afficheFenetre()
    {
     	    int i;
     
            cerr << "\n\n ======= DEBUT AFFICHAGE FENETRE =======\n\n";
        	cerr << "AFFICHAGE FENETRE = Debut, id : " << this->_idFenetre 
    			 << ", nbreLigne : " << this->_nbreLigne 
    			 << ", texture : " << this->_texture << "\n";
        	glColor3f(1.0f,1.0f,1.0f);							// Bright White
        	glEnable(GL_BLEND);									// Enable Blending
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //initialisation de la transparence 
            glEnable(GL_TEXTURE_2D);
     
     
        	glDisable(GL_DEPTH_TEST);							
        	glMatrixMode(GL_PROJECTION);						
        	glPushMatrix();	
     
        	glLoadIdentity();									
        	glOrtho(0,LARGEUR_FENETRE,0,HAUTEUR_FENETRE,-1,1);	
        	glMatrixMode(GL_MODELVIEW);							
        	glPushMatrix();	
     
        	glLoadIdentity();	
     
        	glTranslated(0,0,0);
     
        	//glEnable(GL_ALPHA_TEST);
            //glAlphaFunc(GL_GREATER, 0.0f);
     
            glBindTexture(GL_TEXTURE_2D, this->_texture);		 // Selection Texture Fenetre
            glCallList(this->_idFenetre);
           // glDisable(GL_ALPHA_TEST);
     
        	glMatrixMode(GL_PROJECTION);					
        	glPopMatrix();										
        	glMatrixMode(GL_MODELVIEW);							
        	glPopMatrix();		
            glEnable(GL_DEPTH_TEST);
     
            glDisable(GL_BLEND);
            cerr << "\n\n ======= FIN AFFICHAGE FENETRE =======\n\n";
    }
     
    void C_fenetre::_afficheTexte()
    {
        int i;
     
        glEnable(GL_BLEND);					                            // Autorise le blending pour la 2D				
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //initialisation de la transparence 
    	glEnable(GL_TEXTURE_2D);
     
    	glDisable(GL_DEPTH_TEST);							
    	glMatrixMode(GL_PROJECTION);						
    	glPushMatrix();	
     
    	glLoadIdentity();									
    	glOrtho(0,LARGEUR_FENETRE,0,HAUTEUR_FENETRE,-1,1);	
    	glMatrixMode(GL_MODELVIEW);							
    	glPushMatrix();	
     
    	glLoadIdentity();	
     
    	glTranslated(0,0,0);
     
    	for (i = 0; i < this->_nbreLigne; i++)
        {
            glBindTexture(GL_TEXTURE_2D, this->_lignesFenetre[i]->_textGL);  // Selection Texture Texte
            glCallList(this->_idTexte + i);
            cerr << "affichage TEXTE : " << this->_nom << " = ok, text : " 
    			 << this->_lignesFenetre[i]->_text << ", Ligne : " << i << "\n";
        }
     
        glMatrixMode(GL_PROJECTION);					
    	glPopMatrix();										
    	glMatrixMode(GL_MODELVIEW);							
    	glPopMatrix();		
        glEnable(GL_DEPTH_TEST);
     
    	glDisable(GL_BLEND);								            // Annule le blending avant retour en 3D
        glColor4f(1.0f,1.0f,1.0f,1.0f);
        glColor3f(1.0f,1.0f,1.0f);                                      // couleur = blanc         
     
    }

  6. #6
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2006
    Messages : 55
    Par défaut
    suite et fin...

    5. sdlglutils.h
    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
     
     
     
    #ifndef SDLGLUTILS_H
    #define SDLGLUTILS_H
     
    #include <GL/gl.h>
    #include <SDL/SDL.h>
     
     
     
     
    GLuint convertSurfaceTTF2GL(SDL_Surface *surfaceName);
     
    GLuint loadTexture(const char * filename,bool useFont = false,bool useMipMap = true);
     
    #endif
    7. sdlglutils.cpp //fonction de chargement image et conversion pour GL
    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
     
     
     
    #ifndef SDLGLUTILS_H
    #define SDLGLUTILS_H
     
    #include <GL/gl.h>
    #include <SDL/SDL.h>
     
     
     
     
    GLuint convertSurfaceTTF2GL(SDL_Surface *surfaceName);
     
    GLuint loadTexture(const char * filename,bool useFont = false,bool useMipMap = true);
     
    #endif

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

Discussions similaires

  1. Passage d'argument d'une classe à une autre
    Par aurelie.guegan.15 dans le forum PyQt
    Réponses: 3
    Dernier message: 04/09/2014, 20h14
  2. Pb de passage d'argument dans une fonction de classe maison
    Par deusyss dans le forum Général Python
    Réponses: 10
    Dernier message: 18/03/2010, 02h14
  3. Passage d'argument dans une fonction d'une autre classe.
    Par lavince dans le forum Général Python
    Réponses: 5
    Dernier message: 13/09/2008, 22h16
  4. Réponses: 4
    Dernier message: 08/02/2008, 13h01
  5. [VB.NET] passage d'arguments d'une classe(form1) à une autre
    Par zouhib dans le forum Windows Forms
    Réponses: 5
    Dernier message: 05/05/2006, 16h54

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