简体   繁体   中英

xna: display 2d sprites behind the 3d object

i am a beginner in 3d graphics thing and learning xna and csharp.

i have 3d object that i want to draw in front of a 2d background, the 3d object is simple, it is just a line. i made it from 2 dimensional VertexPositionColor[].

and then i drew it with PrimitiveType.LineStrip.

and also i have a Texture2D that i displayed with Spritebatch.draw.

what is happening is the line is displayed at the back of the background, so i cant see any line.

but if i commented the spritebatch.draw, i can see the line there.

please help..

You have a z-buffer problem there. In what order are you doing the 2D and 3D drawing? 2D should come first I would guess. Also, you should check out how to make render states work when mixing SpriteBatch and 3D operations.

i managed to fix it. all the 3D draw method should be after spritebatch.begin and end.

what i did was put the effect.begin and pass.begin after the spritebatch.begin and end

here are the code for the draw method on game1.cs(the default filename when you use the wizard)

    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.Black);

        spriteBatch.Begin();             
        GameEngine.Draw(GameEngine,gameTime); 
        spriteBatch.End();

        //resetRenderState3D();
        GameEngine.Draw3D(GameEngine, gameTime);

        base.Draw(gameTime); 
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM