Java AWT Font and JOGL: 3D text with display lists and VBO's

I have been messing around with using Java Fonts and rendering them using JOGL. I got a lot of ideas from the code at http://lwjgl.org/forum/viewtopic.php?t=1430 I use a PathIterator from GlyphVector from the text/font combo to get an outline and use a GLUtessellator to create the polygon text. For 3D text a mirror of the polygon text is writen at depth z and then the sides are drawn based on the outline.

I have a display list for 2D text and display lists and VBO’s for 3D extruded text. I am going to attempt to refactor the tesselator callback to store all the vertices in one big array and then use seperate array indices for the top, bottom, and sides of the text since the current implmentation uses triangle arrays so there is effectively no vertice reuse. Rename the txt file to zip and rename the packages as needed.

I have updated this code by dropping the display list and the single vertex use VBO. Now There is a VBO vertex array that contains the vertices for the text polygon at z=0 and the vertices for the text at z=depth. There is also now a seperate index array VBO that contains triangle array vertices for the text at z=0, z=depth, and indices for the sides. Together these two VBO’s are used to draw the triangles to the screen in hopefully a bit more efficient manor. I have also added 2D functionality.

Instead of straight depth based extrusion I would have liked to have use evaluators for nice curved 3D text but that is beyond my capabilities so this is pretty much it. Save VBOFontTesselator.txt as a .zip

First off, thanks for your code!
I’m very interested in your VBOFont classes, because I want to learn about VBO’s and I want to learn about having fonts inside my apps :slight_smile:

I decided to do some stresstesting, and I fed a 9K text to your tesselator.
I must admit I’m too lazy to get a profiler going at it ::slight_smile: but I peppered your code with a few System.currentTimeMillis()


before read file: 1152966958906
after read file: 1152966958921
before create glyphVector: 1152966959078
after create glyphVector: 1152966959125
after getOutLine: 1152966978359
after path iterator: 1152967186109
#closes = 9875
#cubics = 0
#lines = 41342
#moves = 9875
#quads = 88350

It takes the tesselateText() method in your class about 3.4 minutes to complete the file :o The framerate was still acceptable, though (2800+ CPU, NVidia GF4ti)
I wonder where I could take some shortcuts to speed up the process? setting the “curvePoints” parameter lower than 2 created nonsensical glyphs :slight_smile:

And secondly, if I want real, raw performance, should I stay away from truetype fonts, or pre-render them into a bitmap ? I suspect half-life 2 uses them for the console, so it can’t be that slow!

Cool stuff! Congratulations!

[quote]And secondly, if I want real, raw performance, should I stay away from truetype fonts, or pre-render them into a bitmap ? I suspect half-life 2 uses them for the console, so it can’t be that slow!
[/quote]
yeah, Arons code is wonderful for creating 3D text, but if you only need to render 2D text it is faster to pre-render all characters on a texture. We do exactely that in FengGUI (http://fenggui.java.net). You will also find some handy tools for loading/saving fonts and pre-rendering characters (anti-aliased, outlined, filled with a pattern, etc.). I am currently playing around with some Klingon fonts in the webstart demo.

Johannes

Wow that is a lot of time!

Off hand I used arraylists to store the vertices before putting them into a VBO so I could create the NIO buffer to size. If during tesselation the arraylist needed to be constantly resized that could cause extreme delays. I also ran this code on an AMD64 bit machine so I used doubles instead of floats for better percision so it may run much slower on a 32 bit machine. Really the VBO code is best for 3D extruded text and Schabby is right in rendering 2D text to a FBO for reuse would be less taxing on the GPU. I will work on some FBO JOGL code and see if I can an example working.

Wow Schabby your https://fenggui.dev.java.net/ project rocks! You need to get the word out :slight_smile:

[quote]Wow Schabby your https://fenggui.dev.java.net/ project rocks! You need to get the word out
[/quote]
Thanks! I am glad you like it!

Johannes

Here is some code for rendering text to a Frame Buffer Object (FBO)
Rename .txt to .zip

Ah cool! I look into it ASAP. Thanks again for posting the code!

I have been pretty busy with other stuff lately such that I had to put FengGUI into stasis for a few weeks. That’s also the reason why I have been absent on the forum. I resume development at the WE. However I am quite happy with our current font solution and I am not sure when (and if) we integrate your code. There are pressing things like deeper XMLization, animated textures, nicer table Widget, missing Widgets and lethal bugs that I need to tackle first.

Johannes