SetMaterial(NULL) causing crash
I'm using lighting and materials in my game, and for some of the object's I'm I don't want materials applied to them. I tried using m_Device->SetMaterial(NULL), where m_Device is a valid IDirect3DDevice*, and it crashes with an access violation error. After it crashed, I tried the same call using a valid material, and it didn't crash, but it also didn't give me the results I want. Is there anything wrong with calling SetMaterial and passing in NULL, or is there a better way to not apply materials to specific objects?
I don't think setting a NULL material really makes much sense. If the material is NULL, what's Direct3D going to use for its lighting calculations?
If you want to disable lighting, use SetRenderState() instead.
If you want to disable lighting, use SetRenderState() instead.
NULL isn't a valid parameter for SetMaterial().
1. The debug D3D runtime would have told you that ("Direct3D9: (ERROR) :Invalid D3DMATERIAL pointer. SetMaterial failed."). The debug runtime is a great tool for debugging D3D problems.
2. What behaviour do you expect from setting a NULL material? A D3DMATERIAL9 with all elements set to 0 (black)? A D3DMATERIAL9 with all elements set to 1 (white)? A D3DMATERIAL9 with the diffuse or ambient set to white and specular set to black? No lighting computation?
If you want to disable lighting entirely, set the D3DRS_LIGHTING render state to FALSE. If the effect you want is just the texture colour rather than the lit texture colour, then you'll need to change the D3DTSS_COLOROP texture stage state to select whichever argument the texture is in instead of modulating between them.
An alternative is to set up a new material with the ambient values set to white and the rest set to black then set the D3DRS_AMBIENT render state to white.
1. The debug D3D runtime would have told you that ("Direct3D9: (ERROR) :Invalid D3DMATERIAL pointer. SetMaterial failed."). The debug runtime is a great tool for debugging D3D problems.
2. What behaviour do you expect from setting a NULL material? A D3DMATERIAL9 with all elements set to 0 (black)? A D3DMATERIAL9 with all elements set to 1 (white)? A D3DMATERIAL9 with the diffuse or ambient set to white and specular set to black? No lighting computation?
If you want to disable lighting entirely, set the D3DRS_LIGHTING render state to FALSE. If the effect you want is just the texture colour rather than the lit texture colour, then you'll need to change the D3DTSS_COLOROP texture stage state to select whichever argument the texture is in instead of modulating between them.
An alternative is to set up a new material with the ambient values set to white and the rest set to black then set the D3DRS_AMBIENT render state to white.
And if you're trying to use vertex colors for lighting, set D3DRS_COLORVERTEX to TRUE. Set D3DRS_DIFFUSEMATERIALSOURCE to D3DMCS_COLOR1 and possibly D3DRS_SPECULARMATERIALSOURCE to D3DMCS_COLOR2. Maybe you want ambient to use your diffuse vertex color too. If so, set D3DRS_AMBIENTMATERIALSOURCE to D3DMCS_COLOR1.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement