Im trying to render text with sdl-ttf to a surface that is converted to
opengl texture later to show in a quad.
Here is my code:
fgcol.r=0;
fgcol.g=1;
fgcol.b=0;
tmp = TTF_RenderText_Blended(theme::getTheme()->font,text.c_str
(),fgcol);
if (tmp==NULL) printf(“Error rendering text\n”);
else {
tmp=SDL_DisplayFormat(tmp);
if (tmp==NULL) printf(“Error converting rendered text\n”);
}
glBindTexture(GL_TEXTURE_2D, caption_tex); // 2d texture (x and y
size)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, tmp->w, tmp->h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, tmp->pixels);
And here is the rendering code:
glBindTexture(GL_TEXTURE_2D, caption_tex);
glTexCoord2f(0.0,0.0);
glVertex2i(x+10,y+5);
glTexCoord2f(1.0,0.0);
glVertex2i(x+w-10,y+5);
glTexCoord2f(1.0,1.0);
glVertex2i(x+w-10,y+h-5);
glTexCoord2f(0.0,1.0);
glVertex2i(x+10,y+h-5);
But instead of text what I get is the previously used texture. Can
somebody see what Im doing wrong here?–
Roger D. Vargas
Formatur Santiago