|
Post by ATC on Oct 14, 2012 20:00:55 GMT -6
I was thinking about this today because DirectX11 provides no native way to draw fonts/text... I was wondering if it would be possible to create a GDI+ font engine which you could feed an input file (e.g., an XML file like a SpriteFont file XNA) that has a font family/name, size, style, etc... Then the font engine would render every character to a bunch of little bitmaps. Then the pixel data of those bitmaps could be used to create D3D Texture2D resource instances... Then (lol, I know) the Texture2D versions of the the characters could basically be used as little glyphs to assemble strings of text from sprites. It could even be done in a geometry shader.
Anyone know anything about this or think it would be good/bad?
|
|
|
Post by Bolkonsky on Oct 14, 2012 21:12:49 GMT -6
I think some games draw the vertices directly instead of using bitmaps. The data is stored in an XML file and accessed when the game goes to draw the font. Take for instance Mount&Blade. It's very easy to convert a .ttf file to a readable format. If you want to take a look at the file, check this out (warning, it's a decent sized file, I recommend saving as and using Notepad++ or something similar to view it): www.igmod.net/font_data.xmlSomeone figured out how to make a tool to auto-gen the font. I'm pretty good friends with the guy so I could probably get him to shed a bit more light on the process. Here's his work: forums.taleworlds.com/index.php/topic,67315.0.html Anyways that fonts_data file just looks like coordinates that they're using to draw directly.
|
|
|
Post by ATC on Oct 14, 2012 21:25:08 GMT -6
Thanks! Very interesting stuff!
I will give it a good look-over tomorrow. Right now I'm working on the engine's new effect/shading engine (essentially a more robust/complete and powerful replace for the Microsoft DirectX Effects Framework) and I'm in the night-time "home stretch" (where I code like mad to finish as much as I can before sleep lol).
The idea behind using GDI+ to create pre-processed glyphs is that it's extremely simple and it seems like it would be fast... the GDI+ code only has to run once when the engine's content processor fires up at load-time, and it spits out a bunch of glyphs... Then a super fast geometry shader could render text by just accepting a buffer of points (Vector2 positions). It would essentially be GPU-accelerated text! lol.
However, it's a Windows-only solution. So it won't be able to cover all bases of the engine. I just think it would be a quick, easy (and hopefully fairly clean) solution for Windows-only games. That being said, something like your buddy's solution is ultimately needed for the engine as we need something both platform and API agnostic...
P.S. -- Did you check out the SlimDX "Game" class tutorial yet? Your criticisms/praises would be greatly appreciated! Especially if you were to try it out! :-)
|
|
|
Post by Bolkonsky on Oct 14, 2012 22:25:12 GMT -6
Thanks! Very interesting stuff! I will give it a good look-over tomorrow. Right now I'm working on the engine's new effect/shading engine (essentially a more robust/complete and powerful replace for the Microsoft DirectX Effects Framework) and I'm in the night-time "home stretch" (where I code like mad to finish as much as I can before sleep lol). The idea behind using GDI+ to create pre-processed glyphs is that it's extremely simple and it seems like it would be fast... the GDI+ code only has to run once when the engine's content processor fires up at load-time, and it spits out a bunch of glyphs... Then a super fast geometry shader could render text by just accepting a buffer of points (Vector2 positions). It would essentially be GPU-accelerated text! lol. However, it's a Windows-only solution. So it won't be able to cover all bases of the engine. I just think it would be a quick, easy (and hopefully fairly clean) solution for Windows-only games. That being said, something like your buddy's solution is ultimately needed for the engine as we need something both platform and API agnostic... P.S. -- Did you check out the SlimDX "Game" class tutorial yet? Your criticisms/praises would be greatly appreciated! Especially if you were to try it out! :-) The more I think about it, the more I'm convinced that can't just be the case though because there has to be some kind of image support since the font boldness would be very complicated to do with vectors...I dunno, it's past midnight, I need sleep. If you want this to be completely platform agnostic, you might have to write your own library. Oh, and I'll try and check out the SlimDX either tomorrow or Tuesday, right now I'm working on compressing resources to get the load times and fragmentation down in a mod I'm working on...and then I have to set up SVN. Just tedious time consuming stuff.
|
|
|
Post by ATC on Oct 15, 2012 17:39:29 GMT -6
Well yes, I am talking about writing a new library. It would just accept a Font argument... font name/family, size, style, etc... and then render all the necessary characters to scaled System.Drawing.Bitmap instances. We can then read the pixel data out of those bitmaps and create DirectX Texture2D interfaces. And then, of course, those can put on the screen in numerous ways. A simple approach would be to use point sprites. An even better way, I think, would be using the geometry shader stage to generate vertices and map each glyph texture onto it. Voila, we have text! :-)
Hopefully that clarifies what I was talking about. The method of using point/curve data to render text is a lot more complicated and, yes, it doesn't natively support bold/italics, kerning, etc. Doing all of that without using the GDI+ "hack" I'm talking about is not a trivial thing at all. A good font engine can be hideously complex. Sooner or later we will have to bite the bullet and develop one though.
|
|