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.

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 on other sites
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 textureDirect3D_Device.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); //draw the first quadDirect3D_Device.SetTexture(0, Texture2); //set the second textureDirect3D_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 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.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• Forum Statistics

• Total Topics
633370
• Total Posts
3011542
• Who's Online (See full list)

There are no registered users currently online

×