Hallo Leute
ich möchte das SDLSpiel aus dem Buch C++ für Spieleprogrammierer erweitern.
Dazu habe ich nun begonnen ein Menü zu erstellen.
Dass ist einfach ein Hintergrund, auf dem nun Text erscheinen soll. Der Text soll wie folgt aussehen:
(1) Spiel starten
(2) Highscore
(3) Beenden
und eventuell noch mehr.
Jetzt sitze ich schon 3 Tage daran irgendwie einen Text mit der SDL_ttf.h zu rendern, doch komme einfach nicht weiter.
Ich stelle euch hier einmal meine Font.hpp und meine Font.cpp vor, welche ich zusammen gebalstet habe.
Font.hpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#ifndef FONT_HPP
#define FONT_HPP
#include "SDL_ttf.h"
#include "Menü.hpp"
class CFont
{ public:
CFont (); void Run ();
private:
TTF_Font *font; SDL_Color textColor; SDL_Surface *m_pScreen; SDL_Surface *message; void load ();
void Render ();
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL );
void Quit ();
};#endif
|
und hier ist die Font.cpp
|
C-/C++-Quelltext
|
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
|
#include "Font.hpp"
CFont::CFont (){ SDL_Surface *message = NULL; TTF_Font *font = NULL; SDL_Color textColor = { 255, 255, 255 }; m_pScreen = g_pFramework->GetScreen ();}void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{ SDL_Rect offset;//Get offsets
offset.x = x; offset.y = y;//Blit
SDL_BlitSurface( source, clip, destination, &offset );}void CFont::load ()
{ if( TTF_Init() == -1 )
{ exit (0); } //Open the font
font = TTF_OpenFont( "lazy.ttf", 28 );
//If there was an error in loading the font
if( font == NULL )
{ exit (0); }}void CFont::Render ()
{ //Render the text
message = TTF_RenderText_Solid( font, "(1) Starten", textColor );
//If there was an error in rendering the text
if( message == NULL )
{ exit (0); }//Apply the images to the screen
apply_surface( 0, 150, message, m_pScreen );//Update the screen
if( SDL_Flip( m_pScreen ) == -1 )
{ exit (0); }}void CFont::Run ()
{ load (); Render ();}void CFont::Quit ()
{ SDL_FreeSurface( message );//Close the font that was used
TTF_CloseFont( font );//Quit SDL_ttf
TTF_Quit();}
|
Die Funktion CFont::Run wird aus dem Menü herraus aufgerufen. Im Menü selber läuft eine Schleife, welche entweder durch den druck der Escape Taste oder der 1 beendet wird. Bei 1 Startet das Spiel und bei Escape wird es sofort beendet. Die Funktion Run soll sogesehen alle Funktionen der Klasse CFont steuern. Sollte irgendwo ein Fehler auftreten habe ich dort exit(0); stehen. Das ist jedoch nur übergangsweise. Dort kommt später noch ein rückgabewert hin, durch welchen dann ein Fehler ausgeschmissen wird und dann das Programm sauber beendet wird.
Da der Code hier im Forum komisch formatiert ist, habe ich hier mal die cpp und hpp datei hochgeladen, damit man mehr übersicht hat.
Font.cpp:
http://www.mediafire.com/?8fknl6d85n7e5o1
Font.hpp:
http://www.mediafire.com/?np8meyxal2tw911
so nun bekomme ich immer folgenden Fehler:
Fehler 1 error LNK2001: Nicht aufgelöstes externes Symbol ""private: void __thiscall CFont::apply_surface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (
?apply_surface@CFont@@AAEXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z)".
Irgendetwas stimmt dort mit der Funtkion
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
Weiß jemand wie ich diesen Fehler umgehe und woher er kommt?
Und kennt jemand eine bessere möglichkeit Text anzuzeigen, da mir das was ich dort erstellt habe, etwas ungeeignet finde und sehr durcheinander.
Ich hoffe mir kann jemand helfen.