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

Author Topic: Entire screen is flipped on Y axis!  (Read 1310 times)

0 Members and 1 Guest are viewing this topic.

Noogai03

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Entire screen is flipped on Y axis!
« on: June 09, 2017, 04:45:53 pm »
I'm totally mystified!
I'm using SFML.Net, and my entire window seems to have got flipped somehow on the Y axis?

The only thing I could see that could be causing it is RenderTextures - I'm rendering my entire game to a RenderTexture, then updating a Sprite's texture with it, scaling by 2 with smoothing off and then rendering the sprite - for pixelly scaling in a retro styled game

Somewhere along the way it's flipped the Y axis though! Am I doing this right (could this be done better with Views?) - and do you have any idea what the issue is?
I've put my two classes dealing with rendering in code blocks below.

Code:

Game.cs:
class Game
    {
        RenderWindow window;
        List<Entity> entities;
        Tilemap tilemap;
        VertexArray verts;
        RenderTexture buffer;
        Sprite bufferSprite;
        CircleShape circle;

        private int[] tiles = new int[]
        {
            13, 3, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
            1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0
        };

        public Game(RenderWindow window)
        {
            this.window = window;
            tilemap = new Tilemap();
            tilemap.LoadContent("res\\img\\tiles_packed.png", tiles);
            entities = new List<Entity>();
            verts = new VertexArray(PrimitiveType.Quads, 4);

            buffer = new RenderTexture(window.Size.X / 2, window.Size.Y / 2);
            buffer.Smooth = false;

            circle = new CircleShape(50);
            circle.FillColor = Color.Green;
            circle.Position = new Vector2f(200, 50);

            bufferSprite = new Sprite(buffer.Texture);

            //buffer.
        }

        public void Update(float dt)
        {
            //entities.Where(x => x is IUpdateable).
            for (int i = 0; i < entities.Count; i++)
            {
                entities[i].Update(dt);
            }
        }

        public void Draw()
        {            
            window.Clear(Color.White);
            buffer.Clear(Color.White);
            for (int i = 0; i < entities.Count; i++)
            {
                entities[i].Draw(buffer);
            }
            buffer.Draw(tilemap);

            buffer.Draw(circle);



            // scale buffer 2x
            //bufferSprite = new Sprite(buffer.Texture);
            bufferSprite.Texture = buffer.Texture;
            bufferSprite.Scale = new Vector2f(2, 2);
           
           
            //RenderStates states = new RenderStates()
            window.Draw(bufferSprite);
            //window.Draw(verts);
        }
    }
 

Program.cs (contains entry point)
class Program
    {
        static void Main(string[] args)
        {
            RenderWindow window;
            window = new RenderWindow(new VideoMode(800, 600), "Mine cart madness");

            window.Closed += Window_Closed;

            float dt = 1.0f / 60.0f;
            float accumulator = 0;
            Clock clock = new Clock();

            Game game = new Game(window);
           

            while (window.IsOpen)
            {
                Time elapsed = clock.Restart();
                float elapsedTime = elapsed.AsSeconds();
                accumulator += elapsedTime;
                while (accumulator > dt)
                {
                    accumulator -= dt;
                    window.DispatchEvents();
                    game.Update(dt);
                }

                game.Draw();
                window.Display();
            }
        }

        private static void Window_Closed(object sender, EventArgs e)
        {
            ((RenderWindow)sender).Close();
        }
    }
 

Any ideas?

EDIT: output:


That circle is centred at 200, 50!

« Last Edit: June 09, 2017, 04:49:10 pm by Noogai03 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Entire screen is flipped on Y axis!
« Reply #1 on: June 09, 2017, 06:52:15 pm »
buffer.Display()
Laurent Gomila - SFML developer

Noogai03

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Entire screen is flipped on Y axis!
« Reply #2 on: June 09, 2017, 07:12:52 pm »
thanks :)