Jump to content
  • Advertisement
Sign in to follow this  

Spline positioning problem after scaling

This topic is 2772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all.

I have a control (picturebox), in which I want to draw 2D images (splines) at different positions (some kind of VNC - updating different rectangles) with the help of DirectX.

When I receive the first image, I must resize it to fit picturebox' size, and than resize other images with this scale. I've written the following code to complete it:

void InitializeGraphics()
// Set our presentation parameters
var presentParams = new PresentParameters() ;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.Windowed = true;

// Create our device
_device = new Device(0, DeviceType.Hardware, pictureBox1,
CreateFlags.SoftwareVertexProcessing, presentParams);
_sprite = new Sprite(_device);

Matrix GetTransformationMatrix(float width, float height)
var scaleWidth = _currentWidthScale = pictureBox1.Width / width;
var scaleHeight = _currentHeightScale = pictureBox1.Height / height;
return Matrix.Scaling(scaleWidth, scaleHeight,1.0F );

Texture LoadTexture(string path)
return TextureLoader.FromFile(_device, path);

public void Draw()
using(var texture = LoadTexture())

Rectangle textureSize;
using (var s = texture.GetSurfaceLevel(0))
SurfaceDescription desc = s.Description;
textureSize = new Rectangle(0, 0, desc.Width, desc.Height);
_sprite.Transform = GetTransformationMatrix(textureSize.Width, textureSize.Height);
Vector3 position = new Vector3(_currentPositionX, _currentPositionY, 1F);

_sprite.Draw(texture, textureSize, _center, position, Color.White);

Scaling works fine. The problem is with the position . For example, when the first image is 1280x800, and I try to place the small second scaled image on {currentPositionX=640,currentPositionY=400} , it doesn't locate correctly and draw it on some another place. I've spent an hours thinking about this behavior but still have no decision. When scaling is off, everything locates fine.

Any help greatly appreciate.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!