简体   繁体   中英

How to prevent automatic scaling of my Image drawn inside a RenderWindow?

I am using SFML.Net 2.4 with C#

I have a RenderWindow of size 1000x1000 inserted into a System.Windows.Forms.Form this way:

public class ViewForm : Form
{
   SFML.Graphics.RenderWindow _renderWindow = null;
   public ViewForm()
   {
      _renderWindow = new RenderWindow(this.Handle);
   }
}

In my drawing function, I simply draw an image using a sprite:

    _renderWindow.DispatchEvents();
    _renderWindow.Clear(Color.Black);
    Image     img = new Image(path);
    Texture   tex = new Texture(img);
    Sprite    sprite = new Sprite(tex);
    _renderWindow.Draw(sprite);
    _renderWindow.Display();

My problem is that when displayed, this sprite takes the largest dimension it can by default (ie 1000 here) whereas the base image is only 100 pixels high (no stretching, but automatic rescaling nonetheless).

I don't want to have to reverse the auto-scaling myself... how can I keep the original dimensions of my image?


I did a test: to display a sprite correctly in a RenderWindow (running on its own, this time, not embedded in a winform), I had to apply a scale following this rule:

sprite.Scale = new SFML.System.Vector2f(myScreenWidth / 1000f, myScreenHeight / 1000f);

My screen size is 1920x1080, hence I had to apply a scale of (1.92 ; 1.08) to the sprites... WTF?

The issue was that I was changing the size of my ViewForm after having passed its handle to SFML with :

new RenderWindow(this.Handle);

I was then doing :

this.Width = (int)finalWidth;
this.Height = (int)finalHeight;

Now, when my Form changes size, I dispose then reinstantiate SFML's RenderWindow. And it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM