I'm having problems making antialiasing of lines and points work in
pure immediate mode. Is this a known problem? It used to work before
with Java3D 1.1.3, but now fails with Java3D 1.2. My setup is Sun Ultra
60, Elite3D, Solaris 7 (SunOS 5.7), and JDK 1.3.0 (1.2.1 doesn't work
either), and I believe the appropriate patches have been applied.
Please see the enclosed test program. I render lines with a pretty
minimal Appearance that includes only LineAttributes and
ColoringAttributes. When I turn on line antialiasing, the lines just get
thicker, and their color shifts slightly. Should I be doing something
more to setup antialiasing?
--Young
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class AntialiasTest
{
public static void main(String[] args)
{
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
TestCanvas3D canvas = new TestCanvas3D(config);
canvas.stopRenderer();
final Circle circle = new Circle(canvas);
canvas.addPaintObserver(new Observer() {
public void update(Observable o, Object arg)
{
circle.draw();
}
});
SimpleUniverse univ = new SimpleUniverse(canvas);
univ.getViewingPlatform().setNominalViewingTransform();
Frame frame = new Frame();
frame.setSize(600, 600);
frame.setLayout(new BorderLayout());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.add("Center", canvas);
frame.show();
}
private static class TestCanvas3D extends Canvas3D
{
public TestCanvas3D(GraphicsConfiguration config)
{
super(config);
}
public void addPaintObserver(Observer o)
{
m_observable.addObserver(o);
}
public void removePaintObserver(Observer o)
{
m_observable.deleteObserver(o);
}
public void paint(Graphics g)
{
super.paint(g);
m_observable.notifyPaintObservers();
}
//================================================================
private PaintObservable m_observable = new PaintObservable();
private class PaintObservable extends Observable
{
public PaintObservable()
{
super();
}
public void notifyPaintObservers()
{
setChanged();
notifyObservers();
}
}
}
private static class Circle
{
public Circle(Canvas3D canvas)
{
m_canvas = canvas;
Appearance appearance = createAppearance();
m_circleA = new Shape3D(createCircle(0.8f, 12), appearance);
m_circleB = new Shape3D(createCircle(0.6f, 12), appearance);
m_circleC = new Shape3D(createCircle(0.4f, 12), appearance);
}
public void draw()
{
GraphicsContext3D gc = m_canvas.getGraphicsContext3D();
gc.clear();
gc.draw(m_circleA);
gc.draw(m_circleB);
gc.draw(m_circleC);
m_canvas.swap();
}
private Appearance createAppearance()
{
LineAttributes lineAttributes = new LineAttributes();
lineAttributes.setLineAntialiasingEnable(false);
ColoringAttributes coloringAttributes =
new ColoringAttributes(0.9f, 0.5f, 0.0f,
ColoringAttributes.FASTEST);
Appearance appearance = new Appearance();
appearance.setLineAttributes(lineAttributes);
appearance.setColoringAttributes(coloringAttributes);
return appearance;
}
private Geometry createCircle(float radius, int numSegments)
{
int[] stripLengths = { numSegments + 1 };
Point3f[] points = computeCoordinates(radius, numSegments);
LineStripArray lines =
new LineStripArray(points.length, GeometryArray.COORDINATES,
stripLengths);
lines.setCoordinates(0, points);
return lines;
}
private Point3f[] computeCoordinates(float radius, int numSegments)
{
Point3f[] retval = new Point3f[numSegments + 1];
Matrix4d rot = new Matrix4d();
for (int i = 0; i <= numSegments; i++)
{
retval[i] = new Point3f(radius, 0.0f, 0.0f);
double angle = 2.0 * Math.PI * i / numSegments;
rot.rotZ(angle);
rot.transform(retval[i]);
}
return retval;
}
private Canvas3D m_canvas;
private Shape3D m_circleA;
private Shape3D m_circleB;
private Shape3D m_circleC;
}
}