Jump to content
  • Advertisement
Sign in to follow this  
deadimp

Direct3D Questions for 2D - Sprite Frames and Screen Coords

This topic is 4875 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
Advertisement
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:

// SIMPLE 2D COORDINATE
struct _2D_COORD
{
float x, y, z, rhw; // positions, rhw (1 for pretransformed)
float u, v; // texture coordinates;
};
// Appropriate vertex declaration
#define D3DFVF_TRANSTEXT (D3DFVF_XYZRHW|D3DFVF_TEX1)

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,

ace

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 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!