Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  blurry image - java slick2d  (Read 1267 times)
0 Members and 1 Guest are viewing this topic.
Offline Dicee

Junior Devvie


Medals: 2



« Posted 2013-12-20 23:20:25 »

So, I have a scaled image size, but the problem is, the image is blurry..
I've found related topic http://slick.ninjacave.com/forum/viewtopic.php?f=3&t=5145 on this problem, but for some reason it does not affect.

With out Image.FILTER_NEAREST
1  
2  
3  
4  
5  
6  
7  
            Image tableImg = new Image(tableImgRef);
            float miniTableScale = 0.35f;
            float miniTableX = miniTableBGX + (((miniTableBGX + miniTableBGWidth) - miniTableBGX) / 2)
                                                        - ((tableImg.getWidth() * miniTableScale) / 2);
            float miniTableY = miniTableBGY + (((miniTableBGY + miniTableBGHeight) - miniTableBGY) / 2)
                                                        - ((tableImg.getHeight() * miniTableScale) / 2);
            tableImg.draw(miniTableX, miniTableY, miniTableScale);



With Image.FILTER_NEAREST, it seems even worse.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
            String tableImgRef = UI_PATH + setupTable.getTableTheme() + "/table.png";
            Image tableImg = new Image(tableImgRef, false, Image.FILTER_NEAREST);
            float miniTableScale = 0.35f;
            float miniTableX = miniTableBGX + (((miniTableBGX + miniTableBGWidth) - miniTableBGX) / 2)
                                                        - ((tableImg.getWidth() * miniTableScale) / 2);
            float miniTableY = miniTableBGY + (((miniTableBGY + miniTableBGHeight) - miniTableBGY) / 2)
                                                        - ((tableImg.getHeight() * miniTableScale) / 2);
            tableImg.draw(miniTableX,
                          miniTableY,
                          tableImg.getWidth() * miniTableScale,
                          tableImg.getHeight() * miniTableScale
            );



Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #1 - Posted 2013-12-21 12:12:16 »

Odd question, but what is the original size of the image? OpenGL (and in turn Slick 2D) can sometimes do odd things behind the scenes with non power of two sized images to get them to work properly with the GPU. If your image isn't a "pot" image, then try padding it with transparent pixels until it is and see if that makes a difference.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Online SHC
« Reply #2 - Posted 2013-12-21 14:02:56 »

GL_NEAREST
is the fastest scaling filter but
GL_LINEAR
is the one that gives you best appearance.

So change it to

1  
Image tableImg = new Image(tableImgRef, false, Image.FILTER_LINEAR);

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-12-21 15:25:43 »

GL_NEAREST
is the fastest scaling filter but
GL_LINEAR
is the one that gives you best appearance.
The choice of filtering is not going to impact performance in desktop OpenGL, since it's all done on the GPU.

The image is going to look blurry no matter what, since we are re-sampling it and there are always artifacts. To reduce artifacts, use a power-of-two texture size and snap to a scaling factor like 0.5 instead of 0.473. For really small sizes, you can use mip-mapping in OpenGL to get smoother down-sampling, but that isn't well supported in Slick.

Offline Dicee

Junior Devvie


Medals: 2



« Reply #4 - Posted 2013-12-21 15:50:57 »

Quote
Odd question, but what is the original size of the image?
-580/320, png format.

Quote
GL_NEAREST is the fastest scaling filter but
GL_LINEAR is the one that gives you best appearance.

- It's same, nothing changes.



The image is going to look blurry no matter what, since we are re-sampling it and there are always artifacts.
To reduce artifacts, use a power-of-two texture size and snap to a scaling factor like 0.5 instead of 0.473.
For really small sizes, you can use mip-mapping in OpenGL to get smoother down-sampling, but that isn't well supported in Slick.

- Looks better if I set 0.5 value to scaling factor, but that's not size I need.



It seems, that everything below 0.5 is goint to make picture look blurry.. :/
You can see that these smaller circles (in above picture) are also blurry, which are images, scaled with factor less than 0.5..


Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #5 - Posted 2013-12-21 17:16:35 »

Have you considered using Slicks shape and gradient drawing functions to generate the image in question at run time instead of loading it from a preexisting image? It's a little work, but in this particular scenario it could give you the smooth look you want.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline Dicee

Junior Devvie


Medals: 2



« Reply #6 - Posted 2013-12-21 18:10:49 »

Have you considered using Slicks shape and gradient drawing functions to generate the image in question at run time instead of loading it from a preexisting image? It's a little work, but in this particular scenario it could give you the smooth look you want.

Yes, and I've already experienced that, when I used to make this components, and unfortunately found that it is really bad to draw rounded shapes in Slick2D, as I had the problems with using the AA on them. Whenever I would like to draw some rounded rectangle or circle, some strange pixels would appear above the corners. I have already asked for an answer to this problem on Slick2D forum, but they say that Slick2D not suitable for drawing rounded shapes.
Offline davedes
« Reply #7 - Posted 2013-12-21 22:28:46 »

Slick's shape classes are not so great for rendering. Things like line thickness, anti-aliasing, etc are not so easy to control.

You can just use another image that is the correct size of whatever you need it when scaled down. That way both will appear with 100% crispness, and no issues due to resampling. Or you can try mip-maps for a smoother down-scale -- search the slick forums.

Offline Dicee

Junior Devvie


Medals: 2



« Reply #8 - Posted 2013-12-22 12:11:21 »

Ok, thanks for the information.
Offline Dicee

Junior Devvie


Medals: 2



« Reply #9 - Posted 2013-12-22 17:14:29 »

I've found a nice example on how to get smoother downscaling
https://bitbucket.org/kevglass/slick/src/tip/trunk/Slick/src/org/newdawn/slick/tests/MipmapTest.java?at=development

but it seems that latest version of Slick2D, does not include

1  
2  
3  
supported = InternalTextureLoader.isGenerateMipmapSupported(); // the InternalTextureLoader does not have this method
...
ImageData.Format fmt = imageData.getFormat(); // also this ImageData doesn't have that static class Format


So I can not run a test...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #10 - Posted 2013-12-22 17:36:35 »

Grab the latest version from the repo.

You probably shouldn't expect a great deal of support for Slick since it isn't actively maintained anymore. If you want more control over your game's rendering then maybe LibGDX is a good choice. Smiley

Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #11 - Posted 2013-12-22 17:36:56 »

Here's a slightly modified version of the function from Kevin's old codebase:
1  
2  
3  
public static boolean isGenerateMipmapSupported() {
   return GLContext.getCapabilities().OpenGL14;
}

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #12 - Posted 2013-12-22 17:39:37 »

You probably shouldn't expect a great deal of support for Slick since it isn't actively maintained anymore.

I keep hearing this; however, Slick was updated in June. It just isn't maintained by Kevin anymore. Now it's handled by NinjaCave.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline Dicee

Junior Devvie


Medals: 2



« Reply #13 - Posted 2013-12-22 18:10:26 »

Grab the latest version from the repo.

Lol, I'm downloading right now the latest version from http://slick.ninjacave.com/, no way that I had out out of date version.

EDIT:

I'm checking now javadoc for LoadableImageData, and it does not contain the getFormat() method:
http://slick.ninjacave.com/javadoc/org/newdawn/slick/opengl/LoadableImageData.html

Here's a slightly modified version of the function from Kevin's old codebase:
1  
2  
3  
public static boolean isGenerateMipmapSupported() {
   return GLContext.getCapabilities().OpenGL14;
}

Thanks for that, but what about the

1  
ImageData.Format fmt = imageData.getFormat();


There's no Format class :/, and getFormat() method from LoadableImageData class.. ?
Offline davedes
« Reply #14 - Posted 2013-12-23 04:24:01 »

You probably shouldn't expect a great deal of support for Slick since it isn't actively maintained anymore.

I keep hearing this; however, Slick was updated in June. It just isn't maintained by Kevin anymore. Now it's handled by NinjaCave.
Only four commits this year, and still lots of outstanding bugs. Compared to LibGDX, which has had 26 commits in the last week. Wink

With that said, it's a nice library. Hats off to kev for all his hard work.

Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #15 - Posted 2013-12-23 04:58:07 »

There seems to be multiple ways to tackle Slick's lack of MipMaps. A couple are discussed here and here.

Only four commits this year, and still lots of outstanding bugs. Compared to LibGDX, which has had 26 commits in the last week. Wink

With that said, it's a nice library. Hats off to kev for all his hard work.

Well if LibGDX wasn't so buggy...Wink OK, I'm just kidding and you do make a valid point about the rate of commits, but I haven't seen any announcement that development on it has been halted. I'll also second your tip of the hat to Kevin for his work on making a truly "slick" 2D library. (I need to lay off the bad jokes and get some sleep. Tongue)

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (13 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (83 views)
2014-12-05 12:39:02

SHC (94 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!