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

Author Topic: Pixel perfect texture blitting?  (Read 4272 times)

0 Members and 1 Guest are viewing this topic.

MasterQ32

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • MasterQ32.de
Pixel perfect texture blitting?
« on: July 14, 2013, 02:42:18 pm »
Hey!

I'm new to SFML and just migrate my current project to it. I previously used SDL for drawing and event management but it has some flaws like missing keyboard input and other things.
My project is written in C# with SFML.Net, but i think this doesn't matter in my case. I compose a lot of graphics in my project from one source texture. With SDL it looked really good, but now i have the problem that seams appear in my GUI system:


That's the code i use to draw a texture on the screen:
public static void DrawTexture(
        RenderTarget target,
        Texture texture,
        IntRect targetPos,
        IntRect? sourcePos,
        bool tileTexture)
{
        texture.Repeated = true;
        texture.Smooth = false;
        using (Sprite sprite = new Sprite(texture))
        {
                if (sourcePos != null)
                        sprite.TextureRect = sourcePos.Value;
                else
                        sprite.TextureRect = new IntRect(0, 0, (int)texture.Size.X, (int)texture.Size.Y);

                sprite.Position = new Vector2f(targetPos.Left + 0.5f, targetPos.Top + 0.5f);
                if (!tileTexture)
                {
                        sprite.Scale = new SFML.Window.Vector2f((float)targetPos.Width / sprite.TextureRect.Width, (float)targetPos.Height / sprite.TextureRect.Height);
                        sprite.Draw(target, RenderStates.Default);
                }
                else
                {
                        sprite.Scale = new Vector2f(1, 1);
                        while (sprite.Position.X <= targetPos.Left + targetPos.Width - sprite.TextureRect.Width)
                        {
                                sprite.Draw(target, RenderStates.Default);
                                sprite.Position = new Vector2f(sprite.Position.X + sprite.TextureRect.Width, sprite.Position.Y);
                        }
                }
        }
}

Is there any way to get SFML to create pixel perfect graphics?

Greetings
Felix Qu.
I sawed the demons.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Pixel perfect texture blitting?
« Reply #1 on: July 14, 2013, 02:49:05 pm »
I wouldn't use repeating texture if you really want, what you do.
If you want to work with one textures you can use a RenderTexture to draw go, but you can also simply draw the snippet as man times as you want. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MasterQ32

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • MasterQ32.de
Re: Pixel perfect texture blitting?
« Reply #2 on: July 14, 2013, 03:22:29 pm »
Thanks for the fast answer!
I just looked into the features of a RenderTarget and found out that i can draw vertices. This would fit my needs perfectly and should be faster as well (way lesser draw calls).
I think i got it running now.
I sawed the demons.

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Pixel perfect texture blitting?
« Reply #3 on: July 22, 2013, 07:56:06 pm »
I previously used SDL for drawing and event management but it has some flaws like missing keyboard input and other things.

Off topic, but I'm curious: In what way does SDL not have keyboard input support?

MasterQ32

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • MasterQ32.de
Re: Pixel perfect texture blitting?
« Reply #4 on: July 22, 2013, 08:18:49 pm »
I only found 2 C# wrappers for SDL and one was unusable and the other had no Text/Unicode input option so i would've built my own IME system.
I sawed the demons.

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Pixel perfect texture blitting?
« Reply #5 on: July 22, 2013, 09:12:51 pm »
Was one of them this one? In any case, if you need full IME/composition support, I guess yeah, you're on your own with either SDL or SFML =/

MasterQ32

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • MasterQ32.de
Re: Pixel perfect texture blitting?
« Reply #6 on: July 22, 2013, 10:20:48 pm »
no, it was cs-sdl.
But i got IME with SDL working, so my problem is solved
I sawed the demons.

 

anything