OpenGL AntiAliasing Text

How can I render smooth text like Mac and Linux does on Windows using OpenGL. I think this will make my program a nice and clean looking system. What are the limitations, such as fonts that I can use, if any? I am looking for a system possibly better than GDI Plus Plus. I do not actually know if there is a GDI Plus Plus libary but it shows the sort of thing I am trying to achieve. If you have never heard of GDIpp, check it out here: https://code.google.com/p/gdipp/

It is a pretty nice system but because of bugs and stuff, I do not recommend it for casual computer use. I do not use it anymore.

Thanks

OpenGL does not natively render text, as far as I can tell. You’d need to convert the outline shapes of the font into forms that OpenGL can recognize, figure out your own text layout engine, etc. It’s probably out of your league, because if it were IN your league, you woudn’t be asking in the first place. :slight_smile:

You can get a smoothing effect on your drawings on Windows if you draw them to a Picture that is twice as large as needed and then scale it down by drawing it at half size to the screen, or to an intermediate picture at half size that is then drawn to the screen at its full size. This will give you some of the smoothing effect you’re looking for, and although it will never be quite as nice as native anti-aliased drawing, it’s good enough for most people.

[quote=44278:@Eric Williams]OpenGL does not natively render text, as far as I can tell. You’d need to convert the outline shapes of the font into forms that OpenGL can recognize, figure out your own text layout engine, etc. It’s probably out of your league, because if it were IN your league, you woudn’t be asking in the first place. :slight_smile:

You can get a smoothing effect on your drawings on Windows if you draw them to a Picture that is twice as large as needed and then scale it down by drawing it at half size to the screen, or to an intermediate picture at half size that is then drawn to the screen at its full size. This will give you some of the smoothing effect you’re looking for, and although it will never be quite as nice as native anti-aliased drawing, it’s good enough for most people.[/quote]
Thanks. You can get in the right league by learning, you know. :wink:

Printing text in OpenGL is not a trivial thing to do.

Here is a nice example project that shows how to print text in OpenGL, with thanks to Prof. Ramon Sastre for providing the code.

How is it you want to use this text? Labels, a custom TextField, image creation…

I have font rendering in my ezgl framework but it only works in a OpenGLSurface. Fonts are textured quads and are initially created from DrawStrings in a Graphics, so whatever aliasing is happening with DrawString will show up here too. You could pre-generate the anti-aliased font data on a mac and use that instead, I haven’t done the pre-gen loading part yet though. Run Window09Font in here if interested http://home.comcast.net/~trochoid/code/ezgl0h.zip (this window should work but most others need a declare update for Windows OS).

Not sure how this compares speed wise or quality wise to scaling down drawstrings as Eric mentioned.

Sorry, I didn’t mean to be condescending - but OpenGL and typography are both extremely complex subjects; the big OS vendors pay highly-educated specialists highly-zeroed salaries to build and maintain the libraries that simplify the complexity down to where your average developer can draw the words “Hello, world” on the screen. While I agree that you could learn it, your effort is likely best spent elsewhere.

With ezgl ‘Hello World’ is pretty easy

[code]//in a window with a glSurfacePlainCanvas

Property: myFont As GLFont

//glSurfacePlainCanvas events…

Sub Open(g As ezgl)
myFont = new GLFont(“Arial”, 30, true, false)
End Sub

Sub Paint(g As ezgl)
myFont.drawString(g, “Hello World”, 20, 20)
End Sub[/code]

Will need to investigate Alwyns code more.

I like the simplicity of your code Will. The code snippets I’ve posted is a bit more lower level rendering.