switching vertex formats

Started by
6 comments, last by theyorec 18 years, 3 months ago
Is it not possible to draw using two different types of vertex formats? I am trying to draw a scene with TransformedTextured vertices and TransformedColored. I set the device.VertexFormat to TransformedTextured then draw those vertices, then set the device.VertexFormat to TransformedColored and draw my colored vertices. Unfortunately the colored vertices are drawn with no color at all, only in black. When the prior TransformedTextured code is removed the TransformedColored vertices are drawn fine with color. Is it not possible to draw a scene with two different kinds of vertices, if it is how do I accomplish this? Thanks!
Advertisement
As long you have set the proper Projection,View,And World Matrix and the proper FVF then you should not have any problem. But if you are trying to combine both and draw them at the same time i do not think that is impossible.
It should be possible, so you needn't worry about that. My guess is that the problem lies in the texture you set for the TransformedTextured vertices. Since the TransformedColored vertices have no texture uv information, applying the texture will fail. Try setting the texture to null (typically with device.SetTexture(0, null)) after you render the TranformedTextured vertices and before your render the TransformedColored ones.

The world, view and projection matrices don't come into play with theyorec's problem (yet:), since he's using pretransformed vertices that are defined in screen space.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Just a correction...

Since your using Transformed vertex type, you dont need to worry about Matrices...

Are you sure you are doing something like:
pDevice->BeginScene();// Draw object #1pDevice->SetFVF(TransformedColored);pDevice->SetVertexBuffer(theVB1);pDevice->SetIndexBuffer(theIB1);pDevice->DrawIndexed(.....);// Draw object #2pDevice->SetFVF(TransformedTextured);pDevice->SetVertexBuffer(pVB2);pDevice->SetIndexBuffer(pIB2);pDevice->SetTexture(0, pTheTexture);pDevice->DrawIndexed(.....);pDevice->EndScene();pDevice->Present(0,0,0,0);


EDIT:
Geez, 2nd time tonite i got biten on a response :)
But i would add something to remigius, u dont need to unset Texture, simply cause the FVF tell DX not to look for those information in the VB..

Jonathan
Quote:Original post by LowRad
But i would add something to remigius, u dont need to unset Texture, simply cause the FVF tell DX not to look for those information in the VB..


Actually, you're both wrong. You should not set the texture to NULL and expect that to fix things because it's incorrect. But the FVF does not tell DX whether to read a Texture or not, it has nothing to do with it. The data in the vertex (as defined by the FVF) tells *where* to read the texture, but not whether to. If your TextureStageStates say that a texture needs to be read, regardless of whether you have no texture coordinates or have set the Texture to NULL, Direct3D *will* read texture data; it will just be wrong data.

Use something like this to read ONLY from the texture for color:
device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);   //Ignored


Something like this for only from diffuse (in this case, vertex colour):
device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2);device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);   //Ignoreddevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);


Something like this to modulate the 2:
device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);


Stay Casual,KenDrunken Hyena
Hummm...

If im trying to do this..

// Draw object #1
pDevice->SetFVF(TransformedColored);
pDevice->SetVertexBuffer(theVB1);
pDevice->SetIndexBuffer(theIB1);
pDevice->DrawIndexed(.....);

Wont all thoses calls get ignored, since there nothing to modulate !?
device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);

If so, that was i mean by setting the FVF.. else i gotta read again that beefy MSDN.


Btw, i hope that help you theyorec..
Jonathan
Quote:Original post by DrunkenHyena
Actually, you're both wrong.


That's entirely within the realm of the possible :)

But I'm a bit puzzled then why the TransformedColored do get rendered correctly when theyorec omits the draw call of the TransformedTextured vertices. I'll have to double check to be 100% sure, but as I recall setting the texture to null solved the same problem for me in MDX.

Edited:

Well, I cannot speak for Unmanaged DirectX, but for MDX setting the texture to null does solve the problem. When I don't reset the texture, the vertices with the color information will be rendered in black and when I set it to null, they are rendered in the expected color. There's probably something in the Managed wrapper that sets the appropriate renderstate based on the texture value then, I guess...

Here's a little demo project (271KB Zip) that demonstrates this.

[Edited by - remigius on December 29, 2005 11:54:03 AM]
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
setting the texture to null did solve the problem,
thanks!

This topic is closed to new replies.

Advertisement