Jump to content

  • Log In with Google      Sign In   
  • Create Account

MatsK

Member Since 21 Feb 2008
Offline Last Active Sep 19 2016 10:19 AM

Posts I've Made

In Topic: Rendering 3D Over 2D

05 September 2016 - 01:16 PM

Solved it! :D
Turns out that the Depth parameter in GraphicsDevice.Clear works exactly like the one in SpriteBatch.Draw :)


In Topic: Rendering 3D Over 2D

11 August 2016 - 01:25 PM

That didn't work either :(

But thanks for pointing out that SpriteSortMode.Deferred actually ignores depth! :D


In Topic: Rendering 3D Over 2D

10 August 2016 - 04:56 AM

Ok, I changed my drawing callback to:

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Resolution.BeginDraw();

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.Default, 
                RasterizerState.CullCounterClockwise, null, Resolution.getTransformationMatrix());
            m_ScrManager.Draw();
            spriteBatch.End();

            //Reset device to defaults before rendering...
            GraphicsDevice.BlendState = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
            GraphicsDevice.Viewport = new Viewport(0, 0, GlobalSettings.Default.ScreenWidth, GlobalSettings.Default.ScreenHeight);
            GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Black, 0.5f, 1);
            m_ScrManager.Draw3D();

            HitVM.Step();

            base.Draw(gameTime);
        }

Still doesn't work. :(

Are the parameters correct? They're not exactly very well explained on MSDN, so I just put something...


In Topic: Rendering 3D Over 2D

08 August 2016 - 04:50 PM

Yes.
As is I only see the 2D.

How do I clear the depth buffer?

In Topic: Rendering 3D Over 2D

08 August 2016 - 01:48 PM

Yeah, I believe it does.

Here's how I'm drawing a button to the UI, for instance:

        public override void Draw(SpriteBatch SBatch, float? LayerDepth)
        {
            if (Visible)
            {

                float Depth;
                if (LayerDepth != null)
                    Depth = (float)LayerDepth;
                else
                    Depth = 0.0f;

                if (Image != null && Image.Loaded)
                {
                    Image.Draw(SBatch, new Rectangle((int)m_SourcePosition.X, (int)m_SourcePosition.Y, (int)m_Size.X,
                        (int)m_Size.Y), Depth);
                }

                if (m_IsTextButton)
                    SBatch.DrawString(m_Font, m_Text, m_TextPosition, TextColor);
            }
        }

Notice how I'm passing Depth to Image.Draw:

        public override void Draw(SpriteBatch SBatch, Rectangle? SourceRect, float? LayerDepth)
        {
            float Depth;
            if (LayerDepth != null)
                Depth = (float)LayerDepth;
            else
                Depth = 0.0f;

            if (Visible)
            {
                if (SourceRect != null)
                {
                    SBatch.Draw(Texture, Position, null, SourceRect, new Vector2(0.0f, 0.0f), 0.0f, null, Color.White,
                        SpriteEffects.None, Depth);
                }
                else
                {
                    SBatch.Draw(Texture, Position, null, null, new Vector2(0.0f, 0.0f), 0.0f, null, Color.White,
                        SpriteEffects.None, Depth);
                }
            }
        }

But in my drawing callback in the OP, I'm resetting the DepthStencilState before rendering 3D... I thought that should do the trick! 


PARTNERS