ID3DXSprite is not working?

Started by
13 comments, last by Cambo_frog 19 years, 5 months ago
OK Mikey,

I have never used Managed DirectX or .Net languages in any way ( I use C++ for DirectX apps ) so that makes it a bit more difficult.

Quote:
1) Yes.. but not SetTransform(), there is a read/set Transform property


This definately sounds like the managed equivalent of the C++ function ID3DXSprite::SetTransform(). Try setting this property before you call the C# equivalent of ID3DXSprite::Begin(). I am not saying it will work, but I am thinking it is best to explore all possibilities.

Quote:
3) (I'm using C#/MDX)
flareTest.Begin(SpriteFlags.SortTexture | SpriteFlags.ObjectSpace);

Sprite.Transform = Matrix.Scaling(0.02f, 0.02f, 0.02f);

Sprite.Draw(Texture, new Rectangle(0, 0, 32, 32), new Vector3(16, 16, 0), new Vector3(0, 0, 0), Color.Gray);

flareTest.End();


These lines look OK, but I can't be sure because I don't use C#

Quote:
So, to 'Add a sprite to the list of batched sprites.', I need to call Draw(), but for each sprite do I need to do a Begin() and End()? If each End() call 'Restores the device to the state it was in before', wouldnt doing Begin() and End() for each sprite be inefficient?


As I read it, you can draw the same sprite object several times between Begin and End with different state/properties/textures.

If you use several different sprite objects, you will need to call Begin and End for each sprite object.

I will try and write a test app tomorrow to solve the problem.
If I find solution I will post the code in C++ and hopefully someone can convert to C# for you.

If I don't find a solution, I will let you know anyway.

HTH,
Cambo_frog
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
Advertisement
Yeah, nevermind about the begin() end() stuff, I'm an idiot:)

C# and C++ aren't so different, I can interpret the C++ and figure out the C# pretty easily. Anyway, dont worry about the C++.
Quote:Original post by MikeyO
Yeah, nevermind about the begin() end() stuff, I'm an idiot:)

C# and C++ aren't so different, I can interpret the C++ and figure out the C# pretty easily. Anyway, dont worry about the C++.


Ok I just tried creating a scale transform:

D3DXMATRIX spriteScaleMatrix;
D3DXMatrixScaling( &spriteScaleMatrix, 0.02f, 0.02f, 0.02f );

Then setting the sprite transform:
pSprite->SetTransform( &spriteScaleMatrix );

works for me setting the transform between Begin and End or before Begin, both work.

note If you use the scaling you specified (0.02f) which would make your texture 1/50th of its original size, and if the size of the texture was say 32 X 32 as in your original example, your sprite would be displayed as a single pixel (or less!)

HTH,
Cambo_frog

[Edited by - Cambo_frog on November 8, 2004 6:59:50 PM]
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
Actually, when I was rendering it like that without the scaling it was taking up more than the whole screen (probably too close to the camera), so 0.02 made it so you could actually see the whole thing..

Do I need to set the worldspace/billboard for scaling?
Quote:Original post by MikeyO
Actually, when I was rendering it like that without the scaling it was taking up more than the whole screen (probably too close to the camera), so 0.02 made it so you could actually see the whole thing..


I don't think the distance from the camera would make any difference so the scaling of the sprite when rendering in screen space.

When you specified your rectangle:
new Rectangle(0, 0, 32, 32),

This would use the 32 x 32 pixel block from the top left corner of the texture, which should easily fit the screen without any scaling.

Quote:
Do I need to set the worldspace/billboard for scaling?


No, I just used the C++ equivalant of the flags you used:
D3DXSPRITE_ALPHABLEND|D3DXSPRITE_SORT_TEXTURE

It also works for me with flags set to 0.

**** Edit ******

Also try using the position parameter of the Draw function instead of the center parameter to position the sprite.

When you use:

Sprite.Draw(Texture, new Rectangle(0, 0, 32, 32), new Vector3(16, 16, 0), new Vector3(0, 0, 0), Color.Gray);

Are you trying to make the sprite entirely visible in the top left corner of the screen?

If so, then it would not work. Try:

Sprite.Draw(Texture, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.Gray);

or pass NULL (or C# equivalant) in the position and center parameters.

If you want to position the sprite using its center at say x,y
and use the entire texture

You could use:
Sprite.Draw(Texture, new Rectangle(0, 0, texture_width, texture_height), new Vector3(texture_width / 2, texture_height / 2, 0), new Vector3(x, y, 0), Color.Gray);

But this will not work when correctly when using scaling (other than 1.0)


****************

HTH,
Cambo_frog

[Edited by - Cambo_frog on November 9, 2004 3:17:33 AM]
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.

This topic is closed to new replies.

Advertisement