Font in SDL with opengl?

Hello Everyone,
i am using Opengl with SDL(instead of glut),i tried to render SDL text creating function as follows
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
27
28
29
30
Uint32 colorRGB(SDL_Surface *surface, Uint8 R, Uint8 G, Uint8 B)
   {
  return (SDL_MapRGB(surface->format, R, G, B));
   }


void drawText(SDL_Surface* surface, char* string,
            char* fontname, int size, int x, int y,
            Uint32 pixel, int indent)
{
int w, h;
Uint8 fR, fG, fB;
SDL_GetRGB(pixel, surface->format, &fR, &fG, &fB);
TTF_Font* font = TTF_OpenFont(fontname, size);
if(font != NULL)
{
    SDL_Color foregroundColor = { fR, fG, fB };
    TTF_SizeText(font, string, &w, &h);
    SDL_Surface* textSurface = TTF_RenderText_Solid(font, string, foregroundColor);
    if(indent/3 == 0)  y -= h/2;
    else if(indent/3 == 2)  y -= h;

    if(indent%3 == 1) x -= w/2;
    else if(indent%3 == 2) x -= w;
    SDL_Rect textLocation = { x, y, 0, 0 };
    SDL_BlitSurface(textSurface, NULL, surface, &textLocation);
    SDL_FreeSurface(textSurface);
    TTF_CloseFont(font);
}
}

and then calling it like
1
2
3
Uint32 bgcolor = colorRGB(screen, 0, 0, 100); //before game loop

   drawText(screen, text, "Fonts/ka____.TTF", 50, x, 50, colorRGB(screen, 255, 255,       255), CENTER);  //in main loop 


It doesnot show text in the surface, so i move to search if there is any opengl function to do so , i found saw suggestions like sprintf() but it don't work for me(i think sprintf() only print in console) , so how to deal it ? plz help
Topic archived. No new replies allowed.