Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: glx.pas for JEDI_SDL

  1. #1

    glx.pas for JEDI_SDL

    There is an error in function InitGLXFromLibrary. The if statement should be
    Code:
    if not LoadModule( libGLX, dll ) then exit;
    not
    Code:
     if LoadModule( libGLX, dll ) then exit;
    In present form it loads library and exits witout initialising glx functions.

  2. #2

    glx.pas for JEDI_SDL

    Thanks for pointing it out. I'll try and commit the change to CVS this evening.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3

    glx.pas for JEDI_SDL

    I've never used glx; the X-Windows library gives me the shakes. I've had a go at gtkglext, though. Looks pretty cool, but I think I'll stick with JEDI-SDL while it's still cooking.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  4. #4

    glx.pas for JEDI_SDL

    The fix is now part of CVS. Thanks again.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  5. #5

    glx.pas for JEDI_SDL

    Quote Originally Posted by cragwolf
    I've never used glx; the X-Windows library gives me the shakes. I've had a go at gtkglext, though. Looks pretty cool, but I think I'll stick with JEDI-SDL while it's still cooking.
    I only need glxUseXFont to create fonts in my app. And yes, xlib programing
    is even more dificult than Win API

  6. #6

    glx.pas for JEDI_SDL

    Quote Originally Posted by grudzio
    I only need glxUseXFont to create fonts in my app.
    Have you tried sdl_ttf? I suppose that's another possibility. I just use premade font textures; it's simple but not as flexible.

    And yes, xlib programing is even more dificult than Win API
    Heheh, WinAPI is a distant memory for me having used Linux for the past few years.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  7. #7

    glx.pas for JEDI_SDL

    The problem with textured font is that you need a texture . I could not find any font generating utility for linux and was too lazy to make my own.
    As for SDL_TTF, I dont like the idea of generating new openGL texture each time I want to print something an the screen. So I am stuck with glxUseFont.

  8. #8

    glx.pas for JEDI_SDL

    Quote Originally Posted by grudzio
    The problem with textured font is that you need a texture . I could not find any font generating utility for linux and was too lazy to make my own.
    Yes, I created my fonts in the GIMP, and used a monospace font to be sure of the spacing. It was very tedious.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  9. #9

    glx.pas for JEDI_SDL

    Creating the font texture on-the-fly is easy if you have some kind of surface to draw the fonts in the system to, like TBitMap.

    Here's some old code of mine, should be easy to port to Lazarus:

    [pascal]
    {$R-}
    unit J3D_Text;

    interface

    uses Windows, OpenGL, Graphics;

    type
    ThTexture = array [0..0] of Byte;
    TTexture = ^ThTexture;

    TTextureFont = record
    S1, T1, S2, T2: Single;
    Width, Height: Integer;
    end;

    var
    TextureFont: array [' ' .. '~'] of TTextureFont;
    TextureID: Longword;
    TextureSize: Longword;
    FontTexture: TTexture; // Texture


    procedure Text_LoadFont(Fontname: String; Size: Integer; Color: TColor);

    implementation

    procedure Text_LoadFont(Fontname: String; Size: Integer; Color: TColor);

    const
    z: Integer = 0;
    var
    BitMap: TBitMap;
    x: Integer;
    y: Integer;
    y2: Integer;
    z2: Integer;
    Delphi_Color: TColor;
    Font: TFont;

    FontHeight: Integer;
    r: TRect;
    CharWidths: array [0..255] of Integer;
    CharHeights: array [0..255] of Integer;
    FontWidth: Integer;
    Step: Single;
    Chr: Char;
    begin
    // Create and load bitmap
    BitMap := TBitMap.Create;
    //BitMap.LoadFromFile(FileName);
    BitMap.PixelFormat := pf24bit;

    BitMap.Width := 256;
    BitMap.Height := 256;

    r.Left := 0;
    r.Right := 256;
    r.Top := 0;
    r.Bottom := 256;

    BitMap.Canvas.Brush.Color := clBlack;
    BitMap.Canvas.Brush.Style := bsSolid;
    BitMap.Canvas.Pen.Color := clBlack;
    BitMap.Canvas.FillRect(r);
    BitMap.Canvas.Font.Name := Fontname; // Arial
    BitMap.Canvas.Font.Size := Size; // 18
    BitMap.Canvas.Font.Color := Color; //clWhite
    BitMap.Canvas.Font.Style := [];
    FontWidth := BitMap.Canvas.Font.Size - 4;
    FontHeight := Round(BitMap.Canvas.Font.Size * BitMap.Canvas.Font.PixelsPerInch / 72);

    for x := 0 to 255 do
    CharWidths[x] := BitMap.Canvas.TextWidth(Char(x));

    FontHeight := 0;
    for x := 0 to 255 do
    begin
    CharHeights[x] := BitMap.Canvas.TextHeight(Char(x));
    if BitMap.Canvas.TextHeight(Char(x)) > FontHeight then
    FontHeight := BitMap.Canvas.TextHeight(Char(x));
    end;

    Step := 1 / 256;

    x := 0;
    y := 255 - FontHeight;
    y2 := 0;
    for z2 := 32 to 126 do
    begin
    Chr := Char(z);
    FontWidth := CharWidths[z2];
    //FontHeight := CharHeights[z];
    if (x + FontWidth) > 255 then
    begin
    x := 0;
    y := y - FontHeight;
    //y := y + FontHeight;
    y2 := y2 + FontHeight;
    end;

    TextureFont[Char(z2)].S1 := x * Step;
    TextureFont[Char(z2)].T1 := y2 * Step;
    TextureFont[Char(z2)].Width := FontWidth-1;
    TextureFont[Char(z2)].S2 := (x + FontWidth-1) * Step;
    TextureFont[Char(z2)].T2 := (y2 + CharHeights[z2]) * Step;
    TextureFont[Char(z2)].Height := CharHeights[z2];
    BitMap.Canvas.TextOut(x, y, Char(z2));
    x := x + FontWidth;
    end;

    // Create and set size of texture
    TextureSize := BitMap.Width * BitMap.Height;

    GetMem(FontTexture, TextureSize * 3);

    //BitMap.SaveToFile('c:\temp\font.bmp');

    // Position in texture
    z := 0;
    for y := BitMap.Height - 1 downto 0 do
    begin
    for x := 0 to BitMap.Width - 1 do
    begin
    // Converts Delphi Color value to RGB values, no Alpha
    Delphi_Color := BitMap.Canvas.Pixels[x, y];
    FontTexture[z] := Lo(LoWord(Delphi_Color));
    Inc(z);
    FontTexture[z] := Hi(LoWord(Delphi_Color));
    Inc(z);
    FontTexture[z] := Lo(HiWord(Delphi_Color));
    Inc(z);
    end;
    end;
    // glGenTextures(1, TextureID);
    TextureID := 100;
    glBindTexture(GL_TEXTURE_2D, TextureID);

    // Used texture format is size = 256x256, format = 3 (RGB) and type unsigned byte
    glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, FontTexture);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    BitMap.Free;
    end;

    initialization

    finalization
    if FontTexture <> NIL then
    FreeMem(FontTexture, TextureSize * 3);

    end.
    [/pascal]
    If you develop an idiot proof system, the nature develops better idiots.

  10. #10

    glx.pas for JEDI_SDL

    Thanks for the code. That's a nice solution for users of the Delphi VCL or the Lazarus LCL.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

Page 1 of 2 12 LastLast

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
  •