So, I wanted to try out text rendering in opengl and I followed SDL ttf:Tutorials:Fonts in OpenGL - GPWiki
I tweaked the function a bit so finally it looked like this:
Code:
void RenderText(const TTF_Font *Font, SDL_Color color, const double &X, const double &Y, const std::string& Text)
{
/*Create some variables.*/
SDL_Surface *Message = TTF_RenderText_Blended(const_cast<TTF_Font*>(Font), Text.c_str(), color);
unsigned Texture = 0;
/*Generate an OpenGL 2D texture from the SDL_Surface*.*/
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Message->w, Message->h, 0, GL_BGRA,GL_UNSIGNED_BYTE, Message->pixels);
glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex2d(X, Y);
glTexCoord2d(1, 0); glVertex2d(X+Message->w, Y);
glTexCoord2d(1, 1); glVertex2d(X+Message->w, Y+Message->h);
glTexCoord2d(0, 1); glVertex2d(X, Y+Message->h);
glEnd();
glDeleteTextures(1, &Texture);
SDL_FreeSurface(Message);
}
I call this code like that:
Code:
glEnable(GL_TEXTURE_2D);
RenderText(font,must,235.0,190.0,start);
glDisable(GL_TEXTURE_2D);
The variables are declared outside the main cycle
Code:
std::string start = "Alusta mängu";
TTF_Font *font;
font = TTF_OpenFont("data/georgia.ttf",20);
SDL_Color must = {0,0,0};
If I comment RenderText(font,must... out then everything works (have some other rectangles it's drawing etc.).
Now problem is that I get the "Process terminated with status 3" when running it, can someone please help? And for future reference, what exactlt does status 3 mean?