Posted Tuesday, 26 May, 2009 - 21:07 by the Fiddler
As long as you don't create a new TextPrinter every frame, it should be quite fast. Can you post some code?
There are many ways to implement your own text printing routines, however:
it's unlikely you'll get better speed, unless you trade off kerning and unicode support
functions like wglUseFontBitmaps are even slower than the TextPrinter
OpenTK does not expose platform-specific methods. You'll have to use .Net routines like DrawString (in which case you'd be better off with TextPrinter) or native libraries like FreeType and FTGL
Posted Tuesday, 26 May, 2009 - 22:05 by the Fiddler
I see, by guess is that the TextPrinter is hitting a bottleneck due to state changes: enabling / disabling texturing, blending, setting up the orthographic projection, etc. You will likely get better performance if you draw all text in one go, inside a single TextPrinter.Begin() - End() block.
This is a use case I hadn't considered in the original design, I will run some tests to see if it can be made faster.
Edit: why are you invalidating the control in the mouse move event? Seems wasteful, considering you receive dozens of MouseMove events whenever you touch your mouse.
Posted Tuesday, 26 May, 2009 - 22:58 by the Fiddler
Ok, I ran a few tests and it seems the Begin() - End() code is not a bottleneck.
I then made a quick optimization pass and tightened up a few costly operations, resulting in a 100% speed improvement on large datasets. That was the low-hanging fruit - there's a lot of optimization potential left, even without adding a VBO renderer.
The latest code is now in SVN, if you wish to test (rev 1798+). Building is easy, just head to the Build/ folder and follow Intsructions.txt.
Edit 2: A quick test using VBOs showed an additional 70% improvement over the immediate mode renderer, with the potential to become even faster (via MapBuffer). The final step is to move text layout caching towards the back of the pipeline, i.e. not cache text measurements (current implementation) but rather cache vertex layouts. This could easily improve performance by an additional 30-50% at the cost of memory.
[!] File does not exist: ../Documentation/Todo.txt
[!] File does not exist: ../Documentation/Release.txt
[!] File does not exist: ../Documentation/Changelog.txt
[!] File does not exist: ../Documentation/License.txt
[!] File does not exist: ./Instructions.txt
[!] Could not resolve Solution path: ../Source/Build
[!] Could not resolve Solution path: ../Source/Bind
[!] Could not resolve Solution path: ../Source/OpenTK
[!] Could not resolve Solution path: ../Source/Utilities
[!] Could not resolve Solution path: ../Source/Examples
Creating Visual C# 2005 solution and project files
Comments
Re: Texture-Mapped Fonts
OpenTK comes with a cross-platform text renderer. Include OpenTK.Utilities.dll to your project and use the
OpenTK.Graphics.TextPrinterclass.Re: Texture-Mapped Fonts
use the
OpenTK.Graphics.TextPrinterclass.Thanks, but it's so slowly works...
Can I solve my problem in another way?
Re: Texture-Mapped Fonts
As long as you don't create a new TextPrinter every frame, it should be quite fast. Can you post some code?
There are many ways to implement your own text printing routines, however:
Re: Texture-Mapped Fonts
It's my test Draw() function:
If I have more then 20-30 objects, It's works slow when I move any object (objects) (see attachment).
Re: Texture-Mapped Fonts
I see, by guess is that the TextPrinter is hitting a bottleneck due to state changes: enabling / disabling texturing, blending, setting up the orthographic projection, etc. You will likely get better performance if you draw all text in one go, inside a single
TextPrinter.Begin() - End()block.This is a use case I hadn't considered in the original design, I will run some tests to see if it can be made faster.
Edit: why are you invalidating the control in the mouse move event? Seems wasteful, considering you receive dozens of MouseMove events whenever you touch your mouse.
Re: Texture-Mapped Fonts
Thanks, Fiddler.
you receive dozens of MouseMove events whenever you touch your mouse.
This is test application and in this way I provide dragging of objects (as a blue-filled rectangle).
You will likely get better performance if you draw all text in one go, inside a single TextPrinter.Begin() - End() block
I can't to do this, because I have a lot of blocks, and I don't know how many times function Draw() will call.
I can optimise a code, but it a little helps, because I use a lot of text.
Re: Texture-Mapped Fonts
Ok, I ran a few tests and it seems the Begin() - End() code is not a bottleneck.
I then made a quick optimization pass and tightened up a few costly operations, resulting in a 100% speed improvement on large datasets. That was the low-hanging fruit - there's a lot of optimization potential left, even without adding a VBO renderer.
The latest code is now in SVN, if you wish to test (rev 1798+). Building is easy, just head to the Build/ folder and follow Intsructions.txt.
Edit: I made a mistake and the changes are only in the gw-next2 branch (https://opentk.svn.sourceforge.net/svnroot/opentk/branches/gw-next2). I will fix that tomorrow, but feel free to checkout that branch if you wish to test (it is stable).
Edit 2: A quick test using VBOs showed an additional 70% improvement over the immediate mode renderer, with the potential to become even faster (via MapBuffer). The final step is to move text layout caching towards the back of the pipeline, i.e. not cache text measurements (current implementation) but rather cache vertex layouts. This could easily improve performance by an additional 30-50% at the cost of memory.
Re: Texture-Mapped Fonts
Thanks, Fiddler.
But I can't execute Build.exe...
Re: Texture-Mapped Fonts
Which OS? Which version of .Net do you have?
Build.exe is a .Net 2.0 application (you'll have to run it through mono if you are on Linux / Mac OS).
Alternative solution: open a command prompt, head to the Build/ folder and type:
Prebuild.exe /target vs2005 /file Prebuild.xmlRe: Texture-Mapped Fonts
I use MS Windows XP SP3, .Net Framework 3.5, MS VS 2005, 2008
I get an empty solution file:
>Prebuild.exe /target vs2005 /file Prebuild.xml
Prebuild.xml
Prebuild v2.0.4
Copyright (c) 2004-2008
Matthew Holmes (matthew@wildfiregames.com),
Dan Moorehead (dan05a@gmail.com),
David Hudson (jendave@yahoo.com),
Rob Loach (http://www.robloach.net),
C.J. Adams-Collier (cjac@colliertech.org),
See 'prebuild /usage' for help
[!] File does not exist: ../Documentation/Todo.txt
[!] File does not exist: ../Documentation/Release.txt
[!] File does not exist: ../Documentation/Changelog.txt
[!] File does not exist: ../Documentation/License.txt
[!] File does not exist: ./Instructions.txt
[!] Could not resolve Solution path: ../Source/Build
[!] Could not resolve Solution path: ../Source/Bind
[!] Could not resolve Solution path: ../Source/OpenTK
[!] Could not resolve Solution path: ../Source/Utilities
[!] Could not resolve Solution path: ../Source/Examples
Creating Visual C# 2005 solution and project files
What can I do?