Hallo zusammen,
ich schreibe gerade eine PokerEngine (C/C++) und komme bei dem folgenden Problem nicht weiter:
Für die Engine benutze ich die SDL Bibliothek welche ja an sich wunderbar funktioniert. Nun wollte ich natürlich auch die SDL_TTF benutzen um Text auf einfache Art und weise darstellen zu können.
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
//Part of : CSurface.cpp
bool CSurface::OnTextDraw(SDL_Surface* Surf_Dest, int X, int Y, int r, int g, int b, int size,char* text) {
if(TTF_Init()==-1) return false;
SDL_Rect DestR;
SDL_Color color={r,g,b};
TTF_Font *font;
SDL_Surface *Surf_Text;
font = TTF_OpenFont("Arial.ttf",size);
TTF_SetFontStyle(font, 1); // BOLD = 1
Surf_Text=TTF_RenderText_Solid(font,text,color);
DestR.x = X;
DestR.y = Y;
SDL_BlitSurface(Surf_Text,NULL,Surf_Dest,&DestR);
SDL_Flip(Surf_Dest);
TTF_Quit();
return true;
}
|
... kompiliert & ausgeführt wird mir auch der Text angezeigt - nur nach etwa 10 sek. bricht die Anwendung mit
"Segment fault" ab.
Die Funktion CSurface::OnTextDraw wird aus einer anderen Klasse (CApp -> render()) aufgerufen. Dies funktioniert auch gut, da in der CSurface Klasse auch die Routinen für das Anzeigen der Bitmaps implementiert sind :
|
Source code
|
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
|
//CSurface.h
//==============================================================================
// Surface functions
//==============================================================================
#ifndef _CSURFACE_H_
#define _CSURFACE_H_
#include <SDL.h>
#include <SDL/SDL_ttf.h>
//==============================================================================
class CSurface {
public:
CSurface();
public:
static SDL_Surface* OnLoad(char* File);
static bool OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y);
static bool OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y, int X2, int Y2, int W, int H);
static bool OnTextDraw(SDL_Surface* Surf_Dest, int X, int Y, int r, int g, int b, int size,char* text);
};
//==============================================================================
#endif
|
Vielleicht kann mir jemand von Euch bei meinem "Hänger" helfen, da mir derzeit keine Lösung dafür einfällt.
Wie schon oben gesagt - es
muss an der Funktion CSurface::OnTextDraw liegen, da ohne Textdarstellung alles sauber läuft.....
Gruß