PDA

View Full Version : Font Display List



M109uk
02-04-2007, 08:58 PM
Hi again,

Im having a few problems with rendering TTF fonts, they display ok on the screen, but they move across the X axis rapidly when ever i call render.

I am probably missing something.. i have checked several sources on the net.

Heres my Font code:


function TXGUITTFFont.BuildFont: Boolean;
var
Font: HFONT;
_hdc: HDC;
begin
_hdc := wglGetCurrentDC;
If GlID > 0 Then glDeleteLists(GlID, 96);
GlID := glGenLists(96);
Font := CreateFont(-24,
0,
0,
0,
FW_BOLD,
0,
0,
0,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE or DEFAULT_PITCH,
'Courier New');
SelectObject(_hdc, Font);
wglUseFontBitmaps(_hdc, 32, 96, GlID);
Result := True;
end;

destructor TXGUITTFFont.Destroy;
begin
If GlID > 0 Then glDeleteLists(GlID, 96);
inherited Destroy;
end;

function TXGUITTFFont.LoadFromFile(const Filename: String): Boolean;
begin
Result := BuildFont;
end;

procedure TXGUITTFFont.Render(const X,Y,Z: Single; const Value: String);
begin
If Value = '' Then Exit;
glPushMatrix;
glTranslatef(X, Y, Z);
glPushAttrib(GL_LIST_BIT);
glListBase(GlID-32);
glCallLists(Length(Value), GL_UNSIGNED_BYTE, PChar(Value));
glPopAttrib;
glPopMatrix;
end;


When i render the object i go through a loop,

Ortho On
glPushMatrix;
Render Controls

glPushMatrix;
Render Cursor
Render sample text (Cursor position)
glPopMatrix;
glPopMatrix;
Ortho Off

I cant see any where whats wrong, i checked if there's an extra Push/Pop matrix but cant find anything.

Any help will be great :)

K4Z
03-04-2007, 12:04 PM
I'm not entirly sure how your problem is ment to look, and I don't use TTFFont in OGL. What do you mean by:

but they move across the X axis rapidly when ever i call render.

Maybe your giving the wrong value for X. Do you reset to the identity when changing to Ortho mode?

M109uk
03-04-2007, 06:41 PM
I'm not entirly sure how your problem is ment to look, and I don't use TTFFont in OGL. What do you mean by:

but they move across the X axis rapidly when ever i call render.


I mean, when the cursor (GUI) is moved over my window (GUI) control, text is supposed to appear under the cursor (much like a hint), however the text appears at the very bottom of the window, and scrolls along the x axis all the way off the screen, very fast.



Maybe your giving the wrong value for X. Do you reset to the identity when changing to Ortho mode?


i have tried to render the text at point 0,0 and i have then tried 100,100 and it doesnt seem to make a difference.

I have tried it with and without glLoadIdentity.
I do call glPushMatrix and glpopMatrix when rendering each control, would this effect it?

It doesnt effect any other controls, just this 1 thing?!

I have uploaded the current release on my site http://www.pulse-soft.oneuk.com/index.php?option=com_vfm&Itemid=44&dir=devilscube|phase7

as the program loads, make sure the cursor is not in the SDL window, once it has loaded, as soon as you move the cursor into any of the forms text will appear at the bottom of the screen, and disapears off to the right of the screen.

Sly
03-04-2007, 09:43 PM
In that case I would look at the code you use to render the mouse cursor. It sounds like it is accumulating the mouse X coordinate each frame and not setting the matrix back to the previous state. The text moving off screen is just a symptom of a problem elsewhere.

M109uk
03-04-2007, 11:46 PM
I cant see any problems, or maybe im going blind.

Im using translatef to position the cursor, heres the code:


glPushMatrix;
glTranslatef(X, Y, 0);

_XGUISkins.RenderElement('xcursor', 'normal');
If fOControl <> Nil Then
Begin
cn &#58;= fOControl.Propertise.GetStr&#40;'@classname', ''&#41;;
w &#58;= Length&#40;cn&#41;;
h &#58;= 14;
glColor4f&#40;0.5, 0.5, 1.0, 1.0&#41;;
glBegin&#40;GL_QUADS&#41;;
glVertex2f&#40;&#40;14/2&#41;, &#40;14/2&#41;&#41;;
glVertex2f&#40;&#40;14/2&#41;, &#40;14/2&#41;+h&#41;;
glVertex2f&#40;&#40;14/2&#41;+w, &#40;14/2&#41;+h&#41;;
glVertex2f&#40;&#40;14/2&#41;+w, &#40;14/2&#41;&#41;;
glEnd;
_XGUIFonts.Items&#91;_XGUIFonts.Count-1&#93;.Render&#40;&#40;14/2&#41;+1, -&#40;&#40;14/2&#41;+1&#41;, cn&#41;;
End;
glPopMatrix;


I have changed from:


_XGUIFonts.Items&#91;_XGUIFonts.Count-1&#93;.Render&#40;&#40;14/2&#41;+1, -&#40;&#40;14/2&#41;+1&#41;, cn&#41;;


To:


glPopMatrix;
_XGUIFonts.Items&#91;_XGUIFonts.Count-1&#93;.Render&#40;0, 0, cn&#41;;


yet the problems still the same?

Andreaz
07-04-2007, 07:44 AM
Note that the raster positions of OpenGL always starts from the bottom-left and not from the top-right as in delphi vcl.

You can however via the perspective calculations flip the coordinates for glVertex and so forth, but not for the raster.

When i found out this i ditched the truetype fonts in OpenGL and went for textured bitmap fonts instead.

M109uk
11-04-2007, 09:46 PM
Ok thanks for your help..
I have given up with GL Fonts, and stuck with BMP fonts.

I was mainly playing with GL Fonts to see what i can do with it, but its not really worth the hassel over a 1meg file.