font size problems with wglUseFontOutlines

hello, I've been having some really frustrating problems while trying to get pretty fonts working. I've been trying to use wglUseFontOutlines (I've checked out and built the latest version of Tao from svn, I am not sure if it was in 2.0.0 but I think not. I thought I checked right before I downloaded the source, but in retrospect I didn't).

Basically, the problem comes down to not being able to adjust the font size. its stuck at 'really really ridiculously small.' For example the string "testing"'s length is about 2.3 (when the spacing information from each glyph is added together), regardless whether I set the font size to 10 or 150. First I thought it was a problem when I was calling myFont.ToHFont() to get a handle to the font, so I switched to the Gdi.CreateFont() method for getting a pointer to a valid font object. no change. I even tried specifying CreateFont myself (using DLLImports), but no change. (by no change, I mean all of these methods displayed text on screen, but not at any good size. a couple word sentince comes out as maybe a 5 pixel line when glOrtho is called to set 1 unit in opengl space to 1 pixel. when you zoom in 20-100 times the font is clearly visible.)

Then, I thought perhaps the problem was with selecting the font object as part of the opengl context. so i made a picturebox (to obtain a private offscreen context) and used its handle to obtain a context, and no change at all.

I'm basically at a loss, I'm not sure whats going on. Any help would be appreciated Smiling The class is below, its constructor is called with a font (that has size, style, a face, etc), and then you call DrawText with a point and what to draw. it does put it there (to reiterate), just at an unreadably small constant size.


public class NewFont3D
{
//Public members
private int list_base;
Font ourFont;

Gdi.GLYPHMETRICSFLOAT[] gmf = new Gdi.GLYPHMETRICSFLOAT[256];

public NewFont3D( Font newFont )
{
ourFont = newFont;

System.Windows.Forms.PictureBox offscreen = new System.Windows.Forms.PictureBox();

offscreen.Size = new Size(300, 300);

IntPtr hDC = User.GetDC(offscreen.Handle);

IntPtr hFont = newFont.ToHfont();

/* creates a font, but always draws the same size, as the .ToHfont() method does.
IntPtr hFont = Gdi.CreateFont(120, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
Gdi.FW_BOLD, // Font Weight
false, // Italic
false, // Underline
false, // Strikeout
Gdi.ANSI_CHARSET, // Character Set Identifier
Gdi.OUT_TT_PRECIS, // Output Precision
Gdi.CLIP_DEFAULT_PRECIS, // Clipping Precision
Gdi.ANTIALIASED_QUALITY, // Output Quality
Gdi.FF_DONTCARE | Gdi.DEFAULT_PITCH,// Family And Pitch
"Comic Sans MS");
*/

Gdi.SelectObject(hDC, hFont);

list_base = Gl.glGenLists(256);

Wgl.wglUseFontOutlines(hDC, // Select The Current DC
0, // Starting Character
255, // Number Of Display Lists To Build
list_base, // Starting Display Lists
0.0f, // Deviation From The True Outlines
0.2f, // Font Thickness In The Z Direction
Wgl.WGL_FONT_POLYGONS, // Use Polygons, Not Lines
gmf); // Address Of Buffer To Recieve Data

}

public bool SameFont(Font anotherFont)
{
if (ourFont.SizeInPoints == anotherFont.SizeInPoints &&
ourFont.Name == anotherFont.Name &&
ourFont.Style == anotherFont.Style)
return true;

return false;
}

public void Dispose()
{
Gl.glDeleteLists(list_base, 255);
}

public float extent( string what )
{
float length = 0;

for (int loop=0; loop

well, I am not completely

well, I am not completely satisfied, but I did come up with a work around. right before calling glCallLists() with the string, I add a glScaled call, and afterwards I reset glFrontFace to GL_CCW (apparently WGL does things clockwise).

heres the code:

...

Gl.glScaled(2 * ourFont.SizeInPoints, 2 * ourFont.SizeInPoints, 0);

Gl.glCallLists(what.Length, Gl.GL_UNSIGNED_BYTE, textbytes); // Draws The Display List Text

Gl.glPopAttrib();

Gl.glFrontFace(Gl.GL_CCW);
...

maybe this can help someone else...

Hmm, I recently rewrote the

Hmm, I recently rewrote the wgl bindings with the Tao.GlBindGen, but I had to add wglUseFontOutlines by hand (it was missing from the specs). It is very possible that I made a mistake with its parameters!

As I don't have the slightest clue how the wgl font functions work, is there some way to test whether the requested parameters were set correctly? Or maybe it possible to test your code with Tao 2.0.0 and see if it works as it should then?

------
OpenTK

Sorry if I'm resurrecting a

Sorry if I'm resurrecting a dead thread, but I was just trying to figure out how to do 3D text in C# with Tao, and discovered this thread.

I believe the size issue is just how wglUseFontOutlines works. The project I'm working on is a new, improved version of MATLIGHT (the Materials and Lighting Studio demo program from older editions of the OpenGL SuperBible) (this is for school), and I noticed in the original source that they are scaling the font by a factor of 30 in x, y, and z to make it a reasonable size.

I tried copying the code from this thread (and modifying it a bit), but I can't seem to get anything to draw. Any idea what I'm doing wrong here (I'm using VS2005 with Tao 1.3):

class Font3D
{
private int listBase;
private Font ourFont;
private Gdi.GLYPHMETRICSFLOAT[] gmf = new Gdi.GLYPHMETRICSFLOAT[256];

public Font3D() : this(new Font("Arial", 10, FontStyle.Bold))
{
}

public Font3D(Font newFont)
{
ourFont = newFont;
System.Windows.Forms.PictureBox offscreen = new System.Windows.Forms.PictureBox();
offscreen.Size = new Size(300, 300);
IntPtr hDC = User.GetDC(offscreen.Handle);
IntPtr hFont = newFont.ToHfont();
Gdi.SelectObject(hDC, hFont);
listBase = Gl.glGenLists(256);
Wgl.wglUseFontOutlines(hDC, // Select The Current DC
0, // Starting Character
255, // Number Of Display Lists To Build
listBase, // Starting Display Lists
0.0f, // Deviation From The True Outlines
0.2f, // Font Thickness In The Z Direction
Wgl.WGL_FONT_POLYGONS, // Use Polygons, Not Lines
gmf); // Address Of Buffer To Recieve Data
Gdi.DeleteObject(hFont);
}

public void DrawText(string text)
{
Gl.glPushMatrix();
Gl.glScaled(2 * ourFont.SizeInPoints, 2 * ourFont.SizeInPoints, 2 * ourFont.SizeInPoints);
Gl.glListBase(listBase);
Gl.glFrontFace(Gl.GL_CW);
Gl.glCallLists(text.Length, Gl.GL_UNSIGNED_BYTE, text); // Draws The Display List Text
Gl.glListBase(0);
Gl.glPopMatrix();
Gl.glFrontFace(Gl.GL_CCW);
}
}

Theme by La Boite a site | Powered by Drupal