Je suis actuellement en train de programmer une classe "SDL" qui gère toute les
possibilité de la SDL pour que ça soit plus simple à utiliser par la suite.
La classe est terminer mais il se trouve que la méthode "affiche()" ne marche pas.
En fait le programme s'éteint lorsque j'appuie sur la flêche du haut.

Voici mon code:

Le 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
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
 #include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>
#include <SDL/SDL_ttf.h>
#include "SDL.h"
 
 
using namespace std;
 
 
int main(int argc, char *argv[])
{
  SDL_Event event;
  int continuer=1;
  SDL_Surface*ecran;
  int aff1=0;
 
  /* initialisation de la SDL*/
  SDL_Init(SDL_INIT_VIDEO);
  SDL_WM_SetCaption("   Test c++ et classe SDL  ", NULL);
  SDL_WM_SetIcon(IMG_Load("nuinui4.png"), NULL);
  ecran = SDL_SetVideoMode( 1000  ,  800  , 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
  SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
 
 
  /*création des  objets de type SDL*/
  SDL menu1(ecran, "surf.jpg", 0, 0);
 
while (continuer)
{
    SDL_WaitEvent(&event);
     switch(event.type)
        {
            case SDL_QUIT:
                continuer = 0;
                break;
 
            case SDL_KEYDOWN  :
            switch (event.key.keysym.sym)
            {
                case SDLK_ESCAPE:
                continuer=0;
                break;
 
               case SDLK_UP:
               aff1=1;
               break;
            }
            break;
        }
        if (aff1)
        menu1.affiche();
}
 
 
 
 
    menu1.Free();
    SDL_Quit();
    return EXIT_SUCCESS;
}
 
 
le SDL.h
#ifndef DEF_SDL
#define DEF_SDL
 
class SDL
{
    public:
    SDL (SDL_Surface*, const char*nom="",long x=0, long y=0);//constructeur
 
    void SetNom(const char *);//changer le nom
    void setPos (long,long);//changer la position
    void SetTrans(long, long, long);//changer la transaparence
    void SetTransA(long);// changer la transparence alpha
    void SetColor(long, long, long);//changer la couleure
    void SetTexte(const char*, const char*, long);
    void Free();
    void affiche();
 
 
 
    private:
    //position
    long m_x, m_y;
 
    //transparence
    bool m_t, m_tA;
    long m_setTransA;
    long m_setTransC[3];
 
   //couleur et contenue
    bool m_color;
    long m_setColor [3];
    const char *m_nom;
 
    //texte
     bool m_texte;
     const char*m_message;
     const char*m_police;
     long m_taille;
 
     //Surface
     SDL_Surface *ecran;
     SDL_Surface *m_surface;
     TTF_Font *police;
};
 
 
#endif
 
 
 
Et enfin, le SDL.cpp
#include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_Image.h>
#include <SDL/SDL_ttf.h>
 
#include "SDL.h"
 
using namespace std;
 
SDL::SDL (SDL_Surface*ecran1, const char*nom ,long x, long y)
{
        ecran=ecran1;
        m_nom=nom;
        m_x=x;
        m_y=y;
        m_t=false;
        m_tA=false;
        m_setTransA=0;
        m_setTransC[3]=0;
        m_color= false;
        m_setColor[3]=0;
        m_texte=false;
        m_surface=NULL;
        m_message=NULL;
        m_police =NULL;
        m_taille=0;
        police=NULL;
}
 
void SDL::SetNom(const char *nom)//changer le nom
{
    m_color=false;
    m_nom=nom;
}
 
 
void SDL::setPos (long x=0,long y=0)//changer la position
{
    m_x=x;
    m_y=y;
}
 
 
void SDL::SetTrans(long a, long b, long c)//changer la transaparence
{
       m_t=true;
       m_tA=false;
 
       m_setTransC[0]= a;
       m_setTransC[1]= b;
       m_setTransC[2]= c;
 
}
 
void SDL::SetTransA(long a)// changer la transparence alpha
{
    m_t=false;
    m_tA=true;
 
    m_setTransA=a;
}
 
void SDL::SetColor(long a, long b, long c)//changer la couleur
{
    m_color=true;
 
    m_setColor[0]= a;
    m_setColor[1]= b;
    m_setColor[2]= c;
}
 
void SDL::SetTexte(const char* message, const char* police, long taille)
{
    m_message=message;
    m_police=police;
    m_taille=taille;
}
 
void SDL::Free()//pour libérer la surface;
{
  SDL_FreeSurface (m_surface);
  SDL_FreeSurface (ecran);
  if (m_texte)
  TTF_CloseFont(police);
}
 
 
void SDL::affiche()
{
   if(!m_texte)
   {
    m_surface=IMG_Load(m_nom);
    SDL_Rect position;
 
    position.x=m_x;
    position.y=m_y;
 
    if (m_t)
    {
    SDL_SetColorKey(m_surface , SDL_SRCCOLORKEY, SDL_MapRGB( m_surface ->format, m_setTransC[0], m_setTransC[1], m_setTransC[2]));
    }
    else if (m_tA)
    {
    SDL_SetAlpha(m_surface, SDL_SRCALPHA, m_setTransA);
    }
 
    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
    SDL_BlitSurface(m_surface, NULL, ecran, &position);
    SDL_Flip(ecran);
   }
   else
    {
    SDL_Rect position;
 
    SDL_Color couleur = {m_setColor[0], m_setColor[1], m_setColor[2]};
    police = TTF_OpenFont(m_police, m_taille);
    m_surface = TTF_RenderText_Blended(police, m_message , couleur);
    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
    SDL_BlitSurface(m_surface, NULL, ecran, &position);
    SDL_Flip(ecran);
    }
 
}
Merci de vos suggéstions et conseils, pour résoudre mon prolbème.