Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know that is there any way of resizing our texture to the size of a sprite in slimdx direct3d9 or directx9. That is if my image size is 1024x768 and sprite size is 500x500, how can i resize the image in slimdx to display it fully on the sprite without any cropping.

share|improve this question
why would you want to resize it, you can draw any texture size on any sprite size without texture being cropped. – Ali.S Sep 30 '11 at 19:17
up vote 2 down vote accepted

Unless the sprite image is itself part of a larger image (see "sprite sheets"), you don't need to do any resizing of the image at runtime. You can simply adjust the geometry of the quad you are rendering so that it appears the desired size, in pixels, in your final render.

How exactly you do this depends on how exactly you are setting up your rendering pipeline (in particular, the values of the vertices you are using in your vertex buffer and the way you've configured your transformation pipeline matrices), so it's not possible to give an authoritative answer with the information you've provided. That said, it's common to either arrange for your vertices to be pre-transformed (that is, already specified in the [-1, 1] or [0,1] range) and then scale them by the render target width to obtain pixel positions, or to use pixel coordinates for the geometry in the vertex buffers and transform them in a vertex shader into clip space. In the latter case you'd simply set your vertices to be a 500x500 pixel square.

So long as you do not adjust the texture coordinates -- that is, make sure they span the full [0,1] range of the texture -- you'll get your image scaled down.

However, it's worth noting two things:

  1. Scaling a 1024x768 image on to a 500x500 render area will distort the image (because the aspect ratio does not match).
  2. If you are never going to display the 1024x768 image at its native pixel resolution, there is no reason to waste the time and memory loading an image at that resolution; you should downsize the asset (before the game is even built) to the correct, desired pixel size and you will avoid this problem entirely.

All of that being said, if you really want to manipulate the bitmap at runtime, you can lock the texture, read the bits out of it, create a bitmap object, and use that to scale the image as desired. Then you can create a new texture, lock it, and copy the bits back in.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.