PDA

View Full Version : OpenGl & TTF [SOLVED]



code_glitch
14-01-2011, 10:16 PM
First off, I am fully aware of the stance to the issue of using Sdl_TTF and OpenGl together. However - it cannot be denied that Sdl is darn good at handling those TTFs although it may sometimes be slow.

Thus, since it is so flexible with fonts I thought I could use it in Prometheus and my programs I wrote in Sdl, were slow and now have used a custom version of my old MMI [MultiMedia Interface] (my pre-prometheus lib) that uses opengl.

The inherent problem is no text: runtime error.

I have looked around extensively and found this: http://wiki.gamedev.net/index.php/SDL_ttf:Tutorials:Fonts_in_OpenGL

Now that is all well and nice - but I only have a rudimentary grasp of C/C++ :D converting it failed - badly. Could anyone please help me out here at all? It would be very much appreciated.

PS: If anyone knows how to embed a resource file into a ppu or something, and then access it at runtime, please post that also. Prometheus needs a system font, this solution would be neater ;)

code_glitch
14-01-2011, 10:25 PM
My translation so far is:



procedure Font.Draw(X,Y: Int64; Txt: String; Clr: Colour);
var
SS: pSdl_Surface;
Tex: Gluint;

begin

New(SS);

SS := TTF_RenderText_Blended(Pointer_, PChar(Txt), Clr.Sdl^);

glGenTextures(1, @Tex);
glBindTexture(GL_TEXTURE_2D, Tex);

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, SS^.w, SS^.h, 0, GL_EXT_BGRA, GL_UNSIGNED_BYTE, SS^.pixels);

glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex3d(X, Y, 0);
glTexCoord2d(1, 0); glVertex3d(X+SS^.w, Y, 0);
glTexCoord2d(1, 1); glVertex3d(X+SS^.w, Y+SS^.h, 0);
glTexCoord2d(0, 1); glVertex3d(X, Y+SS^.h, 0);
glEnd();

glDeleteTextures(1, @Tex);
sdl_freesurface(SS);

end;
And surprise surprise, it does not work...

Edit: one of the reasons behind this is that ttf_openfont does not load anything to the pointer as some extensive testing revealde. Are there any ways to get this to work? I've tried telling it the absolute path, case sensitive and etc but still no luck. has anyone else had this error?

code_glitch
15-01-2011, 11:19 AM
Okay, so I was looking thorugh google, and since sdl_ttf is such a pain I came accross the Freetype library; the question is: does anyone know of a good tutorial that works with pascal or any example code they would be willing to share? It would be very much appreciated.

cheers
code_glitch

code_glitch
15-01-2011, 12:04 PM
Sorry about the useless thread - I managed to fix the font issue: the pointer was being cleaned up too fast after being set to an unset variable! Now that must be the stupidest thing that ever happened.

I will leave this up here in case anyone wants some demo code to use sdl_ttf with opengl or to convert an sdl surface to opengl texture all done for them ;)