PositionColoredTextured

Started by
8 comments, last by Supernat02 19 years, 6 months ago
I'm trying to use an animated texture with this type of vertex, and it has the ability to set texture coordinates. I have done animated textures in directdraw, but you can set the size of each part of the texture to draw as well as the coordinates. With PositionColoredTextured you cannot set the size to draw, only texture coordinates. Anyone have any suggestions as to how to get animated textures working? I want to use a 256x256 texture split into sixteen 64x64 images. Also.. would anyone recommend an ArrayList (part of the Systems.Collection namespace) or an array of type PositionColoredTextured to hold each vertex. [Edited by - MikeyO on October 17, 2004 7:08:40 PM]
Advertisement
No one wants to venture a guess?
There are two options. One is to use a D3DXSprite interface because you can plug in the actual pixel value of the texture and it will calculate the texture coordinates for you. The other option is to calculate them yourself. Let's look at a 1D example. If the texture runs betwee 0 and 1.0, then you can consider 0 as 0% into the texture and 1.0 as 100% into the texture. So, if you have 16 textures in a row, you'll have 100/16 or 6.25% chunks. The first texture is at 0%, the second is at 6.25%, etc. Since 1.0 maps to 100% then 6.25% maps to 0.0625. Hope this helps.

Chris
Chris ByersMicrosoft DirectX MVP - 2005
I would actually prefer to make my own sprite, either with a pointsprite (like Im using now), or with a textured quad, than use d3dsprite.. wouldn't drawing each sprite individually be a lot slower than drawing a whole vertex buffer?
Depending on which version of DirectX you have, it will differ I think. Let me put it this way. I know the sprite in version 9 is better than previous versions. I don't know what those differences are.

To answer your question though, drawing everything in one vertex buffer can be better. I believe DirectX 9 sprites do this though. You call a Begin(D3DXSPRITE_SORT_TEXTURE) function to start "building" the buffer and batch them by texture. Then you call Sprite->Draw(...) for each sprite, which tells which texture and a rectangle region of the texture, and then you can End() when you're done with the draw calls. DirectX batches up the draw calls in the best form possible (I'm thinking this includes vertex and index buffers) and sends them at once. If more than one texture is used, it sets the texture first. If you passed in D3DXSPRITE_SORT_TEXTURE, then it puts all similar textures together (whether it puts them in a single vertex buffer or just calls SetTexture once I'm not sure of).

On the other hand, drawing one vertex buffer can be bad too. If it's very large, you don't get a good CPU/GPU balance and could lose CPU time. If you had it broken into 3 draw calls for instance, where you used CPU time granted while the first draw call was in progress to create your second set of vertices for the second draw call, you come out ahead.

I wouldn't re-invent the wheel unless you have special needs for your sprites. If not, give it a shot and see if it meets your needs. You can do some profiling of various numbers of sprites you think you'll need and see if it meets your requirements. Most likely, you will spend very little time profiling the D3DXSprite interface for your needs compared to the time you'd spend creating a new class (unless you've done it many times before). That's all up to you though!

Chris
Chris ByersMicrosoft DirectX MVP - 2005
If PositionColoredTextured is not meant for doing animated textures, then what is it meant for?

I'd prefer to use a point sprite with positioncoloredtextured to using D3DXSprite
I assume you mean the hardware point sprite and not a quad. If not, ignore this paragraph. You can't use a point sprite with PositionColoredTextured, because a point sprite can only contain position, color, and size. The texture is set through SetTexture, and the point sprite uses the entire texture when it is drawn. You will not be able to perform animated texture point sprites unless you change the entire texture, because you can't set the texture coordinates. You could batch certain sprites together and set the texture and draw them in this frame, then rotate the textures every frame to achieve this, but I think what you're looking for is moving the texture slightly so it appears that it is moving (like water).

PositionColoredTextured is meant for qauds that have color, texture, and a position...pretty common. The vertices can be locked and modified to move the texture coordinates too. For point sprites (not the hardware ones), you'll need to create a billboard from PositionColoredTextured. Then you can lock and update the vertices every frame with the new texture coordinates. Is this what you are looking for?

Chris
God, how could I have been so stupid rofl..

I just realized why there is only one set of texture coordinates in positioncoloredtextured.. thank you anonymous. I have to make a manual quad & have it face the camera, which shouldnt be too difficult, thanks for the help you two.
Will a triangle strip connect all the vertices in a buffer that you are drawing at the same time, or can you seperate the triangle strip into quads with the drawprimitives call's primitive count?
I was anonymous. They logged me out for some reason. Yes, I wouldn't recommend using a strip. You will want to go with triangle lists. Most cards are optimized for lists now days anyway from what I've read.

Good luck,
Chris
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement