bool FONT = false;
TTF_Font* Font = NULL;
Font = TTF_OpenFont("arial.ttf", 14);
if(Font == NULL)
std::cout << TTF_GetError() << std::endl;
else
FONT = true;
SDL_ttf not opening font
I am deeply confused as to why this won't open the font:
arial.ttf is in the same file as the .exe but it just isn't working.
SDL_ttf is initialized.
Also I'm not sure how to find out the error because there's no console :3, I remember something about stdout or something along those lines from ages ago when I dabbled with SDL
SDL, at least the version I have, redirects cout to a text file name stdout.txt . It will probably be placed in the same folder as your executable, in the bin\debug path or whatever it is.
Or, you can do it yourself with std::ofstream.
More info on std::ofstream.
Or, you can do it yourself with std::ofstream.
#include <fstream>std::ofstream errfile("my_error_file.txt");if(Font == NULL){ errfile << "error loading font: " << TTF_GetError() << std::endl;}
More info on std::ofstream.
Ok, the problem was that arial.ttf was in the wrong folder, now don't get an error message.
The text won't render though;
I used this: http://www.gamedev.net/community/forums/topic.asp?topic_id=284259
The text won't render though;
void Text(std::string Text, TTF_Font *Font, SDL_Color Colour, SDL_Rect *Position) { SDL_Surface *Initial; SDL_Surface *Intermediary; SDL_Rect Rect; int W, H; unsigned int Texture; Initial = TTF_RenderText_Blended(Font, Text.c_str(), Colour); W = NextPowerOfTwo(Initial->w); H = NextPowerOfTwo(Initial->h); Intermediary = SDL_CreateRGBSurface(0, W, H, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); SDL_BlitSurface(Initial, 0, Intermediary, 0); glGenTextures(1, &Texture); glBindTexture(GL_TEXTURE_2D, Texture); glTexImage2D(GL_TEXTURE_2D, 0, 4, W, H, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, Intermediary->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, Texture); glColor3f(Colour.r, Colour.g, Colour.b); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex2f(Position->x, Position->y); glTexCoord2f(1.0f, 1.0f); glVertex2f(Position->x + W, Position->y); glTexCoord2f(1.0f, 0.0f); glVertex2f(Position->x + W, Position->y + H); glTexCoord2f(0.0f, 0.0f); glVertex2f(Position->x, Position->y + H); glEnd(); glFinish(); Position->w = Initial->w; Position->h = Initial->h; SDL_FreeSurface(Initial); SDL_FreeSurface(Intermediary); glDeleteTextures(1, &Texture); /*Errors << "Text OGL Error: " << glGetError() << std::endl; Errors << "Text SDL Error: " << SDL_GetError() << std::endl;*/}inline int Round(double x) { return (int)(x + 0.5); }inline int NextPowerOfTwo(int x) { double LogBase = log((double)x) / log(2.0f); return Round(pow(2, ceil(LogBase)));}
glEnable2D(); glDisable(GL_DEPTH_TEST); if(FONT) { TextColour.r = 0; TextColour.g = 0; TextColour.b = 0; TextPosition.x = View[0]/2; TextPosition.y = View[1]/2; Text("G'day, kind sir", Font, TextColour, &TextPosition); } glEnable(GL_DEPTH_TEST); glDisable2D();
I used this: http://www.gamedev.net/community/forums/topic.asp?topic_id=284259
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement