Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  (Slick2D) TiledMap scaling quality  (Read 1329 times)
0 Members and 1 Guest are viewing this topic.
Offline DrewLols

Senior Member


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Posted 2012-11-02 01:03:00 »

When I scale the graphics context in any render method, images, for the most part, scale perfectly smoothly.  Images extracted from a TiledMap, however, don't seem to have this effect.  Let me be specific in what I'm doing...

I extract images from a TiledMap for individual rendering rather than simply calling the map's .render() method (for my own purposes,  don't judge!) and I render them one by one in a separate pool.

The problem is, when I render images from a TiledMap in this fashion, the quality of the images deteriorate when, for instance, I want to transform the graphics context before anything is rendered.

So, I might write something like this...

public void render(Graphics g)
{
    g.transform(0.75f, 0.75f);
    imagePool.render(g);

    // Blah blah blah, render other stuff, blah blah blah...
}

The images rendered from said pool appear to be a little blocky, nearest neighbor-ey-ish.  They are jagged in comparison to the rest of the images.

How can I avoid this problem?

Did you know that 90% of statistics are wrong?
Offline SHC
« Reply #1 - Posted 2012-11-02 02:15:55 »

This is because TiledMap scales the images to the tile size and you are stretching it.

P.S use
Quote
/[code/]
tags for code.

Offline davedes
« Reply #2 - Posted 2012-11-02 02:27:06 »

Quote
appear to be a little blocky, nearest neighbor-ey-ish.  They are jagged in comparison to the rest of the images.
TiledMap uses FILTER_NEAREST by default.

Use getTileSetCount and getTileSet to iterate through each tile set, then call setFilter on the SpriteSheet in that tile set and use FILTER_LINEAR.

Note that you may run into filtering artifacts; e.g. lines between tiles, depending on how you are rendering and storing your data.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DrewLols

Senior Member


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #3 - Posted 2012-11-02 16:30:22 »

Quote
appear to be a little blocky, nearest neighbor-ey-ish.  They are jagged in comparison to the rest of the images.
TiledMap uses FILTER_NEAREST by default.

Use getTileSetCount and getTileSet to iterate through each tile set, then call setFilter on the SpriteSheet in that tile set and use FILTER_LINEAR.

Note that you may run into filtering artifacts; e.g. lines between tiles, depending on how you are rendering and storing your data.

Ah!  You were right about the visual artifacts, davedes.  Also, I was only really able to get the smooth effect to work when I applied the filter to each individual image within the map rather than the sprite sheets (probably because I painted the images outside of the TiledMap itself).  Course, the side effect of this is that the borders of the images when scaling are transparent half the time and leave behind an awkward outline in the shape of the grid.

I've considered rendering all that there is to a second buffer, then scaling said buffer.  I would do this by drawing my objects to an Image, then drawing the scaled image to the graphics context in the render method.

If there is a way to do this with less bloat, or if my entire idea is a bad one,  I would appreciate some input!  Thanks a bunch!  Cool

Did you know that 90% of statistics are wrong?
Offline davedes
« Reply #4 - Posted 2012-11-02 17:41:47 »

Quote
I've considered rendering all that there is to a second buffer, then scaling said buffer.  I would do this by drawing my objects to an Image, then drawing the scaled image to the graphics context in the render method.
This is an easy solution and should give you pretty good results. Benchmark & stress test it to see if the performance is acceptable, as it will lead to extra texture binds and high fill rate.

Read the following links to get a better understanding of sprite rendering in Slick/OpenGL:
http://www.slick2d.org/wiki/index.php/Performance
http://slick.javaunlimited.net/viewtopic.php?p=31225#p31225
http://slick.javaunlimited.net/viewtopic.php?p=31187#p31187

Offline DrewLols

Senior Member


Medals: 3
Projects: 1


Noob going through metamorphosis...


« Reply #5 - Posted 2012-11-02 19:15:40 »

Quote
I've considered rendering all that there is to a second buffer, then scaling said buffer.  I would do this by drawing my objects to an Image, then drawing the scaled image to the graphics context in the render method.
This is an easy solution and should give you pretty good results. Benchmark & stress test it to see if the performance is acceptable, as it will lead to extra texture binds and high fill rate.

Read the following links to get a better understanding of sprite rendering in Slick/OpenGL:
http://www.slick2d.org/wiki/index.php/Performance
http://slick.javaunlimited.net/viewtopic.php?p=31225#p31225
http://slick.javaunlimited.net/viewtopic.php?p=31187#p31187

Thanks for the rendering tips!  Eventually, I AM going to have to learn how to use openGL.  I just post that the method I suggested seems to work fine.  I don't know how it will perform on a larger scale, though.

Did you know that 90% of statistics are wrong?
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!