Advertisement Jump to content
Sign in to follow this  

Direct3D Questions for 2D - Sprite Frames and Screen Coords

This topic is 4969 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

I have two questions for Direct3D for 2D graphics. Please note that I am only just beginning to start 3D programming and Direct3D, so I'm not too savy on many a topic. 1) Is there some way to apply only a section of a texture, instead of having to create multiple textures using locking and unlocking, like IDirectDrawSurface::Blit and source/destination rectangles? I am using the Blit function from the tutorial Dissecting Sprites in Direct3D 2) I thought I remembered (when I had examined some tutorials here) some sort of flag in the initialization of Direct3D that made it to where the coordinates were screen coordinates, instead of having to calculate what a screen coordinate would be in the floating-point coordinate system. Is there actually such a flag that eliminates that extra calculation, or do I have to do it manually? Please correct my errors, numerous as they may be.

Share this post

Link to post
Share on other sites
1) To apply only portions of a texture simply use fractions for the float value. Like if you wanted to start half way accrossa texture make the left hand x valued 0.5 etc.

2) You have to tell D3D not to transform the vertices by the world matrix and this is done by doing the following:

struct _2D_COORD
float x, y, z, rhw; // positions, rhw (1 for pretransformed)
float u, v; // texture coordinates;
// Appropriate vertex declaration

Thats an example vertex struct.

The coordinates are floats and their values are the locations on the back buffer x-pixels by y-pixels.

Hope this helps,


Share this post

Link to post
Share on other sites
Thanks for the reply.
So the fractional coordinates would belong in the variables "u" and "v"? This what he (author of the article) has when structuring a quad:
D3DTLVERTEX vertices[4] =	{
// x, y, z, rhw, colour, tu, tv
{ left, top, z, rhw, colour, 0, 0 }, //It's the last two, right?
{ right, top, z, rhw, colour, 1, 0 },
{ right, bottom, z, rhw, colour, 1, 1 },
{ left, bottom, z, rhw, colour, 0, 1 } };

Also, for the vertices, the author of "Dissecting Sprites in Direct3D" uses a whole bunch of complex (to me) computations dealing with matrices and stuff like that... Why does it need a matrix when it's only two-dimensional?

Sorry if I'm being somewhat difficult.

EDIT: Ah, you were right about the portion coordinates. Thanks.

EDIT (AGAIN): I'm starting to see, now that I can actually think (yay Dr. Pepper!), what the transformations and such do. Probably need to look at it some more.
Thanks for your help.

However, I have one more question: When exactly do I need to be sure to keep a texture that's dimensions are a power of two? His (the author again) sprite's size is 32x40 and it doesn't seem distorted or fuzzy at all...

Share this post

Link to post
Share on other sites
From my experience i can tell you there is nothing complicated about gett quads in 2D, u simply set the RHW values to 1 so that the xyz values are not transformed by the world matrix

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!