Jump to content
  • Advertisement
Sign in to follow this  
Kija

ID3DXSprite

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

Hello, I'm creating a GUI system using ID3DXSprite, I have a few question, first of all, the z value of the sprite, I can't get it to work. I've tried several different values, seems like the range is between 0.0 and 1.0? But I always get them ordered in the way they're rendered. Which isn't that bad, however it would be nice to skip the z sort of objects. Should it be possible to render with a z value between 0.0 and 1.0? And do I have to begin + end between every or maybe I must do them in a single begin + end pass to be able to use the z order. Question number two: I'm using a font class for rendering text, and I want to use it to write _on_ the sprites, like a caption on a button. If I do sprite->Begin(0); BlitSprite(); sprite->End(); font->Print("bla"); it works, but I have to end the sprite. And I would really like to call a function that firsts blits the sprite and then prints a text on it. A button with caption for example. So this means I would have to do sprite->Begin(0); and sprite->End(); for every sprite... That could be hundreds per frame. And I guess I could render all the sprites first, then end, then print all the text but I would prefer it the other way. Is this how it should be or maybe I've designed my font class wrong? And finally, someone mentioned batching of sprites, what does this mean? I haven't found much any resources on ID3DXSprite, otherwise they would probably have answered these questions.

Share this post


Link to post
Share on other sites
Advertisement
Try to do just one begin and one end with one sprite interface object for all your 2D drawing. Internally D3D is just doing a textured quad and it gains a lot of speed by doing it all between a begin and and end. I sort my sprites by texture which gives some speed ups. I would render all your sprites then all your text to get teh text on the sprites.

Share this post


Link to post
Share on other sites
1. If you want your sprites to be drawn according to their z value (which is indeed between 0.0f and 1.0f, 0.0f being the closest, 1.0f being the farthest), pass D3DXSPRITE_SORT_DEPTH_FRONTTOBACK as a parameter into ID3DXSprite::Begin().

2. Are you using ID3DXFont or something homemade? In any case, I think passing D3DXSPRITE_SORT_DEPTH_FRONTTOBACK into ID3DXSprite::Begin() should solve the problem. You want to call ID3DXSprite::Begin() and ID3DXSprite::End() each only once per frame. (Render everything in one go)

3. Pass D3DXSPRITE_SORT_TEXTURE as a parameter into ID3DXSprite::Begin() to tell ID3DXSprite to internally render all the sprites using texture x, and then render all the sprites using texture y, and so on so there isn't any unnecessary texture changing (which is slow). However, if you're not using the August 2005 DirectX 9 SDK, then passing D3DXSPRITE_SORT_TEXTURE as well as D3DXSPRITE_SORT_DEPTH_FRONTTOBACK into ID3DXSprite::Begin() for some reason causes D3DXSPRITE_SORT_DEPTH_FRONTTOBACK to be completely ignored, making all sprites using texture x to be at the same depth y, and all sprites using texture y to be at the same depth w, and so on. The August 2005 SDK release notes said that you can now pass both parameters into ID3DXSprite::Begin() and it'll work fine, but I haven't tried it myself yet (though I assume they know what they're talking about [wink]).

So your ID3DXSprite::Begin() call should like this:

sprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_FRONTTOBACK | D3DXSPRITE_SORT_TEXTURE)

Again, assuming you are using the August 2005 SDK.

Share this post


Link to post
Share on other sites
Thanks for the quick replies, and the followups:

The z ordering works great, but not for my fonts. It is a custom class that uses vertex buffers and DrawPrimitive. The thing is that I want to do small windows with buttons, input boxes, static texts, lists, sliders and so on. I would like to use transparancy for the windows so with two windows overlapping each other I could see the "back window" through the first window. This works great, but... if my font class fails to render on top of the sprites when I'm in between sprite->Begin and sprite->End, it won't be possible (without z sort my stuff and have several begin + ends).

If it should be possible to render my vertex buffer screen spaced font in between, what could be wrong? I'm using a FVF without the RHW component and I just pass the x, y, z to a shader that just sets the OUT.position to IN.position in the vertex shader. (it doesn't do anything with the position). z component is set to 0.0 so I thought that my sprites, rendered at 0.1-1.0 should be behind the font but that is not the case. (I render the font after the sprite aswell)

And to spam this thread even more, another question. I'm using one big texture and put all my components in it. Can I somehow make a sprite that has a size of say ... 100x100 pixels and make it use a 10x10 texture source repeatedly? For example. I want to make windows / frames using one parts of the texture for each of the following things horizontal border, vertical border, four corners and a background. Maybe I could just do one border and one corner then rotate the sprites. Well, the problem is, as I said. If I want a window of size 100x100 px I want to "build it" from much smaller size borders and background textures, and tile them.

EDIT:
Well, the sprite buffer (all the batched sprites) is flushed at the sprite->End() call, so if I draw my font within the begin + end section I will draw it before sprite->End() and thereby before all the sprites. So I have to do it after end, or, I'll call a sprite->Flush() then draw the text. I guess this is a bit slow though :S But it seems to me that it's the only option. Even if I could skip transparent windows, I would require windows to overlap. And if windows overlap and I draw all the text _after_ all of the sprites, text from windows behind the topmost window, will be written over the topmost window. So I have to do one "layer" of Z, all sprites, flush, all text for that layer then continue with next layer. If I batch this good it should be sufficient with max 5-10 flushes, shouldn't be that awful, and transparency will work :P

[Edited by - Kija on August 26, 2005 5:29:36 PM]

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!