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
spriteBatch.Draw(rockTexture, rockPosition, null, Color.White,
rockRotation, rockCenter, 1.0f, SpriteEffects.None, 0.0f);
spriteBatch.Draw(shipTexture, shipPosition, null, Color.White,
shipRotation, shipCenter, 1.0f, SpriteEffects.None, 0.0f);
spriteBatch.End();
thease instruction to Draw function,the 3D primitive can not be displayed why?have you can fix the problem?
render 3D primitive
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.
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
SaveStateMode.SaveState
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.
Game making is godlike
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
Is it mean change it as spriteBatch.Begin(SaveStateMode.SaveState); correct?but the compiler say no,because some unusefull parameter within the begin call.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement