Jump to content
  • Advertisement
Sign in to follow this  
Jacob Roman

Vertex Buffers Revisited

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

Ok. Lets keep this simple. Cause I'm still having issues pulling this off. As an example, I'm only gonna have 4 polygons (all triangles, 2 per quad) for the vertex buffer. One quad will have one texture, while the other quad will have another texture. Don't worry bout the overkill part just yet cause this is to prep me for more polygons. Now, here is where I'm stuck. Where I render, I set the texture, and I draw the primitive:
Direct3D_Device.SetTexture 0, Texture1

Direct3D_Device.SetStreamSource 0, Vertex_Buffer, Len(Vertex_List(0))
Direct3D_Device.DrawPrimitive D3DPT_TRIANGLELIST, 0, 4


Now you can't set Texture2 in after setting Texture1 because it will override it. Now how on earth can I set one texture on quad1 and set another texture on quad2, using just one Vertexbuffer? Theres something I'm not doing, I just know it. C++ code is fine. I'm learning it anyways for DX9.

Share this post


Link to post
Share on other sites
Advertisement
Hi there Jacob Roman, how are you doing?

[The problem]
How do I set a texture for each of the quad's I'm drawing?

[The solution]
Believe it or not, it's more simple than you think :)
[source lang = c++]
Direct3D_Device.SetStreamSource 0, Vertex_Buffer, Len(Vertex_List(0));

Direct3D_Device.SetTexture(0, Texture1); //set the first texture
Direct3D_Device.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); //draw the first quad

Direct3D_Device.SetTexture(0, Texture2); //set the second texture
Direct3D_Device.DrawPrimitive(D3DPT_TRIANGLELIST, 4, 2); //draw the second quad
//Note:(Index Position) The index position of the primitive in the vertex buffer
// Since I assume you have a vertex buffer with 8 vertices (2 Quads)
// The next quad will start at index position 4 in the vertex buffer
//Note:(Num Primitives) the number of primitives drawn is 2 (Quad)



Simple hey?
What you need to know is that whenever you set a texture, everything rendered after that will be rendered with that texture applied. So what you do is follow a simple pattern...

1) Set the texture
2) Render the primitives
1) Set the texture
2) Render the primitives
....

I hope this helps.
Keep cool.

Share this post


Link to post
Share on other sites
Finally some real answers. This must have been my third or forth thread asking for such things. Thanks man, I'll give that a shot. If anyone has a better solution, let me know.

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!