www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Has Tomasz's (h3r3tic's) OpenGL font rendering code been ported to

reply Chad J <chadjoan __spam.is.bad__gmail.com> writes:
I've been looking for a good way to render font in OpenGL with D.

Back in they day I was very impressed with Tomasz's article on the 
subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
I was wonder if anyone has ported it.
Mar 10 2012
next sibling parent reply bioinfornatics <bioinfornatics fedoraproject.org> writes:
Le samedi 10 mars 2012 =C3=A0 21:23 -0500, Chad J a =C3=A9crit :
 I've been looking for a good way to render font in OpenGL with D.
=20
 Back in they day I was very impressed with Tomasz's article on the=20
 subject: http://h3.gd/dmedia/?n=3DTutorials.TextRendering1
 I was wonder if anyone has ported it.

take derelict2 http://www.dsource.org/projects/derelict [stable] derelict3 in development https://github.com/aldacron/Derelict3
Mar 10 2012
next sibling parent reply Chad J <chadjoan __spam.is.bad__gmail.com> writes:
On 03/10/2012 10:29 PM, bioinfornatics wrote:
 Le samedi 10 mars 2012 à 21:23 -0500, Chad J a écrit :
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

take derelict2 http://www.dsource.org/projects/derelict [stable] derelict3 in development https://github.com/aldacron/Derelict3

I already have OpenGL working with derelict2. How do these links help with rendering text in OpenGL?
Mar 10 2012
parent Chad J <chadjoan __spam.is.bad__gmail.com> writes:
On 03/11/2012 04:24 AM, Kiith-Sa wrote:
 On Sunday, 11 March 2012 at 03:45:36 UTC, Chad J wrote:
 On 03/10/2012 10:29 PM, bioinfornatics wrote:
 Le samedi 10 mars 2012 à 21:23 -0500, Chad J a écrit :
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

take derelict2 http://www.dsource.org/projects/derelict [stable] derelict3 in development https://github.com/aldacron/Derelict3

I already have OpenGL working with derelict2. How do these links help with rendering text in OpenGL?

I have some code based on that tutorial in https://github.com/kiith-sa/ICE, but beware that it's not the most effective code and not particularly readable either. However, I abstracted it away it to pack any textures instead of just font glyphs, and it is spread over many files. The relevant files are: video/glvideodriver.d video/texturepage.d video/gltexturebackend.d video/binarytexturepacker.d video/font.d video/fontmanager.d Works with DMD 2.058, but it'd probably be nontrivial to rip it out and use separately.

Thanks for the link! I don't have time to go over it right now, but that looks promising. I took a shot at porting Tomasz's code a while ago, but I never got it to compile. At least your code /compiles/, so even if it's integrated into other stuff, at least I might stand a better chance. Btw, also a fan of Raptor and Tyrian. Good taste dude. ;)
Mar 11 2012
prev sibling next sibling parent "Kiith-Sa" <42 theanswer.com> writes:
On Sunday, 11 March 2012 at 03:45:36 UTC, Chad J wrote:
 On 03/10/2012 10:29 PM, bioinfornatics wrote:
 Le samedi 10 mars 2012 à 21:23 -0500, Chad J a écrit :
 I've been looking for a good way to render font in OpenGL 
 with D.

 Back in they day I was very impressed with Tomasz's article 
 on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

take derelict2 http://www.dsource.org/projects/derelict [stable] derelict3 in development https://github.com/aldacron/Derelict3

I already have OpenGL working with derelict2. How do these links help with rendering text in OpenGL?

I have some code based on that tutorial in https://github.com/kiith-sa/ICE, but beware that it's not the most effective code and not particularly readable either. However, I abstracted it away it to pack any textures instead of just font glyphs, and it is spread over many files. The relevant files are: video/glvideodriver.d video/texturepage.d video/gltexturebackend.d video/binarytexturepacker.d video/font.d video/fontmanager.d Works with DMD 2.058, but it'd probably be nontrivial to rip it out and use separately.
Mar 11 2012
prev sibling parent "Kiith-Sa" <42 theanswer.com> writes:
On Sunday, 11 March 2012 at 22:39:46 UTC, Chad J wrote:
 On 03/11/2012 04:24 AM, Kiith-Sa wrote:

 Thanks for the link!

 I don't have time to go over it right now, but that looks 
 promising.  I took a shot at porting Tomasz's code a while ago, 
 but I never got it to compile.  At least your code /compiles/, 
 so even if it's integrated into other stuff, at least I might 
 stand a better chance.

 Btw, also a fan of Raptor and Tyrian.  Good taste dude.  ;)

