Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

synthexp

Index Buffer

This topic is 6306 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 all I will be developing my final year project this coming semester and I will be doing it using Direct3D. Before that, I am a little confused over the term index buffer coined in the DX8 docs. As far as my understanding of the concept (at least what the docs said), IB is an array of 16bit integers which refers a stream of vertex data in VB. Does the each indices refers (points to) to one particular vertex data or each indices refers to the starting point of vertex data. How does DrawIndexedPrimitive () works with the indices. Does DIP() starts at particular vertex data referred by the indices and starts drawing them from the points onward or something else? I''ve peeked into the D3D samples and I couldn''t understand the usage. Furthermore, all of the samples use DIP with static vertex data, data that is not changed over the duration of the runtime. I would like to know if it is possible, DIP working with dynamic vertex data. Does anybody out there has a fully commented and working index buffer implementing dynamic vertex data sample. FYI, I will be developing a real-time water caustic effect and surely it means dynamic data. What does it mean by drawing the furthest vertex location in world model on a perspective viewing, so that Z-buffer would work. Say you want to draw a soccer ball 1000 points behind a cat, you must draw the ball first then the cat. Does the location refers to the current position in the eye (rendering) point or the camera point? If the camera is moving, how can the furthest location be defined? One more thing is the inclusion of SetRenderStates. I''ve noticed that SRS must be reset to its initial states after every usage. Why it is so? and why it is done in the bunches and what exactly a render state? Pls excuse the nature of this question as I''m quite new to DirectX. Regards, Ihsan

Share this post


Link to post
Share on other sites
Advertisement
Go to www.wazooenterprises.com and read his first basic tutorials in direct3d. They all use index buffers and are very easy to understand. Basically all your doing is telling directx the order in which to render the "shapes" you defined in your vertex buffer.

For example, you define six different triangles in your vertex buffer. Well, after that you can use the index buffer to tell directx the order to draw those triangles in order to make a 3d cube or pyramid. Its just an easy way to reuse code and draw many different objects from the list (triangles defined in the vertex buffer).

If that confused you, go to the site above and you''ll find several good articles to show how its used and what it is.

Hope this helps!

Share this post


Link to post
Share on other sites
thank you chris for your reply

the site sure helps, in fact i''m studying the codes now. it''s quite interesting on how they implement the IB. too bad they did not change the VB data. just use memcpy on locks.

now if only i can get my another two questions on zbuffer and setrenderstates () answered.

Share this post


Link to post
Share on other sites
Z Buffers.

When the rasteriser draws a pixel, it first checks with the z buffer to see if that pixel should be drawn. It takes the distance of that point on the polygon you are drawing, and compares it to a value on the Z buffer. If it is nearer, it draws it, if it is further, the pixel is not drawn.

Try drawing nearby ball, and then drawing a cat behind it. If your Z buffer is turned off, the cat appears in front of the ball, despite the fact that it is further away. If you have the Z buffer on, it all looks fine.

SetRenderState:

SetRenderState is used to errr... set the state of the renderer. For example, maybe you want to draw some verts in wireframe, or perhaps you want to turn backface culling and the Z buffer off for some alpha blending or whatever.

Share this post


Link to post
Share on other sites
Z buffer - the whole point of the Z buffer is to let you render in any order. With no Z buffer, you''d have to render the ball and then the cat. With the Z buffer enabled, you can render in any order and the renderer will only update pixels if the new pixel is nearer to the eye.

SetRenderState - you don''t need to reset everything after every usage, but many people do so that different parts of the program don''t make bad assumptions about what the state is. But, if you know that you are always going to need something turned on, turn it on and forget about it - no need to turn it off. In general, the less state changes, the better.

Share this post


Link to post
Share on other sites

bool checkzbuffer = false;

glGetBooleanv( GL_DEPTH_TEST, &checkzbuffer );

if (checkzbuffer)
{
// our zbuffer is enabled
}
else
{
// we''re screwed
}


--------

On how to determine what objects are farthest away it is pretty simple. The camera can be anywhere and rotated any angle, but everything in your world must be rotated so that it appears that the camera is in the center of your screen pointing straight into the screen before the scene is projected to 2D. Therefore you take your already transformed objects and test the Z value. Assuming that the Z axis points into your screen, the object with the highest Z value is the furthest away. You don''t need actual distance in any arbitrary direction, only the distance in the direction of your depth axis.

Hope that makes some sense

Seeya
Krippy

Share this post


Link to post
Share on other sites

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