PDA

View Full Version : Font wglUseFontOutlines Anti-aliasing



WhatJac3
08-08-2010, 10:44 AM
Hello,

I have a problem with anti-aliasing the font that I use in my application. I have seen that more people had that problem but when trying does implementations they don't seem to work for me. When I set my anti-aliasing from my graphics card (ATI control panel) from application managed to 4x the fonts look smooth like they should. But I can't let everyone who uses my application have to change their anti aliasing settings on the graphics card. I know it can be done in the application, but I cant seem to get it work.

Here is my current code:

procedure GLInit();
begin
glClearColor(1.0, 1.0, 1.0, 1.0); // White Background
glDisable(Gl_DEPTH_TEST);
glEnable (GL_POLYGON_SMOOTH);
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
BuildFont;
end;



procedure BuildFont();
var
font:HFont;
begin
fontOffset := glGenLists (256);
font := CreateFont(-cFontHeight, 0, 0, 0, 0, 0, 0, 0,
ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE or DEFAULT_PITCH, cFont);
SelectObject(DC, font);
wglUseFontOutlines(DC, 0, 255, fontOffSet, 0.0, 0.0, WGL_FONT_POLYGONS, @gmf);
end;

And my pixel format:

procedure GLFormCreate(AHandle: HWND);
var pfd : TPIXELFORMATDESCRIPTOR;
pf : Integer;
begin
dc:=GetDC(AHandle);

// PixelFormat
pfd.nSize:=sizeof(pfd);
pfd.nVersion:=1;
pfd.dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
pfd.iPixelType:=PFD_TYPE_RGBA;
pfd.cColorBits:=24;

pf :=ChoosePixelFormat(dc, @pfd);
SetPixelFormat(dc, pf, @pfd);

rc :=wglCreateContext(dc);
wglMakeCurrent(dc,rc);

// Initialist GL environment variables
glInit;
GLResize(); // sets up the perspective
end;

If I change everything to GL_Line, so:

WGL_FONT_POLYGONS = WGL_FONT_LINES
GL_POLYGON_SMOOTH = GL_LINE_SMOOTH
GL_POLYGON_SMOOTH_HINT = GL_LINE_SMOOTH_HINT

I get nice smooth fonts, but only the outlines of the fonts. They are not filled. Anyone has any idea what I am doing wrong?

VilleK
08-08-2010, 04:26 PM
The kind of antialiasing that you set in the GPU control panel is actually called "multisample" and requires quite a bit of code to initialize yourself.

See this NeHe-tutorial:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=46

WhatJac3
08-08-2010, 05:24 PM
Thanks for your reply. I have downloaded the example and had to change one thing (added the red part):

wglGetExtString: function(hdc: HDC): PAnsiChar; stdcall;


Now when I go debugging wglChoosePixelFormatARB returns false both times (bit either 4 and 2). My videocard (ATI control panel) gives me 8x, 4x and 2x anti-aliasing options. So I can't believe that OpenGL tells me it is not supported. Anyone has any idea what is wrong here?

If I open the OpenGL Extension Viewer it tells met that WGL_ARB_Multisample is a correct extension.

If I list the pixel formats it tell me for instance that pixel format 30 has:
WGL_DOUBLE_BUFFER_ARB = TRUE
WG_ACCELERATION_ARB = TRUE
WGL_PIXEL_TYPE_ARB = 0
WGL_SAMPLES_ARB = 8

Any idea why it doesn't work? Even if I use the options from a correct pixelformat (nr 14 accoring to OpenGL Extensions Viewer), I still get a false as return value.

WhatJac3
08-08-2010, 08:02 PM
Or does anyone know how to list all pixelformats? If I choose one myself from OpenGL Extensions Viewer with Anti-aliasing, it works perfect. So if I could list all options I would be able to pick the most appropriate, since the example from NeHe does not work.

User137
08-08-2010, 09:07 PM
Did you purposefully disable anti-aliasing from graphics card settings or are they set on "application-control"? Those settings can lock anything from using it... ofc depends on manufacturer etc.

WhatJac3
08-08-2010, 09:09 PM
It is set on application-control.

I am now iterating through the pixelformats with:

K := DescribePixelFormat(dc, 1, L , pfd);
while K do
begin
K := DescribePixelFormat(dc, J, L , pfd);
J := J + 1;
end;

Now I only need to find a way to check the value of WGL_SAMPLES_ARB from pfd to find the best possible pixelformat.

WhatJac3
08-08-2010, 10:29 PM
I fixed the NeHe example. It has one problem. This is what should be done.

In ARB_multisample add:

type
TGLLongArray = array[0..21] of GLInt;
PGLLongArray = ^TGLLongArray;

change wglChoosePixelFormatARB into:

wglChoosePixelFormatARB: function(hdc: HDC; piAttribIList: PGLLongArray; pfAttribFList: PGLfloat; nMaxFormats: GLuint; piFormats: PGLint; nNumFormats: PGLuint): BOOL; stdcall;

Add after the iAttributes[21] := 0;


tmp := @iAttributes;


Change valid := wglChoosePixelFormatARB into


valid := wglChoosePixelFormatARB(h_dc,tmp,@fattributes,1,@p ixelFormat,@numFormats);


Now the example works. Enjoy!