I just remembered I also wrote a tool for this as a project at university (in Java, because I had to) last year: http://gitorious.org/fmapper It spits out a texture or a set of textures with tightly packed glyphs of specified font with specified parameters, and a text file containing offsets and texture coords of glyphs. There is an example C++/OpenGL program on how to load the textures and draw fonts. Only supports the basic multilingual plane, though. If you're only using a fixed number of font sizes, you can generate textures for them with this. It's not as flexible, but probably easier than writing your own code based on FreeType. Note that it's not maintained - I hate Java - but it should work.
Mar 12 2012
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-03-11 03:23, Chad J wrote:
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

Just use FreeType? -- /Jacob Carlborg
Mar 11 2012
parent reply Chad J <chadjoan __spam.is.bad__gmail.com> writes:
On 03/11/2012 09:09 AM, Jacob Carlborg wrote:
 On 2012-03-11 03:23, Chad J wrote:
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

Just use FreeType?

FreeType is quite cool, but it will only render glyphs onto small bitmaps. Getting those glyphs onto the screen becomes more complicated after that: you can't just blit them like in SDL or somesuch. Since textures don't come in "supersmall" size, it is effective to pack the glyphs into a larger texture like the article suggests. Then you have to texture-map correctly to only render the glyphs you want. Somewhere in there is a bunch of other font-setting stuff like kerning, sub-pixel anti-aliasing, line offsets, etc. FreeType doesn't do that stuff for anyone, it just provides the tools necessary to make it possible. It's fairly complicated; I'd rather just write "Font f = new Font("Courier New"); f.draw(100, 100, "Hello world!");".
Mar 11 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-03-11 14:18, Chad J wrote:
 On 03/11/2012 09:09 AM, Jacob Carlborg wrote:
 On 2012-03-11 03:23, Chad J wrote:
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

Just use FreeType?

FreeType is quite cool, but it will only render glyphs onto small bitmaps. Getting those glyphs onto the screen becomes more complicated after that: you can't just blit them like in SDL or somesuch. Since textures don't come in "supersmall" size, it is effective to pack the glyphs into a larger texture like the article suggests. Then you have to texture-map correctly to only render the glyphs you want. Somewhere in there is a bunch of other font-setting stuff like kerning, sub-pixel anti-aliasing, line offsets, etc. FreeType doesn't do that stuff for anyone, it just provides the tools necessary to make it possible. It's fairly complicated; I'd rather just write "Font f = new Font("Courier New"); f.draw(100, 100, "Hello world!");".

So you mean putting a texture on a font? -- /Jacob Carlborg
Mar 11 2012
parent reply Chad J <chadjoan __spam.is.bad__gmail.com> writes:
On 03/11/2012 05:04 PM, Jacob Carlborg wrote:
 On 2012-03-11 14:18, Chad J wrote:
 On 03/11/2012 09:09 AM, Jacob Carlborg wrote:
 On 2012-03-11 03:23, Chad J wrote:
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

Just use FreeType?

FreeType is quite cool, but it will only render glyphs onto small bitmaps. Getting those glyphs onto the screen becomes more complicated after that: you can't just blit them like in SDL or somesuch. Since textures don't come in "supersmall" size, it is effective to pack the glyphs into a larger texture like the article suggests. Then you have to texture-map correctly to only render the glyphs you want. Somewhere in there is a bunch of other font-setting stuff like kerning, sub-pixel anti-aliasing, line offsets, etc. FreeType doesn't do that stuff for anyone, it just provides the tools necessary to make it possible. It's fairly complicated; I'd rather just write "Font f = new Font("Courier New"); f.draw(100, 100, "Hello world!");".

