Valid XHTML 1.0!

grafx

Line-drawing and Polygon-filling Rasterization Libraries for Java

written by Nerius Landys


Overview | Acknowledgments | Future | Documentation | Examples | Download

Overview

grafx is an open source Java library for drawing lines and filling polygons using floating-point endpoint coordinates. It is distributed under the terms of a BSD-style license. This library is compatible with Java 1.0 and newer.

This library was developed because Java uses integer endpoint coordinates for all of its built-in line-drawing and polygon-filling routines. [EDIT: With Java 1.2 this has changed if you are using anti-aliasing.] Well, what happens when you draw a line from (0,0) to (13,17), and then want to draw a smaller line segment from (0,0) to the midpoint of the original line segment? The answer is that the smaller segment will not completely cover the original segment; they will not overlap. This causes much frustration for Java game developers who are using line drawings in their games.

The lines and polygons produced by this library are uber correct. The performance of this library is decent; it's not possible to get substantially better performance from a software rendering system. I received an A+ from an advanced Computer Graphics course at University of California, Berkeley, and I applied the knowledge gained from that course to writing this code. :-)

It's not possible to do anti-aliasing with this library. The lines and polygons produced by grafx are suitable for simple Java-based video games that want to have that "retro" look to them (see the jblockout.net example below).

By the way, Bresenham's line drawing algorithm is crap. It's only suitable if you can live with always having your line start and end at integer endpoint coordinates. I developed a superior line drawing algorithm that is almost as efficient, but uses floating point endpoints instead.


Acknowledgments

The grafx project is hosted by sourceforge.net.

I have my own private SVN repository with lots of neato stuff (for my jblockout.net project), but I thought I'd make these line-drawing and polygon-filling algorithms public. Hence the hosting on SourceForge.


Future

I'd like to provide an API for grafx that uses only fixed-point integer arithmetic. Then, it would be possible to draw nice lines and fill nice polygons in J2ME.

I had started to implement a 3D version of this library with z-buffering, but when I started thinking about rendering bitmaps I became overwhelmed. I had gotten to having a polygon filler in 3D using z-buffering and vertex color interpolation when I aborted this project.


Documentation


Examples


Download Source Files

All downloads for grafx are available at https://sourceforge.net/projects/grafx/. The current version of grafx is 1.0.2. There are currently no known bugs (only shortcomings). :-)