-
Notifications
You must be signed in to change notification settings - Fork 1
Home
ABOUT
This project uses JOGL libraries to draw geometry. Main idea is that every shapes are triangle strips (or sets of triangle strips) and are stored, and rendered with VBO. Each shape during construction is stored in FloatBuffer. Sometimes to build corresponding set of triangle strip additional temporary buffer or array is used (eg while tessellation or ending caps as arc in stroking).
Geometry is based on shape’s classes from java.awt.geom package. User can provide corresponding shape to API to be precess. Each shape can be fill, stroke and clip. Then shape’s geometry are taken according to Java’s PathIterator. Next is creation of triangle strips depending on demanding operation. For filling or clipping simple convex primitives (like rectangles or ellipses) are triangulated, concave and more complicated shapes (like those constructed by Java’s Path2D) are tessellated. Stroking is done separately in independent way.
Everything was constructed to be used in loop.
Simple ‘geometry flow’
Images are treated as textures. Image data should be dimension of power of 2, otherwise it will cause unpredicted rendering. There is also possibility to render Java’s BufferedImage ‘on the fly’, then dimension can be different, but it is about 20% slower than using textures.
There is also possibility to draw antialiased texts (also as geometry).
Antialiasing is done by multisampling. Unfortunately not each system respect application settings and then antialiasing need to be switch on in system. Moreover when antialiasing is not supported than it can behave unpredictable because of GLcapabilities which are then selected ‘by defoult’; (eg with such ‘defoult’ capabilities double buffering can be switched off).
Main Features:
- Filling
- Stroking
- Clipping
- antialiased texts
- text drawn on shapes
- colour alpha blending
- drawing images (supports most used formats: jpg, tiff, gif, tga, bmp)
- vertex and fragment shader
- tessellation
TESSELLATION and TRIANGULATION
Convex shapes are triangulated, this process is less CPU resources consuming than tessellation. Triangulation process create triangle strip from path iterator coordinates. It simply starts from first and last point and connect them in strip till last left point.
Triangulated ellipse
Tessellation is done using GLU’s tessellation. Unfortunately those classes seems to be designed for immediate mode only: it produces different triangles structures (triangle fan, triangle strips, single triangles) which has to be converted into triangle strips.
Tessellated concave shape (as ‘line strip’)
Tessellated concave shape (as ‘triangle strip’)
Possible future improvement: some fast test for convex and concave shapes to perform triangulation instead of tessellation; use different libraries or own tessellation classes which would be faster especially when no need to convert triangle fans int triangle strips.
VBO
Each geometry as triangle strips is processed into Vertex Buffer Object. Each shape (also stroke) is loaded into buffer by glBufferData function, so the VBO doesn’t need to be resized, only vertexes which belong to curently renderd shape are loaded into buffer. There was other possibilities eg to use glBufferSubData or to map buffer but test shows that glBufferData is the fastest. Straight after loading rendering is performed by glDrawArrays. So the glBufferData and glDrawArrays functions are called together once per shape. This solution gives possibility to change vertex attribute like color or current used shaders for each shape separately.
Possible future improvement: numbers of glBufferData and glDrawArrays has affect on performance, to reduce those functions call numbers shapes which has same attributes cloud be load and render in same time.
STROKE CONSTRUCTION
Stroking is done is Stroker.scala class. Is use Java’s BasicStroke class to capture settings like cap and join style, width, dash pattern and dash offset. There are different kind of stroke: outline and stroke itself. Outline is just not interrupted line around shape, is done a bit different way that interpreted stroked line.
When outline, it goes through all point around shape geometry: each point are connected by ‘lineTo’ which create single line segment; each line segments are joined by ‘joinTo’; algorithms goes until last iterated point. First and last points are ended by cap determined by corresponding style.
Stroking is done in similar way: first it creates path which is consist of stroke’s sequence points (two point for each dash line). According to those moveTo and lineTo sequence stroke is build.
Lines segments and caps are separate triangle strips sequences.
Stroke and outline produces “double belnding” artifacts which are removed using OpenGL’s stencil buffer. Becouse of that, before stroke render, it needs to be draw with stencil plane (clear method in GLCanvas.scala file).
Another possibility to perform stroking is to triangulate path given by createStrokedShape method form BasicStroke class. This approaches doesn’t produce “double blending” artifacts but test shows that is nearly two times slower.
Stroke’s Double Blending artifacts
Stroke rendered with stencil buffer
SHADERS
Shaders can be use for all geometry, they can be “assigned” for separate shape or for group of shapes.
Convolution image filters by shaders
EXEMPLE
Exemplary applet based on this API, written in Java which shows that API is compatible with Java
applet






