Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (4 posts)

2D Overlay for 3D Scene

Last post 12/28/2012 5:54 AM by Phil Fortier. 3 replies.
  • 12/27/2012 12:14 AM

    2D Overlay for 3D Scene

    Hi,

    i created a 3D scene (an earth with a space skybox) and now i would like to add some 2D overlays (text and a view images). I planned to do this by using a SpriteBatch and its Draw() and DrawString() Methods. Now either i get the 2D overlay icons and text transparent (and the 3D scene apears blueish) or i get the scene how it should be but the 2D overlay doesn´t have a transparent background anymore.

    That is the code i use to display the 2D overlay:

     

    spritebatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.AnisotropicWrap, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
    spritebatch.DrawString(calibri, currentInstance.GetType().Name, new Vector2(80, 150), Color.Green);
    spritebatch.DrawString(calibri, currentInstance.getSceneDescription(), new Vector2(80, 200), Color.Green);
    spritebatch.Draw(previousScene, new Rectangle(80, SceneFactory.Graphics.GraphicsDevice.Viewport.Height - 120, 80, 80), Color.White);
    spritebatch.DrawString(calibri, "Next Scene", new Vector2(170, SceneFactory.Graphics.GraphicsDevice.Viewport.Height - 90), Color.Green);
    spritebatch.Draw(nextScene, new Rectangle(280, SceneFactory.Graphics.GraphicsDevice.Viewport.Height - 120, 80, 80), Color.White);
    spritebatch.End();

     

    That is the result i get (click for bigger view):

    Bluish:

     

    no transparent images with BlendState.Opaque:

     

    does anyone know, what settings i need to get transparent 2D elements and a proper 3D scene, or how i can set the "background" of the SpriteBatch totally to alpha - 0?

    thank you so far!

  • 12/27/2012 6:44 PM In reply to

    Re: 2D Overlay for 3D Scene

    Torpedo27:

    Yeah, that didn´t change anything. I´ve read that post before and it didn´t change anything (it is only useful if you don´t specify these states in your shader, i guess)

    I don´t know, what exactly causes the spritebatch to draw the skybox blueish but it seems to be linked with the clear color of the Clear-Function. With black as the clear color the blue alpha tone is gone and the scene is displayed as intended.

  • 12/28/2012 5:54 AM In reply to

    Re: 2D Overlay for 3D Scene

    Markus Miller:

    Yeah, that didn´t change anything. I´ve read that post before and it didn´t change anything (it is only useful if you don´t specify these states in your shader, i guess)

    I don´t know, what exactly causes the spritebatch to draw the skybox blueish but it seems to be linked with the clear color of the Clear-Function. With black as the clear color the blue alpha tone is gone and the scene is displayed as intended.

    Is your Skybox a 3d model? What BlendState and DepthStencilState do you use when rendering it?

    In what order to do: clear the graphics device, draw your skybox, draw your planet, draw your 2d stuff?

    btw, your second image looks fine. I don't see what's wrong with it.

Page 1 of 1 (4 posts) Previous Discussion Next Discussion