zShapes - Resolution Independent Curve Rendering

ok, well I asked all those questions because im currently thinking about creating a framework in which shapes are fundamental;
for example it will contain a gui system which uses shapes as base for widgets, so it seems like a good idea to make these shapes as generic as possible (so I can use them for other purposes aswell), would it be a good idea to stick to the SVG specification for that? (maybe use or interface the batik library)

i’d like to have the implementation for rendering these shapes abstracted too (be it java2d, jogl, lwjgl etc), so maybe I could use zShape for rendering these shapes on hardware?

I updated zShapes (~3.8MB) again. A font map file can now be created from the Tools menu. The whole unicode range can be used, even supplementary characters (>16-bit, surrogates are fully supported in the renderer). Select a font, choose all or some of the unicode ranges available and press OK to create the font map file.

Warning: Some fonts contain tens of thousands of glyphs and the triangulation process takes a lot of time (not optimized yet). Most fonts are ok though, for example, the Arial font with ~1150 glyphs takes 14 seconds to complete on my machine.

The Viewer has also been updated to support font maps. Press ‘M’ to select a font map, then select a text file and the proper encoding. Press ‘I’ for italics, ‘U’ for underlined and ‘S’ for strikethrough (see README or the built-in help for more shortcuts).

Two more improvements left (faster font map creation and better antialiasing quality) and then I’ll release the source code.

[quote=“bitshit,post:21,topic:28237”]
Yes, absolutely. A resolution independent GUI (not only text) is one of the things I want to try as an application of zShapes. Another one is projected texturing (as an example in our game, a team logo projected on a hoplite’s shield).

[quote=“bitshit,post:21,topic:28237”]
Unless you implement the whole SVG spec, it would have to be a small subset of it. But yes, at least for simple stuff, I think it can be done.

[quote]Yes, absolutely. A resolution independent GUI (not only text) is one of the things I want to try as an application of zShapes. Another one is projected texturing (as an example in our game, a team logo projected on a hoplite’s shield).
[/quote]
That’s great! I think I’ll better wait a bit to see how things develop given my limited expirience and your & Ulfjacks effords in that area :wink:

Hi again,

This is the (probably) final release of zShapes in binary (4.12MB) and source (4.02MB) form. Some notes:

  • Both archives contain the samples
  • The BSD license is used for the source
  • There’s an ant script with the following targets:
    ant jars (creates the binaries)
    ant editor (runs the Editor)
    ant viewer (runs the Viewer)

I didn’t have much time lately, so I couldn’t make any further improvements to the antialiasing quality. I managed to improve the font map creation speed though (around 100 glyphs per second on my machine).

I know this is a REALLY old thread, but I was hoping there might be some example source code somewhere on how to use this?

The source archive contains a simple viewer (gr.zdimensions.zshapes.viewer package) with all the rendering code. The shaders are in there too.

I created a

I created a font map and loaded it like:

fontMap = new FontMap(".../test.zfm");
font = new Font(fontMap, 32.0f);

Then to render it I used:

font.render("Hello World!", false, 0.0f);

I get no errors but nothing is displaying on the screen…is there something else I need to do to make this function?

Yes, the Font and FontMap classes only encapsulate the font geometry/information, they don’t know how to render themselves. What you need is a ShapeRenderer implementation. Some example code:

// Init
ContextCapabilities caps = GLContext.getCapabilities();
ShapeRenderer renderer = ShapeRenderer.shapeRendererGetHard(caps); // or .shapeRendererGetAA(caps) for antialiased shapes

FontMap fontMap = new FontMap(".../test.zfm");
Font font = new Font(fontMap, 32.0f);

TextArea renderable = new TextArea(font, "Hello World!");

// Render
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

renderer.render(renderable);

The ShapeRenderer factory methods will return an implementation appropriate for your GPU. There are GLSL implementations and also ATI_fragment_shader and NV_register_combiners implementations for older hardware. The TextArea class is a simple Font wrapper that simplifies its use, it doesn’t do anything special. For more details see the initialize, loadMap and renderShape methods in the ShapeViewer class.

Anyway, when you get this working and are more familiar with it, I’d highly recommend you rewrite the whole thing. It’s really old code of a quick’n’dirty implementation.

Yeah, if I get this working I will probably start re-writing it. I’m getting farther, but now I seem to be having trouble with compiling a fragment shader:

[quote]Caused by: java.lang.RuntimeException: Failed to compile fragment shader: curve.fsh
0(17) : error C7506: OpenGL does not define the global type half4
0(17) : error C7557: OpenGL does not allow Cg-style semantics
0(17) : error C7530: OpenGL requires main to return void
0(21) : error C7506: OpenGL does not define the global type half3
0(22) : error C7506: OpenGL does not define the global type half
[/quote]
I’m really surprised there isn’t an SVG / vector font API for OpenGL already in common use. I would think this would be a really popular feature.

Try to remove the #version 110 directive from the shader files and see what happens. If it doesn’t work, simply replace all half{234} instances in the shader code with float/vec{234}. Half types are kinda obsolete now anyway, but they were important back then for first generation shader hardware (NV’s particularly).