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

Author Topic: Weird Sprite draw behavior with RenderTexture upon resizing the window  (Read 1965 times)

0 Members and 1 Guest are viewing this topic.

coretradict

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hello everyone!

My goal is to have a PixelSize setting. I am very new to SFML (I am having a blast so far, even as a newbie) and I've been trying to get the RenderTexture working with Sprites.

Drawing the sprites on the RenderTexture itself didn't work because interacting with the View does not seem to draw the Sprites differently (perhaps I am missing something? please point it out if so). So after some browsing I stumbled upon another approach in the forums: drawing the Sprite on the RenderWindow and setting the RenderTexture to what's already on the RenderWindow then drawing the RenderTexture back to the RenderWindow.

while (window.IsOpen)
{
        window.DispatchEvents();

        // some "camera" behavior
        view.Move(new Vector2f(0, 0.05f));
        view.Zoom(0.9999f);
        view.Rotate(0.1f);
        window.SetView(view);

        window.Clear();

        rendSprite.Position = camera.Center;    // "parenting" the Sprite of the RenderTexture to the View
        rendSprite.Rotation = camera.Rotation;  // so that it is not treated as an ingame object
        rendSprite.Scale = new Vector2f(VideoMode.DesktopMode.Width  / camera.Size.X,
                                        VideoMode.DesktopMode.Height / camera.Size.Y);

        sprite.Position += new Vector2f(0.1f, 0);       // moving &
        window.Draw(sprite);                            // drawing some sprite

        var vert = new Vertex[]
        {
                new Vertex(new Vector2f(0, -50), Color.Red),
                new Vertex(new Vector2f(50, 0), Color.Green),
                new Vertex(new Vector2f(0, 50), Color.White),
                new Vertex(new Vector2f(-50, 0), Color.Blue),
        };
        window.Draw(vert, PrimitiveType.Quads);

        rendTexture.Texture.Update(window);
        rendTexture.Display();
        window.Clear(Color.Black);
        window.Draw(rendSprite);
        window.Display();
}
 

All of this seems to be working until resizing/maximizing the window.
(it seems like only the zooming is working as intended):
https://i.imgur.com/kiMGbFb.mp4

I am aware my approach is bad, I would really appreciate if someone points out a fix/solution/new approach. Or if I can somehow get the View's Transform in C# (I saw it is possible in the C++ docs) so I can draw the Sprites according to it. Please point me towards a direction or explain some proper way of handling RenderTextures + Views + Sprites. Thanks!

 

anything