Jump to content
  • Advertisement
Sign in to follow this  
gekigangar

[java] AntiAlias with Java2D,OpenGL or LWJGL?

This topic is 3756 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!