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

Author Topic: Sprite rendering messed up.  (Read 4833 times)

0 Members and 1 Guest are viewing this topic.

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Sprite rendering messed up.
« on: April 28, 2013, 01:37:29 am »
I am creating a small game engine using SFML in C#, when the engine is rendering a sprite it draws it messed up and not scaled correctly, it is to thin and to small. I tried to use the scale function, but it seems to be a different amount for each image.

Here is my code:
        public void SetImage(string file)
        {
            Drawing.Texture ImageLoaded = new Drawing.Texture(file);
            ImageFile = new Drawing.Sprite(ImageLoaded);

            Width = (int)ImageFile.Texture.Size.X;
            Height = (int)ImageFile.Texture.Size.Y;

            ImageFile.Position = new Vector2f((float)RealX, (float)RealY);
        }
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #1 on: April 28, 2013, 09:46:08 am »
Can you please show a complete and minimal code that reproduces the problem? By minimal I mean a simple Main() with a sprite, not your game engine ;)
Laurent Gomila - SFML developer

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Re: Sprite rendering messed up.
« Reply #2 on: April 28, 2013, 03:38:01 pm »
Can you please show a complete and minimal code that reproduces the problem? By minimal I mean a simple Main() with a sprite, not your game engine ;)
Ok, Is this what you need?

        static void Main(string[] args)
        {
            ImageTexture = new Texture("Image File Path");
            ImageFile = new Sprite(ImageTexture);

            Width = ImageFile.Texture.Size.X;
            Height = ImageFile.Texture.Size.Y;

            FormControl.Draw(ImageFile);
        }
 

If it is not than I have add code for what is going on in the parts of the engine.

Opening the window:
FormControl = new RenderWindow(VideoMode.Desktop, "Window Caption");
FormControl.Size = new Vector2u((uint)FormWidth, (uint)FormHeight);
 

The two classes used for drawing objects to screen:
private Sprite ImageFile;
private Texture ImageTexture;
 

Loading the Image:
ImageTexture= new Texture("The image file.");
ImageFile = new Sprite(ImageTexture);

Width = ImageFile.Texture.Size.X;
Height = ImageFile.Texture.Size.Y;

ImageFile.Position = new Vector2f((float)X, (float)Y);
 

Drawing the Image:
Core.FormControl.Draw(ImageFile);
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #3 on: April 28, 2013, 03:58:10 pm »
Complete and minimal really means complete and minimal. Please read this: http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368
Laurent Gomila - SFML developer

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Re: Sprite rendering messed up.
« Reply #4 on: April 29, 2013, 12:54:21 am »
Complete and minimal really means complete and minimal. Please read this: http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368
Ok, I think I got what you want.
        static void Main(string[] args)
        {
            FormControl = new RenderWindow(VideoMode.DesktopMode, "Test");
            FormControl.Clear(Color.Black);

            ImageTexture = new Texture("test.bmp");
            ImageFile = new Sprite(ImageTexture);

            FormControl.Draw(ImageFile);
        }
 

EDIT: I am using SFML 2.
« Last Edit: April 29, 2013, 02:21:39 am by void() »

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Sprite rendering messed up.
« Reply #5 on: April 29, 2013, 07:25:56 am »
Hello, I think you missed FormControl.Display() at the end (after all draw calls).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #6 on: April 29, 2013, 07:59:44 am »
Thanks.

Can you now post a screenshot of the original texture, and of the result after drawing it with this code?
Laurent Gomila - SFML developer

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Re: Sprite rendering messed up.
« Reply #7 on: April 29, 2013, 10:56:43 pm »
Thanks.

Can you now post a screenshot of the original texture, and of the result after drawing it with this code?
Ok, I got it here: https://www.dropbox.com/s/zwxasghbz33uiaz/ErrorPic.jpg

I think the problem is coming from the texture object and not the sprite.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #8 on: April 29, 2013, 11:54:00 pm »
Your code uses the desktop mode, but your window is smaller... is it really this piece of code that generates this output?
Laurent Gomila - SFML developer

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Re: Sprite rendering messed up.
« Reply #9 on: April 30, 2013, 01:35:10 am »
Your code uses the desktop mode, but your window is smaller... is it really this piece of code that generates this output?
Yes, I also use this:
FormControl.Size = new Vector2u((uint)FormWidth, (uint)FormHeight);

I think it might be the window or do I have to do something with the viewpoint? So far I have not needed to use the viewpoint at all and have not made a call to it. I hope this helps.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #10 on: April 30, 2013, 08:00:45 am »
Please... give the exact and complete source code and the matching result.
Laurent Gomila - SFML developer

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Re: Sprite rendering messed up.
« Reply #11 on: April 30, 2013, 11:17:11 pm »
Please... give the exact and complete source code and the matching result.
Ok, I removed the things that did not effect the result, to make it a bit shorter.
Link: https://www.dropbox.com/s/oj3mp05t8m11jcp/PantherEngine.zip

P.S: Great work o SFML! I love it.
« Last Edit: April 30, 2013, 11:33:43 pm by void() »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #12 on: May 01, 2013, 08:44:56 am »
If you need to put it in an archive, it's already too big. Can't you reproduce your problem in a simple Main() with few lines of code?

If you don't spend some time to properly find out what part of your code is wrong, and extract a minimal example from your project, nobody will be able to help you.
Laurent Gomila - SFML developer

void()

  • Newbie
  • *
  • Posts: 8
  • Console.WriteLine("C#");
    • View Profile
Re: Sprite rendering messed up.
« Reply #13 on: May 01, 2013, 09:47:28 pm »
If you need to put it in an archive, it's already too big. Can't you reproduce your problem in a simple Main() with few lines of code?

If you don't spend some time to properly find out what part of your code is wrong, and extract a minimal example from your project, nobody will be able to help you.
Sorry, but Drop Box makes me archive it in order for it to download properly. The test.bmp image can be replaced with any other image, the download of the code below includes it.

Here is the minimal code:
        static RenderWindow FormControl;
        static Texture ImageLoaded;
        static Sprite ImageFile;

        static void Main(string[] args)
        {
            FormControl = new RenderWindow(VideoMode.DesktopMode, "Error Example");
            FormControl.Size = new Vector2u(640, 480);

            FormControl.SetFramerateLimit(30);

            ImageLoaded = new Texture("test.bmp");
            ImageFile = new Sprite(ImageLoaded);

            ImageFile.Position = new Vector2f(32, 32);

            FormControl.Clear(Color.Black);

            ImageFile.Draw(FormControl, RenderStates.Default);

            FormControl.Display();

            Console.ReadKey();
        }
 
Download to code above:
https://www.dropbox.com/s/58ckrxn0ltib5xa/ErrorExample.zip?m=&v=0mwns

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sprite rendering messed up.
« Reply #14 on: May 01, 2013, 10:53:31 pm »
Have you tried to create a window smaller than the desktop?

What's your OS?
Laurent Gomila - SFML developer