My java application uses jogl to create surfaces with an overlaid grid. The lines of the grid are anti-aliased. However, on Windows the anti-aliasing is complete garbage, unless I add a small alpha value to the surface. Here are screen shots of the same scene on all three platforms:
Mac OS X:
Ubuntu 11.10:
Windows 7:
Windows 7 with alpha=0.01:
The basic procedure to create this is as follows:
gl.glPushAttrib( GL.GL_ALL_ATTRIB_BITS );
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(1.0f, 1.0f);
drawSurface(gl);
gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
gl.glPopAttrib();
gl.glDisable( GL.GL_LIGHTING );
gl.glDepthFunc(GL.GL_LEQUAL);
float[] c = {0, 0, 0, 0.5f};
gl.glColor4fv(c, 0);//the alpha here gets overridden if one is specified for the surface (which is why the Windows-with-alpha produces a darker grid)
drawGrid(gl);
gl.glDepthFunc(GL.GL_LESS);
gl.glEnable( GL.GL_LIGHTING );
The drawSurface() method also does the following before creating the polygons for the surface (using GL_TRIANGLE_STRIP primitives):
gl.glPushAttrib(GL.GL_LIGHTING_BIT);
gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
gl.glEnable(GL.GL_COLOR_MATERIAL);
The drawGrid() method sets up anti-aliasing like so:
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_LINE_SMOOTH);
gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);
The grid itself is created using GL_LINE_STRIPs
I've read up on the OpenGL documentation regarding line anti-aliasing and also tried out the polygon offset example here.
As for hardware, I have dual boot IBM ThinkPad (64-bit quad core) with an integrated nVidia 3100M card and an Intel Core 2 Duo iMac which has an ATI Radeon. Since Ubuntu and Windows are running on the same hardware, I know it can't be a hardware issue.
I'm looking for suggestions for improving the anti-aliasing of the grid lines on Windows.
Turns out I had not tried (I thought I had, but I did not rebuild and test it correctly) gl.glDepthMask( false );
Adding that in correctly did greatly improve the fragmentation of the anti-aliased lines of the grid.
That said, I'm still not 100% happy with the look of the lines, but, for now, this question is resolved. Here is a screen shot of the 'improved' grid lines:
While this is a great improvement, it's still not as good as Mac OS X or even Ubuntu.