How do I remove the "smoothing out" effect when I render?

Started by
5 comments, last by Folke 16 years ago
Hi Gamedev, I'm switching to OpenGL from DirectX, so wish me good luck, will you? Overall everything is working out fine. Except from this one detail. But it's a really important detail, so I just have to make it work. I'm making an old-school 2D game. So it naturally has to be in low resolution. And I know that I could just change the screen resolution and be done with it. But I don't want to do that, some laptops can't enter low resolutions. And changing screen-resolution can take several seconds. Resizing every texture as I draw them is a much better solution, in my opinion. But it doesn't work. OpenGL draws my sprite-textures all fuzzy when I resize them. First look at this screen. That is what it looks like. Then look at this screen. That is what I would like it to look like. (I'm not actually making my game THAT low res. Only almost) To sum it up I want to make a low-resolution (2D) game without changing the screen resolution. So. What should I do? It worked fine in Direct3D, so there has to be a way to do it in OpenGL, right? Here is the code I use to render, in case that's any help:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
float x      = 100.0f;
float y      = 100.0f;
float z      = 0.0f;
float width  = 32.0f;
float height = 32.0f;
float f      = 9.0f;  // resizing factor
glTexCoord2f(0.0f, 0.0f); glVertex3f( x,           y+(height*f), z );
glTexCoord2f(0.0f, 1.0f); glVertex3f( x,           y,            z );
glTexCoord2f(1.0f, 1.0f); glVertex3f( x+(width*f), y,            z );
glTexCoord2f(1.0f, 0.0f); glVertex3f( x+(width*f), y+(height*f), z );
glEnd();




Thank you for your time // Folke
Advertisement
Your images won't load, but I'll try and suggest this:

If you want your images pixelated, MAKE pixelated images. If you try and resize an otherwise normal image to make it pixelated, OpenGL will do everything it can to smooth the image and make it look normal (unless you change the texture filtering parameters).

If you want pixel art, make pixel art. There was an article posted on Gamedev's front page just a few days ago about creating pixel art.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

Quote:Original post by deadstar
If you want your images pixelated, MAKE pixelated images. If you try and resize an otherwise normal image to make it pixelated, OpenGL will do everything it can to smooth the image and make it look normal (unless you change the texture filtering parameters).

Given that changing texture filtering parameters is so easy and that (ostensibly) the art is already done, I'd give it a shot. Particularly, pay attention to your glTexParameteri calls when you load and set up your textures. You'll want to use GL_NEAREST for your min/mag filters.
Sorry about the images, I think they are OK now though. Yeah, you are right I definitely want to make pixel art. But, well that one is actually OK right now. The problem is how to keep my pixel art low res.

The texture filtering parameters you were talking about is probably exactly what I'm looking for though. Any idea about what kind of parameters that would be?
Oh, GL_NEAREST? I'll give that a shot. Thanks!
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Worked like a charm. Thanks!

This topic is closed to new replies.

Advertisement