SFML community forums
General => Feature requests => Topic started by: Mars_999 on September 18, 2010, 06:47:29 pm
-
Hello,
Can we add in the ability to generate mipmapping.
Using
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
We can use the glGenerateMipmap() if everyone is on board for that vs. the above code...
I am thinking of something like this?
bool Image::CreateTexture()
{
// Create the OpenGL texture
if (!myTexture)
{
GLint PreviousTexture;
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
GLuint Texture = 0;
GLCheck(glGenTextures(1, &Texture));
GLCheck(glBindTexture(GL_TEXTURE_2D, Texture));
GLCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, myTextureWidth, myTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
if(myIsMipmapped)
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST));
else
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, myIsSmooth ? GL_LINEAR : GL_NEAREST));
GLCheck(glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE));
myTexture = static_cast<unsigned int>(Texture);
GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
}
}
Mipmapping would be on by default and you would need to add bool IsMipmapped() and SetMipmap(bool)
Please advise!
Thanks,
Dave
-
Mipmapping for 2D?? It wouldn't be used at all in SFML, and if you manage your textures externally... well, you manage them externally :)
If you're using sf::Image for your texture, you can still do it:
image.Bind();
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
-
Yeah I am doing that already, I figured since SFML seems to be somewhat tied to OpenGL it would be nice to have that built in, so one has less code to deal with and would look cleaner sending a flag vs. calling more GL functions for each bind...
Anyway thanks.
-
Yeah I am doing that already, I figured since SFML seems to be somewhat tied to OpenGL it would be nice to have that built in, so one has less code to deal with and would look cleaner sending a flag vs. calling more GL functions for each bind...
I understand your point of view, but SFML is not a general purpose OpenGL wrapper, it's not meant to make your OpenGL code nicer.
-
+1 for this feature, it would be very useful!
Mipmapping for 2D?? It wouldn't be used at all in SFML,
Why not? Any image I load from disk has a fixed resolution obviously, but the sizes at which it will be drawn on screen may vary greatly (depending on the sprite's scales at which I blit it, and to some extent the user's screen resolution).
When loading a large image (e.g. 800x600) and blitting it to a smaller area (say 80x60) the quality will *greatly* benefit from mipmapping (as opposed to only bilinear filtering, which happens by default).
If you're using sf::Image for your texture, you can still do it:
image.Bind();
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
Not quite sure where/how to do this, could you elaborate please?
I'm doing this:sf::Image myImage;
myImage.LoadFromFile("example.png");
Now what? Doing the code above didn't seem to make any difference.
Do I have to assign this image to a sprite in any special way, or do I have to Draw the sprite differently?
-
It's true that mipmaps could improve the 2D quality, I'll do some tests and add it if it's worth.
-
;) I say add it, simple flag should suffice!
BTW what is the status of flipping the image for OpenGL textures? Meaning the image is not lower left but upper left? I am guessing this is setup for DX and should be for GL... Please inform me as I need to figure out what I am to do wait for a update or 2.0 or move on...
-
I say add it, simple flag should suffice!
I'm even thinking about nothing at all in the public API (and removing SetSmooth as well): generating mipmaps + using NEAREST_MIPMAP_LINEAR should be ok for all situations (pixel perfect for scale 1, smoothed for scale < 1, no "big blur" for scale > 1).
That's why I was talking about tests ;)
BTW what is the status of flipping the image for OpenGL textures? Meaning the image is not lower left but upper left?
Well, I'm not convinced that there is a real problem with that. UV (0, 0) correctly maps to the pixel at (0, 0), not (0, height-1). So I'm not sure why people always complain about this stuff.
-
I would use GL_LINEAR_MIPMAP_LINEAR IMO....
THe issue with the image isn't the 0,0 origin, but the pixels are not correct. The image itself needs to be flipped on the Y axis. I am not using your texture coordinates for anything in my engine, and I still have to flip the image either myself, or use a paint program to flip it or else my model mesh will not be mapped correctly! So I beg you please flip the pixels after the image data is loaded with SOIL with a flag parameter that is set to default your way, but can be changed to meet others needs...
Thanks!
-
I would use GL_LINEAR_MIPMAP_LINEAR IMO....
Why?
THe issue with the image isn't the 0,0 origin, but the pixels are not correct. The image itself needs to be flipped on the Y axis.
That's what I meant: if the image is flipped on Y it means that bottom pixels are mapped to top texture coordinates.
But in all the tests that I did, it was not true. So instead of just saying "it doesn't work for me so please fix it", let's try to understand what's really wrong and find the real solution ;)
I am not using your texture coordinates for anything in my engine, and I still have to flip the image either myself
How do you create/load your mesh? Which file format?
-
I use ASSIMP SDK to load my meshes...
http://assimp.sourceforge.net/
My not use Trilinear mipmapping?
Thanks!
-
I use ASSIMP SDK to load my meshes...
http://assimp.sourceforge.net/
My not use Trilinear mipmapping?
Sorry, I don't understand. What do you mean?
-
I use ASSIMP SDK to load my meshes...
http://assimp.sourceforge.net/
My not use Trilinear mipmapping?
Sorry, I don't understand. What do you mean?
Lost me?
ASSIMP is the SDK to load my mesh files.... link shows that
And the mipmapping filtering I was stating use the best Image Quality possible...
Thanks!
-
Lost me?
Kind of. Sorry I had forgotten about the flipped texture thing, I thought your previous answer was all about mipmapping and I didn't understand what ASSIMP was doing here :D
And the mipmapping filtering I was stating use the best Image Quality possible...
Don't forget that in 2D we sometimes want 1:1 rendering (pixel perfect) compared to the original images. Using the "biggest" smooth filter available may not be the best option.
-
+1 :D
How is your testing? Any results?
-
Not yet, I'm working on something else.
-
I've done some tests today.
Here are my conclusions:
- Mipmapping doesn't help at all, it's even worse than bilinear filtering without mipmaps; I think it's just an optimization, it's not meant to provide better results
- I can't remove SetSmooth from sf::Image, hen scale is greater than 1 we really need both modes: when the sprite is aligned, smoothing off gives better results, but when a rotation is involved it's really ugly without smoothing.
-
I beg to differ. I just implemented mipmaps in my game and have seen far superior quality (at least on zoomed out views, such as minimaps).
It's such a simple change that it makes me wonder why it's not implemented. It's definitely very useful if you want to zoom out or scale down sprites.
And here's some screenshots for comparison:
Original: http://i.imgur.com/t9il2S9.png
Without: http://i.imgur.com/G0bUX8t.png
With: http://i.imgur.com/aaTswQd.png
Without: http://i.imgur.com/v4zCEFP.png
With: http://i.imgur.com/3rjNeXz.png
Without: http://i.imgur.com/lnv3ZoE.png
With: http://i.imgur.com/RNv6MIk.png
Without: http://i.imgur.com/noyWMsk.png
With: http://i.imgur.com/n3hfS4Y.png
I'm sure some may argue that without mipmaps you get more 'detail'. But this detail is pretty... unrealistic, as was as looking competely absurd when you do a smooth zoom: https://www.youtube.com/watch?v=JP108IQsA1o&feature=youtu.be
-
Maybe I'm missing something but to my eyes those screenshots seem to be supporting Laurent's view. The ones with mipmapping look more like solid green and gray blobs (especially that last one) than repeated grass and stone textures.
-
Look at the video and tell me that looks natural?
-
Yeah, zooming is definitely a problem, but making that smooth definitely doesn't justify the poor quality when not zooming. Unless the idea is to toggle mipmapping when the user starts and stops zooming.
Also, I know I've seen those strange zoom effects in quite a few professional games before, so maybe this problem is just too hard to solve in general.
-
They look exactly the same when you're not zoomed. It's looks slightly smoother when only zoomed out a bit, of which looks better then is a matter of taste.
My point isn't that mipmaps are good everywhere. They're good in some occasions, and some will just prefer them (as I do, and other in this thread have).
I'd rather have a simple toggle than writing my own mipmap functionality with just 5 lines on every texture I want it in.
-
https://github.com/SFML/SFML/pull/498
Suddenly mipmapping seems to be very popular :)
-
I did a little bit of research and found out that mipmaps are a good thing in general, but can look blurry when used, because they are build by averaging the pixels. Also for good results with non power of two textures or arbitrary scales, you must use polyphase filters.
Possible solutions for the blurriness are:
- Use premade mipmaps
- Use a sharpening algorithm like the Kaiser filter: Mipmapping, Part 1 (http://www.number-none.com/product/Mipmapping,%20Part%201/index.html)Mipmapping, Part 2 (http://www.number-none.com/product/Mipmapping,%20Part%202/index.html)
- Modify the mipmap bias (GL_TEXTURE_LOD_BIAS) http://www.opengl.org/registry/specs/EXT/texture_lod_bias.txt (http://www.opengl.org/registry/specs/EXT/texture_lod_bias.txt)
- Don't use mipmaps
Sources:
http://forums.tigsource.com/index.php?topic=26733 (http://forums.tigsource.com/index.php?topic=26733), http://developer.nvidia.com/content/non-power-two-mipmapping (http://developer.nvidia.com/content/non-power-two-mipmapping)
-
Mipmaps definitely help, even in 2D. I made a simulation called ALife (it's on these forums) where you can zoom in and out of the map. It looked absolutely terrible without mipmaps when zoomed out, but great with them.
Mipmaps apply whenever the image on the screen is scaled down from its actual resolution, something that also applies to 2D.
So yes, I am in favor of adding mipmaps to SFML :D
-
It would be nice if people took a deeper look, rather sooner than later, at not only that pull-request, but also to the other related commits in the further branch of my fork. With the current spin up in activity and the changes for mobile I would get sad when it bitrots, as I made an effort to have it nicely integrated with fitting API that enables use of all mipmap-modes and writing some help text.
Btw, adding on loading of premade mipmaps would be a good addition later on.
-
We will certainly have a look at it, but at the moment the top priority is preparing the release of SFML 2.2 (and organizing the whole development/team)... So please have some patience :)
-
Mipmapping doesn't help at all, it's even worse than bilinear filtering without mipmaps; I think it's just an optimization, it's not meant to provide better results
I understand that I reply to 12yo topic, but! Of course mipmaps is for better results. If you're showing texture that has bigger resolution than you're drawing on screen - you absolutely need mipmaps. If you're drawing 512x512 texture in 32x32 square, what do you expect your GPU to do? It will just sample 32x32 pixels from 512x512 image, basically "skipping" the rest of the pixels, creating a noisy mess. And if move it - it's even worse, because those choosen 32x32 will changed every frame. What you want - is to sample 32x32 pixels from 32x32 image. Which is what mipmaps do for you. Cases where you don't need mipmaps are EXTREMELY rare.
-
Not exactly sure what we gain from that necropost, but just in case you missed it, SFML can generate mipmaps: sf::Texture::generateMipmap() (https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1Texture.php#a7779a75c0324b5faff77602f871710a9). ;)