So you mean putting a texture on a font?

No, just getting the font onto the screen at all. And I want to: - Be able to size the font smoothly. (No bitmap fonts!) - Draw glyphs for higher unicode codepoints. (No texture[128]!) - Have kerning/hinting. (Freetype makes it possible, but does not do it for you.) - Have anti-aliasing and maybe even subpixel accuracy. Tomasz's code does all of this. Freetype is very low-level. Freetype does not make OpenGL calls. You give it a font and a codepoint and it gives you a small grayscale bitmap and a slew of metrics for it. Then it's up to you to figure out where to put it and how to get it onto the screen. If this were trivial, Tomasz (and others who have written on the topic, too) would not have written 5-10 pages of text plus a bunch of D files full of code. It's just not that easy. It's all in the original link. It's actually really weird that there isn't much library code out there to render text in OpenGL. There are a bunch of tutorials that do it wrong and maybe a few library thingies that I can't use for various reasons.
Mar 11 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-03-11 23:36, Chad J wrote:

 No, just getting the font onto the screen at all.

 And I want to:
 - Be able to size the font smoothly. (No bitmap fonts!)
 - Draw glyphs for higher unicode codepoints. (No texture[128]!)
 - Have kerning/hinting. (Freetype makes it possible, but does not do it
 for you.)
 - Have anti-aliasing and maybe even subpixel accuracy.

 Tomasz's code does all of this.

 Freetype is very low-level. Freetype does not make OpenGL calls. You
 give it a font and a codepoint and it gives you a small grayscale bitmap
 and a slew of metrics for it. Then it's up to you to figure out where to
 put it and how to get it onto the screen.

 If this were trivial, Tomasz (and others who have written on the topic,
 too) would not have written 5-10 pages of text plus a bunch of D files
 full of code. It's just not that easy. It's all in the original link.

 It's actually really weird that there isn't much library code out there
 to render text in OpenGL. There are a bunch of tutorials that do it
 wrong and maybe a few library thingies that I can't use for various
 reasons.

I did some font rendering in C# using FreeType and OpenGL for a simple game. I can't remembering it being that hard. -- /Jacob Carlborg
Mar 12 2012
parent reply FeepingCreature <default_357-line yahoo.de> writes:
On 03/12/12 10:42, Jacob Carlborg wrote:
 On 2012-03-11 23:36, Chad J wrote:
 I did some font rendering in C# using FreeType and OpenGL for a simple game. I
can't remembering it being that hard.
 

Mar 14 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-03-14 09:03, FeepingCreature wrote:
 On 03/12/12 10:42, Jacob Carlborg wrote:
 On 2012-03-11 23:36, Chad J wrote:
 I did some font rendering in C# using FreeType and OpenGL for a simple game. I
can't remembering it being that hard.


I know it's a C library. As far as I know it was as similar to the C library as C# allows. I used guides and documentation written for the C library. -- /Jacob Carlborg
Mar 14 2012
prev sibling parent reply "David Nadlinger" <see klickverbot.at> writes:
On Sunday, 11 March 2012 at 02:24:15 UTC, Chad J wrote:
 I've been looking for a good way to render font in OpenGL with 
 D.

 Back in they day I was very impressed with Tomasz's article on 
 the subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

If I were to implement a texture rendering system for 3D graphics, I'd look into signed distance field fonts, as presented in Valve's seminal paper [1]. David [1] http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf
Mar 11 2012
parent Chad J <chadjoan __spam.is.bad__gmail.com> writes:
On 03/11/2012 05:10 PM, David Nadlinger wrote:
 On Sunday, 11 March 2012 at 02:24:15 UTC, Chad J wrote:
 I've been looking for a good way to render font in OpenGL with D.

 Back in they day I was very impressed with Tomasz's article on the
 subject: http://h3.gd/dmedia/?n=Tutorials.TextRendering1
 I was wonder if anyone has ported it.

If I were to implement a texture rendering system for 3D graphics, I'd look into signed distance field fonts, as presented in Valve's seminal paper [1]. David [1] http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf

Sounds interesting. Thanks!
Mar 11 2012