Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Extra-smooth textures  (Read 5679 times)

0 Members and 1 Guest are viewing this topic.

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Extra-smooth textures
« on: November 11, 2011, 04:58:36 pm »
I'm developing a game with SFML(.Net) 2.0 and almost all of my textures have "Smooth = true;" set when they are loaded.
While the appearance is generally good(for instance, zooming in gives the smooth appearance I want), the zoom-out appearance doesn't look smooth enough.
I'd like to make the zoomed out appearance more smooth. Is there any way to do this? (Maybe using OpenGL API calls since SFML smooth doesn't seem to be enough?)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Extra-smooth textures
« Reply #1 on: November 11, 2011, 05:03:47 pm »
I don't know if there's something better.

In 3D (or 2D with depth), mipmaps are used for this purpose. Maybe you can fake them with SFML (ie. generate smaller versions of the texture, and use them when the zoom factor is small enough)?
Laurent Gomila - SFML developer

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Extra-smooth textures
« Reply #2 on: November 11, 2011, 06:15:06 pm »
Is there any chance you could add mipmap support to SFML(Texture's constructor, maybe?)
From what I'm reading here, it should be only a few extra lines of code (GL_GENERATE_MIPMAP for OpenGL>=1.4 and glGenerateMipmap for OpenGL>=3.0)...

I managed to get it to work, but it looks really ugly.
Anyway, this is what I have now(and it does give me the results I want), if anyone else is interested:

(in C# using Tao.OpenGL via OpenTK.Compatibility)
Code: [Select]

string texPath = "hello-world.png";
using (var img = new Image(texPath))
{
var tex = new Texture(img);
tex.Smooth = true;
tex.Bind();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_GENERATE_MIPMAP, Gl.GL_TRUE);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);

tex.Update(img);
//Store tex somewhere
}


I can say that it's not just 3D games that benefit from mipmaps, that's for sure.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Extra-smooth textures
« Reply #3 on: November 11, 2011, 06:43:35 pm »
How do you use the texture? I thought that mipmapping worked only if depth information was used -- which SFML doesn't.
Laurent Gomila - SFML developer

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Extra-smooth textures
« Reply #4 on: November 11, 2011, 06:49:18 pm »
Why would depth information be required?
I certainly did not enable the depth buffer since I use translucency a lot.

To use the texture, I use the ordinary Sprite API:

Code: [Select]

t = img.GetTextureForName("Interface/TileOutline");
using (var spr = new Sprite(t))
{
spr.Position = pos;
spr.Origin = new Vector2f(128, t.Height / 2);
spr.Scale = new Vector2f(zoomLevel, zoomLevel);
spr.Color = color;
info.Target.Draw(spr);
}


Where info.Target is a RenderWindow, GetTextureForName gives me a texture stored in a IDictionary<string, Texture>, which is previously populated using the code I showed before.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Extra-smooth textures
« Reply #5 on: November 11, 2011, 07:49:07 pm »
Oh, ok :)
Laurent Gomila - SFML developer

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Extra-smooth textures
« Reply #6 on: November 11, 2011, 08:23:06 pm »
So can we expect "native" mipmapping in a future SFML version?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Extra-smooth textures
« Reply #7 on: November 11, 2011, 09:12:48 pm »
I must test it first. You can add a request in the issue tracker on github.
Laurent Gomila - SFML developer

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Extra-smooth textures
« Reply #8 on: November 11, 2011, 10:23:51 pm »