[java] AntiAlias with Java2D,OpenGL or LWJGL?

Started by
11 comments, last by gekigangar 16 years, 1 month ago
Hi, my names Thomas and I've just discovered the wonders/horrors of antialiasing. I'm currently working on a simple 2d game in java using the Graphics2D. I'm thinking it would be nice to render every frame with AA to smooth out the rough etches since I'm using pixel art in the form of PNG images. So far I've found lots of examples on how to use renderinghints to turn AA on when drawing shapes, lines or simple fonts but no good examples for rendering images. I've found this but it seems much too complicated and as the author himself states "Note that there will likely be some performance hit from transforming the image in this manner" link to mentioned article It seems like a real hassle if thats the only way to do it. And I have no idea whether the AA only triggers when you actually transform the image or if it's apllied on static images as well. I've had a look at OpenGL and the LightWeightJavaGameLibrary JLWGL which claims to use OpenGL but I can't find a simple good at example of how to render images such as bmp,png,gif or jpeg with AA. What I want to do is draw all my images in a buffered image and then render this image with AA before showing it. If you could just point me in the right direction or show me one good example of how to do this I would be ecstatic. Thanks in advance, Thomas
Advertisement
Look at RenderingHints for Java2D, there you can specify to use anti-alias. Is that enough for you?

Edit: Sorry, missed some things in your post, you have already been down this road.

Lizard
Quote:Original post by gekigangar
I've had a look at OpenGL and the LightWeightJavaGameLibrary JLWGL which claims to use OpenGL but I can't find a simple good at example of how to render images such as bmp,png,gif or jpeg with AA. What I want to do is draw all my images in a buffered image and then render this image with AA before showing it.

If you're using LWJGL and OpenGL, then bilinear filtering on texture is automatic (unless you turn it off), and is controlled via GL_TEXTURE_MAG_FILTER. Antialiasing for poly edges can be done via GL_POLYGON_SMOOTH_HINT (default off).

For a simple example of drawing images via LWJGL, check out the space invaders tutorial.
Quote:If you're using LWJGL and OpenGL, then bilinear filtering on texture is automatic (unless you turn it off)


Ohh sounds interesting. I was looking for a switch on thing like in Graphics2D. I know Coke And Code's Space Invader's game almost by heart. I havent done the example with LWJGL though since I couldn't tell any difference from the look of the sprites in his original version without using LWJGL. But I'll try to recreate my current setup to draw the textures using the settings you've specified.

Any good links for other tutorials or explanations on how to use LWJGL. I find the wiki on their website lacking in many aspects. Is there like an In Depth FAQ or should i just look at their JavaDoc and try things out to see what they do?

Oh and thanks :)
Quote:Original post by gekigangar
Any good links for other tutorials or explanations on how to use LWJGL. I find the wiki on their website lacking in many aspects. Is there like an In Depth FAQ or should i just look at their JavaDoc and try things out to see what they do?

The LWJGL API is actually very small, and covered quite well in the javadocs. As well as that you should check out the samples for some example code.

The OpenGL and OpenAL functions work the same as for C, so any standard documentation will suffice. The red book is a good introduction if you're new to OpenGL, plus theres the documentation.
Thanks a lot for the quick reply. I hope this will suffice for my future rendering needs ;) I'm totally new to OpenGL so that was exactly what I was looking for.
If OpenGL seems daunting you can still use it but not worry about how it works by using Slick. Slick is a 2D game library that uses LWJGL under the hood.

http://slick.cokeandcode.com/
http://slick.javaunlimited.net/index.php
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
Yes Slick is definitely an alternative I will consider. My brother has been corresponding with Kev from Coke&Code who's helping develop Slick and he also told us to check out this project:

http://www.interactivepulp.com/pulpcore/

Which seems nice as well.
OpenGL anti-aliasing is kind of a pain. OrangyTang mentioned using GL_POLYGON_SMOOTH_HINT, but that's deprecated due to rendering artifacts. Full-screen anti-aliasing is the preferred method in OpenGL, but it can be really slow.

Here's a post from another forum about the artifacts: http://objectmix.com/graphics/136634-artifacts-when-using-antialiased-2d-polygons.html

If you're using JOGL for OpenGL, you can setup full-screen anti aliasing using:

GLCapabilities.setSampleBuffers(true);
GLCapabilities.setNumSamples(X); // where X is the number of samples per pixel
BTW, none of this talk of antialiasing will actually help with any sprite rendering whatsoever.

To do antialiased sprites - you need to have them drawn with antialiased edges in the first place by the artist (and then subsequently saved as TGAs or PNGs with 32bit RGBA).

Cas :)

This topic is closed to new replies.

Advertisement