Results 1 to 4 of 4

Thread: OpenGl & TTF [SOLVED]

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    OpenGl & TTF [SOLVED]

    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/SD...onts_in_OpenGL

    Now that is all well and nice - but I only have a rudimentary grasp of C/C++ 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
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    My translation so far is:

    Code:
    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?
    Last edited by code_glitch; 14-01-2011 at 10:45 PM.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    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
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    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
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •