
Rendering 2D Labels on 3D Objects
Posted Monday, 9 January, 2012 - 12:44 by ZioN inHi I am new to OpenTK, love the fact I can program with OpenGL in C#, two of my most favorite things :)
I have been giving a job at work to represent the data in our database, (with is a structure) in 3D.
I have search various places, come close with this thread here
But I am using OpenTK 1.0 2010-10-06, and the TextPrinter class seems to be missing.
I would like to know how to print a label (witch is text), and put in on a 3D Object, and as the camera moves around, the labels need to stay with the objects.
Using windows XP, Microsoft Visual Studio 2008, C# .Net, and the GameWindow class.


Comments
Re: Rendering 2D Labels on 3D Objects
The TextPrinter is part of OpenTK.Compatibility. Replace your project's OpenTK reference with a OpenTK.Compatibility reference.
Re: Rendering 2D Labels on 3D Objects
Thanks I have found the TextPrinter class now! But I see there are a few more differences between the OpenTK and OpenTK.Compatibility references.
I am using GameWindow, and I see the GameWindow class does not exist with the OpenTK.Compatibility, or did I forget to include some 'using'.
All I did was take out my reference to the OpenTK and added the OpenTK.Compatibility reference.
Also here are some few of the error messages I got:
If you want to have a look at my coding here it is:
Program.CS
Objects.CS
Re: Rendering 2D Labels on 3D Objects
for the Vector3, you need to use OpenTK.Math;. As for the other two, I'm not really sure... you may have to reference both OpenTK and OpenTK.Compatibility. Alternatively you could just use QuickFont. http://www.opentk.com/node/2628
My only gripe with QuickFont is that it forces immediate mode, so in a day or two I rolled my own font rendering that used shaders and was more integrated to my project. That's also an option if you absolutely can't have the extra overhead from immediate mode, but for most cases that overhead is nothing.
Re: Rendering 2D Labels on 3D Objects
Well I have tried QuickFont, was able to display text. But all my 3D objects disappear, after struggling, to get it back. I gave up and took it out.
Well let me try your font rendering, if you don't mind posting a link here, when you roll it out. Thanks.
Re: Rendering 2D Labels on 3D Objects
I think QuickFont doesn't unbind the texture or disable anything, make sure to call GL.BindTexture(TextureTarget.Texture2D, 0); after drawing anything with QuickFont and skim through the rendering code to see if they enable/disable anything that you need set to render properly. Also make sure to push the matrix before drawing text and pop it back after.
And I'm not releasing my font rendering as a separate library, it's just a part of a game I'm working on and hoping to eventually sell. If I wanted to release it in it's current state I'd have to also expose most of the game's graphics code and you would have to heavily modify either my code or your code to work together, especially since you're using immediate mode/display lists and I'm using core OpenGL 3.3. It would be impractical and I would be exposing a lot of the work I've done for something I'm planning on selling, sorry.
Re: Rendering 2D Labels on 3D Objects
After some investigating I was about to to get QuickFont working, and not making my 3D objects disappear. I made a call to OpenGL to disable Blending and that seem to do the trick. Not sure what the Blending has to do with it.
For those reading this:
I disable Blending with the following code, which is after my 'myText.Print' call
Here is my working code. Must still work out how to display the label on the 3D object.
Program.CS