# MDX vertex formats and lighting .. need opinions.

This topic is 4250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am currently working on a little engine (more like a simple framework/wrapper over D3D9). I am kind of stuck on a design decision. Right now all meshes in my system are derivations of a base Mesh3D class. None of these classes actually have any directX related data. They all contain data in the form of my own Vertex and Vector classes (I am planning to provide ogl rendering). I have a DirectXRenderer class that makes the DirectX version of the Mesh3D class (the Mesh class) when I add the Mesh3D object after it's initialized. My problem is with lighting. I want to be able to render to different viewports (which my system does right now) but I want to be able to specify some viewports to have lighting while others to not have lighting. This would mean I would have to maintain two versions of the Mesh (one with a CustomVertex.PositionNormalTextured and one with a CustomVertex.PositionColoredTextured format). I really don't want to do this. Is there any way to have all of the format flags in one nice format? Something like PositionColoredNormalTextured? I hope my problem is stated clearly. Thanks, Aditya

##### Share on other sites
Your problem is clearly stated, but I don't understand it [wink]

If you are using your own Vertex structs, you can specify their format on the device by using either the VertexFormat enum or by using a VertexDeclaration. You can bit-or items from the VertexFormat enum together to specify which elements you vertex struct contains, like this:

device.VertexFormat = VertexFormats.Position | VertexFormats.Normal;

Using the VertexDeclaration is somewhat more complex, but you can find more info on that in the Managed DirectX documentation, as well as in various only tutorials (both our advanced rendering tutorials use them for example). The key idea is that you can just stuff information in your own struct and use one of these two vehicles to tell the device what information your Vertex struct contains.

However, all this has nothing to do with the lighting. You can simply toggle lighting on and off by setting the device.RenderState.Lighting boolean appropriately.

Hope this helps :)