Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
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  
  Not blurry enlarged sprites  (Read 1105 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Posted 2012-06-12 03:30:23 »

I have a fairly technical question
I'm rendering my sprites like this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
sprite.bind();
     
      GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(0,0); //Upper left
         GL11.glVertex2f(displayWidth/2 - sideLength/2, topBuffer);
         GL11.glTexCoord2f(0,1); //bottom left
         GL11.glVertex2f(displayWidth/2 - sideLength/2, topBuffer+sideLength);
         GL11.glTexCoord2f(1,1); //bottom right
         GL11.glVertex2f(displayWidth/2 + sideLength/2,topBuffer+sideLength);
         GL11.glTexCoord2f(1,0); //Upper right
         GL11.glVertex2f(displayWidth/2 + sideLength/2, topBuffer);
      GL11.glEnd();


Don'y worry about the code, I'm just showing you the basic format
I'm using GL11

Now, there comes a time in every game programmer's life where he must render a sprite to dimensions bigger than the original sprite's dimensions

For example, my item sprites are 16x16, but I want to draw them to look 128x128

That was no problem. I got that working. However, when the sprite got enlarged, it also got blurry

My game is kinda going for a pixel-y feel, so having the sprite plain enlarged is no problem. In fact, the blurry enlargement looks bad.

How can I set it so that it doesn't enlarge like that?
Offline Kinaces

Junior Newbie




Wokka Wokka Wokka


« Reply #1 - Posted 2012-06-12 04:53:35 »

From what I understand this would be impossible to do with your code. The reason this doesn't work is because from what I understand about sprites. (Might wanna wait for someone to confirm this) Sprites are basically bitmaps. You cannot enlarge bitmaps without loss of quality. (Since you are basically taking each pixel and increasing the size. It gives the edges a rougher look.)
As far as I know there isn't a software that can increase the size of bitmaps.

If you use GIMP or Photoshop. Take the image. Resize it to 128x128. Make a new layer. Trace original image. You can be done in 5 minutes.

P.S. All bitmaps work like this. The images that you can resize freely are vector images.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #2 - Posted 2012-06-12 06:27:47 »

You merely need to set the max filter to GL_NEAREST.  Not sure how to do that with slick (which I assume you're using by the sprite.bind() call), but in raw opengl you do it with glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-06-12 11:18:33 »

Read up on OpenGL texture mapping:
http://www.gamedev.net/page/resources/_/technical/opengl/opengl-texture-mapping-an-introduction-r947
http://www.gamedev.net/page/resources/_/technical/opengl/opengl-texture-mapping-an-introduction-r947

Once you've read those, you might realize that your texture coordinates [0,1] could be wrong, i.e. if your texture is not power-of-two. More info/code here:
http://slick.javaunlimited.net/viewtopic.php?p=25911#p25911

To load images with a different filter in Slick-Util you can use the TextureLoader class.

1  
texture = TextureLoader.getTexture("PNG", inputStream, GL11.GL_NEAREST);


Or to set it after the fact, like sproingie said, you would do it like so:
1  
2  
3  
4  
5  
6  
static import org.lwjgl.opengl.GL11.*;
...

texture.bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


Sometimes you'll want a different minification filter (i.e. LINEAR). Alternatively, you could use mipmapping for smoother down-scaling -- although this isn't supported by Slick-Util. (You'd have to write it yourself.)

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.

TehJavaDev (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!