Please, I need your apps
Hi,
I'm starting with Directx (in C#)so i would be really happy if you could send me some your code from which I can understand this - especialy I mean Sprite.Draw2D and SpriteDraw. I was looking around and I noticed that there are problems with this classes, but if you have anything that is not complicated, then please send it on casnacaj@email.cz and i will be most gratefull.
Thx very much
This is what I'm using for my sprite class wrapper:
You should have one singular sprite object and then use it to draw the textures that you load. I came up with this after much trial and error and reading through books at the bookstore. You can also use the Draw2D method, but it's just a wrapper to the Draw method anyway.
The best bet would be to go out and get the, in my opinion, best book out there on the matter: Managed DirectX 9 Kick Start by Tom Miller, one of the lead developers of the library itself.
m_Sprite.Transform = Matrix.RotationZ(m_Rotation) * // Rotation Matrix.Scaling(m_ScaleX, m_ScaleY, 0f) * // Scaling Matrix.Translation(m_x, m_y, 0f); // Locationm_Sprite.Draw( m_Surface.m_Texture, // Texture Rectangle.Empty, // Crop rectanlge new Vector3(m_Surface.Width / 2, m_Surface.Height / 2, 0), // center Vector3.Empty, // Offset position Color.White.ToArgb()); // or System.Drawing.Color.FromArgb(255, 255, 255, 255));
You should have one singular sprite object and then use it to draw the textures that you load. I came up with this after much trial and error and reading through books at the bookstore. You can also use the Draw2D method, but it's just a wrapper to the Draw method anyway.
The best bet would be to go out and get the, in my opinion, best book out there on the matter: Managed DirectX 9 Kick Start by Tom Miller, one of the lead developers of the library itself.
If you intend to be rendering a LOT of sprites I would suggest you don't use sprites. It requires too many render calls and seriously slows up the system. I used the sprite approach and I went from 800fps to 70fps when only drawing several hundred sprites. I then switched to using a dynamic vertex buffer and drawing several dozen "quads" to the screen at a time and it works infinately more efficiently. I was able to keep my framerate up near 700 or so. The trick is you have to create the verticies of the buffer in pre-transformed space -- ie. NOT creating a quad around the origin and drawing it a hundred times with different transforms, but literally writing all the quads in their proper positions to the vertex buffer and calling one (or very few) draw call(s).
This approach may be a little complicated at the moment, but keep it in mind for the future because the sprite calls has limited use.
This approach may be a little complicated at the moment, but keep it in mind for the future because the sprite calls has limited use.
Quote:Original post by rjackets
If you intend to be rendering a LOT of sprites I would suggest you don't use sprites. It requires too many render calls and seriously slows up the system. I used the sprite approach and I went from 800fps to 70fps when only drawing several hundred sprites. I then switched to using a dynamic vertex buffer and drawing several dozen "quads" to the screen at a time and it works infinately more efficiently. I was able to keep my framerate up near 700 or so. The trick is you have to create the verticies of the buffer in pre-transformed space -- ie. NOT creating a quad around the origin and drawing it a hundred times with different transforms, but literally writing all the quads in their proper positions to the vertex buffer and calling one (or very few) draw call(s).
This approach may be a little complicated at the moment, but keep it in mind for the future because the sprite calls has limited use.
The Sprite class (e.g. ID3DXSprite), properly used, performs quite well. Calls to the Draw/Draw2D functions do not necessarily equate to render calls. The draw calls are batched within the sprite interface and only get turned into renders calls when End is called. If I'm not mistaken, the Sprite interface actually does, internally, basically what you are talking about doing manually.
I recommend you stick with the Sprite interface for now and worry about advanced optimizations only when/if it becomes necessary.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement