Hi guys!I have been render two 3D graphics on my project,but I hope they can display together with the 2D sprite together,but unfortunately if I write spriteBatch.Begin(SpriteBlendMode.AlphaBlend); // start drawing 2D images
The sprite batch changes a few settings of the graphics device to put its 2d graphics on the screen, when you move on to rendering 3d content those settings prevent them from being properly rendered.
To render 3d content you use shaders, and to use a shader you have to manually set the necessary settings and parameters of the graphics device for it to work, the SpriteBatch instead is not a shader, it uses a shader inside, but abstracts you from all those settings. If you use 3d graphics only, many settings will be in a default state that you do not need to change for 3d content, however the sprite batch changes them and does not restore them to their original state unless you tell it to, if I'm not wrong this is done by setting the following parameter on the begin call of the SpriteBatch
By default this is set to None, which does not restore original settings after the end call. If you are only going to render 2d though, you want it set to none, changing render states is expensive and should be done as less as possible.
Normally when you cant see things being drawn, it is to do with the depth buffer. Without the depth buffer enabled, components will be drawn in the order they were added to the component list and not their order in 3d space. I cant say for sure, because I don't know how you coded it, but just try enabling the depth buffer before you draw the primitives.
So, inside the draw method, set :
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
And if your not already, you should draw any 2d sprites AFTER you draw your 3d models/primitives. So put the spriteBatch.Draw() after the call to base.Draw() in your draw method.