tags:

views:

744

answers:

2

Hi. 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..

+1  A: 

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.

Peter Lillevold
i thought that too. when i applied the code, still it didnt affect anything
r4ccoon
A: 

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); 
    }
r4ccoon
So what you're basically saying is that my answer was correct..? ;)
Peter Lillevold
yeah it was correct. lol. but after some changing in the code, i had to apply(uncomment the resetRenderState3D) the reset render state again.weird.. but it s worked.
r4ccoon
Good. Yes, weird. Perhaps letting the sprite batch save render state will have the same effect as resetting render state...
Peter Lillevold
as the article said, saverenderstate will slow the game. even without it my game is already slow. i think i have to do some trick here and there.
r4ccoon