How do I resize D3D9 Textures?

Virgo
03-03-2004, 03:58 AM
How do I resize textures with D3D9? I'm coding a tile engine and use character sets and tilesets.

Before, when I used DDraw7 and surfaces, it was easier because my source rect variables were only needed for the sprites. Now with D3D9, I need to actually change the source rect for the texture. For example:

I have a character set which is 2x4 tiles each tile 32 pixels. Horizontally for each walking frame, vertically for each direction. When I create the texture, It automatically stores the size of the texture to 64x128. Now when I draw this texture to the screen, it will show the whole character set.

So I need to resize the texture to a 32x32 chunk depending on the animation frame and direction. This means I need to access the texture and resize it each time. I've looked all over and can't find how to resize the texture object.

On a side note, this seems non-efficient. Suppose I have a soldier texture, and 50 soldier sprites all moving around on screen at the same time. These 50 soldiers all use this one texture, but each has a different source rect, based on their direction and animation. I would need to access the texture object and change it's size many times per frame.

With DDraw7 and surfaces, It was easier, because I only needed to keep a source rect variable for each sprite, and draw chunks from the character set. The main difference, is that I'm not accessing the texture and resizing it, I'm just changing the parameters from which to draw from (source rect).

So my second question is, is there a better way in handling D3D9 textures or am I forced to resize the texture each time?

Xebec
08-21-2004, 01:32 AM
well from my limited experience...

when your drawing a sprite using Sprite.Draw, something like...

sprite.Draw(texture,new Rectangle(srcpoint,srcsize),v3center,v3position,Color.White);

the Rectangle defines which portion of the texture you wish to draw - in your case you would set its size to 32x32 then adjust the point according to which frame you wantto draw(all within the same co-ordinate space as your texture...so first frame would be point(0,0) second frame point(32,0) etc). As for scaling the sprite just apply a scaling transform prior to the draw.

hehe kind of new to this stuff meself so hope that helps :)

Xeb

ed:

doh...my bad..this post was from ages ago...thats what I get for posting so early in the morning...apologies :(

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum