mac-10
Still Fresh
Hi there
I am having some trouble with a class I am trying to write.
I am new to C++ and have followed some tutorials on the web about
classes but I have run into a problem. Please be gentle I am new to C++
And last time I posted some code I got torn a new one.
I was trying to make a class to load in and display fonts.
Displaying them at different sizes and colours.
The class seems to work up until the point I try and write it to the screen surface.
As you can see I am using the drawtext function that I borrowed from guyforks sdl examples
Does the problem have something to do with the pointer to the screen surface?
Or
Am I not grasping OOP
Any help or advice on this would be great.
CODE
class fontMaker{
private:
TTF_Font* font;
public:
void LoadFont(char*,int);
void drawText(SDL_Surface*, char*, int, int, int, int, int);
void renderText();
};
void fontMaker::LoadFont(char* font_path,int size){
font = TTF_OpenFont(font_path, size);
}
void fontMaker::drawText(SDL_Surface* screen, char* string, int x, int y, int fR, int fG, int fB)
{
SDL_Color foregroundColor = { fR, fG, fB };
SDL_Surface* textSurface = TTF_RenderText_Blended(font,string, foregroundColor);
SDL_Rect textLocation = { x, y, 0, 0 };
SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
SDL_FreeSurface(textSurface);
}
fontMaker my_font;
my_font.LoadFont("AGITPM__.TTF",12);
my_font.drawText(screen,"Hello I am the font class",10,10,255,255,255);
thanks
Mac
I am having some trouble with a class I am trying to write.
I am new to C++ and have followed some tutorials on the web about
classes but I have run into a problem. Please be gentle I am new to C++
And last time I posted some code I got torn a new one.
I was trying to make a class to load in and display fonts.
Displaying them at different sizes and colours.
The class seems to work up until the point I try and write it to the screen surface.
As you can see I am using the drawtext function that I borrowed from guyforks sdl examples
Does the problem have something to do with the pointer to the screen surface?
Or
Am I not grasping OOP
Any help or advice on this would be great.
CODE
class fontMaker{
private:
TTF_Font* font;
public:
void LoadFont(char*,int);
void drawText(SDL_Surface*, char*, int, int, int, int, int);
void renderText();
};
void fontMaker::LoadFont(char* font_path,int size){
font = TTF_OpenFont(font_path, size);
}
void fontMaker::drawText(SDL_Surface* screen, char* string, int x, int y, int fR, int fG, int fB)
{
SDL_Color foregroundColor = { fR, fG, fB };
SDL_Surface* textSurface = TTF_RenderText_Blended(font,string, foregroundColor);
SDL_Rect textLocation = { x, y, 0, 0 };
SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
SDL_FreeSurface(textSurface);
}
fontMaker my_font;
my_font.LoadFont("AGITPM__.TTF",12);
my_font.drawText(screen,"Hello I am the font class",10,10,255,255,255);
thanks
Mac