Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 2044 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Devvie

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

         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);

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:

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:

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

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

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


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  

DesertCoockie (33 views)
2018-05-13 18:23:11

nelsongames (75 views)
2018-04-24 18:15:36

nelsongames (70 views)
2018-04-24 18:14:32

ivj94 (752 views)
2018-03-24 14:47:39

ivj94 (82 views)
2018-03-24 14:46:31

ivj94 (622 views)
2018-03-24 14:43:53

Solater (98 views)
2018-03-17 05:04:08

nelsongames (179 views)
2018-03-05 17:56:34

Gornova (405 views)
2018-03-02 22:15:33

buddyBro (1065 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!