Sign in to follow this  

[java] AntiAlias with Java2D,OpenGL or LWJGL?

This topic is 3563 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
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
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
? I was thinking you could kinda smooth sprites onto a background and depending on the background it would look different, if you know what i mean. If you could just as well anti alias the png or gif then thats just lame. What is want is the kind of effect that the Zsnes uses on it's sprites. They call Super Eagle engine or 2xSai engine. Or High Definition mode and such? Does any of that ring a bell to you?

Share this post


Link to post
Share on other sites
Quote:
Original post by gekigangar
? I was thinking you could kinda smooth sprites onto a background and depending on the background it would look different, if you know what i mean. If you could just as well anti alias the png or gif then thats just lame. What is want is the kind of effect that the Zsnes uses on it's sprites. They call Super Eagle engine or 2xSai engine. Or High Definition mode and such? Does any of that ring a bell to you?

Those are specialised full screen effects, so you'll have to do it manually. That'll either mean reading the framebuffer back into main memory and doing it on the CPU (slow!) or implementing 2xSai in a pixel shader and doing it all on the GPU. There are pixel shader implementations floating around the internet if you look hard enough.

But if you're just wanting nicely smoothed sprites then just use a proper alpha channel, it's much simpler and quicker.

Share this post


Link to post
Share on other sites
OrangyTang I think you just helped me out a lot. Creating an alpha channel to smooth out the entie image after it has been drawn on a buffered image? Can this be done without the OpenGl and JLWGL. If so please do tell, and please do direct me to links and resources with examples please. Because I've gotten OpenGl to work and render simple images but it just seems overwhelmingly complex..

Share this post


Link to post
Share on other sites

This topic is 3563 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this