XNA Creators Club Online
Page 1 of 1 (18 items)
Sort Posts: Previous Next

3D drawing back textuers come through front textures

Last post 7/9/2009 12:25 PM by BlackWolve. 17 replies.
  • 7/2/2009 1:05 PM

    3D drawing back textuers come through front textures


    Im making a 3d Tetris game for school
    The wrong drawing

    as you can see the back textures of the cubes is coming in front of the front textures of the cube.
    Can anyone see whats wrong.
    I'm using Models but before this i tried it with VertexPositionNormalTexture and that gave the exact same result. So i think i must look somewhere else. But im a beginner in XNA and im lost atm.

    please help :)
  • 7/2/2009 1:10 PM In reply to

    Re: 3D drawing back textuers come through front textures

    It looks like you are using SpriteBatch to draw some text, so you might have to reinstate the render states below before drawing your cubes.

        GraphicsDevice.RenderState.DepthBufferEnable = true;
    GraphicsDevice.RenderState.AlphaBlendEnable = false;
    GraphicsDevice.RenderState.AlphaTestEnable = false;

    Depending on your 3D content, you may also want to set:

        GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
    GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

    See here for full explanation.

    Game hobbyist hell-bent on coding a diabolical Matrix
  • 7/2/2009 1:12 PM In reply to

    Re: 3D drawing back textuers come through front textures

    You probably just need to turn on the depth buffer just before doing the 3d rendering:

    GraphicsDevice.RenderState.DepthBufferEnable = true;


    I think it defaults to ON, but using the SpriteBatch without saving the state will turn it off again.

    ---EDIT---
    Beaten by quick draw Craig :)
  • 7/2/2009 1:33 PM In reply to

    Re: 3D drawing back textuers come through front textures

    Thnx for the quick reply
    it worked perfectly.
    See below
    Better drawing

    as you can see @ the bottom of the cubes there is sometimes some small parts missing
    as i zoom in these things get smaller .
    Any ideas on that?
  • 7/2/2009 1:53 PM In reply to

    Re: 3D drawing back textuers come through front textures

    You might want to put your 2D drawing code after your 3D drawing code, as currently all the messages are behind the 3D objects.;)
  • 7/2/2009 2:01 PM In reply to

    Re: 3D drawing back textuers come through front textures

    yeah i know  ;)
    the text is not correct positioned also atm.
    but i want to fix the thingies on the bottom of the cubes.
  • 7/2/2009 6:41 PM In reply to

    Re: 3D drawing back textuers come through front textures

    That looks a little bit like Z-fighting. Do you render two cubes in each location perchance?
  • 7/8/2009 8:10 AM In reply to

    Re: 3D drawing back textuers come through front textures

    No only 1.
  • 7/8/2009 12:59 PM In reply to

    Re: 3D drawing back textuers come through front textures

    Have you fixed this yet? If not can you post your draw code so we can try spot something?
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 7/8/2009 2:17 PM In reply to

    Re: 3D drawing back textuers come through front textures

    no its still the same
    as http://filedump.sargeman.nl/gooddrawing.JPG
    will post some more info tonight. im @ work now
  • 7/8/2009 2:32 PM In reply to

    Re: 3D drawing back textuers come through front textures

    i saw i left my computer on @ home

    1 public void Draw(GameplayScreen Game, Vector2 position, Boolean shadow) 
    2         { 
    3             float x = -6 + (Game.GameField.Width - 1 - position.X / 25); 
    4             float y = -13 + (Game.GameField.Height - position.Y / 25); 
    5             float z = 0; 
    6  
    7             Matrix crateTransform = Matrix.CreateTranslation(new Vector3(x-0.5f,y-1.0f,z-0.5f)); 
    8  
    9             Matrix crateRotation = Matrix.CreateRotationX(0); 
    10             Model model = CrateModel; 
    11  
    12             DrawModel(Game, CrateModel, crateTransform * crateRotation, CrateTransforms, shadow); 
    13         } 
    14  
    15 private void DrawModel(GameplayScreen Game, Model model, Matrix modelTransform, Matrix[] absoluteBoneTransforms, Boolean shadow) 
    16         { 
    17  
    18             Game.ScreenManager.GraphicsDevice.RenderState.CullMode = CullMode.None; 
    19  
    20             Game.ScreenManager.GraphicsDevice.RenderState.DepthBufferEnable = true
    21             Game.ScreenManager.GraphicsDevice.RenderState.AlphaBlendEnable = true
    22             Game.ScreenManager.GraphicsDevice.RenderState.AlphaTestEnable = true
    23  
    24             //Draw the model, a model can have multiple meshes, so loop 
    25             foreach (ModelMesh mesh in model.Meshes) 
    26             { 
    27                  
    28                 //This is where the mesh orientation is set 
    29                 foreach (BasicEffect effect in mesh.Effects) 
    30                 { 
    31                     effect.EnableDefaultLighting(); 
    32                     effect.Texture = SuperBrick ? 
    33                                 shadow ? 
    34                                     ShadowSuperCrateTexture : SuperCrateTexture 
    35                                 : ExplosiveBrick ? 
    36                                     shadow ? 
    37                                         ShadowExplosiveCrateTexture : ExplosiveCrateTexture 
    38                                         : shadow ? ShadowCrateTexture : CrateTexture; 
    39                     effect.World = absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform; 
    40                 } 
    41                 //Draw the mesh, will use the effects set above. 
    42                 mesh.Draw(); 
    43             } 
    44         } 

  • 7/8/2009 6:04 PM In reply to

    Re: 3D drawing back textuers come through front textures

    Do those strange grey bits flicker around if you move the camera or objects? If so, I'm even more sure it's Z-fighting. It looks like your textured cubes are fighting with some non-textured cubes. Maybe your Draw() is actually being called multiple times with the same Vector2 position in a single frame? Try drawing only a single brick and debug step though to confirm this isn't the case.
  • 7/9/2009 8:17 AM In reply to

    Re: 3D drawing back textuers come through front textures

    well i searched and checked but im not drawing anything twice.
    I will try now to draw 1 block and then 2 etc.
  • 7/9/2009 8:33 AM In reply to

    Re: 3D drawing back textuers come through front textures

    it already happens with 1 model i just found out.
    Could it be the model it self?
    i'll try to make my own model and see if it works.
  • 7/9/2009 10:45 AM In reply to

    Re: 3D drawing back textuers come through front textures

    Yes it certainly does look like z-fighting.

    Maybe the model has two cubes in it of the same size or has corrupted indices.

    I would also turn off AlphaBlendEnable and AlphaTestEnable just to be sure its not doing anything weird.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 7/9/2009 11:22 AM In reply to

    Re: 3D drawing back textuers come through front textures

    Yeah i tried it with alphablend off but thats not helping and i also need it because the shadow shapes have transparent textures.
    Ok i tried creating a cube model, but im really noob @ blender. i tried a tutorial with blender and xna but that gives me a huge cube and the textures of that cube are even more messed up
  • 7/9/2009 11:33 AM In reply to

    Re: 3D drawing back textuers come through front textures

    but i can tell one thing that its not the model
    the model itself works fine in original game from a friend of mine.
  • 7/9/2009 12:25 PM In reply to

    Re: 3D drawing back textuers come through front textures

    ok i fixed it :D

    changed
    projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                        aspectRatio,
                                                                        0.0001f, 1000);

    to

    projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                        aspectRatio,
                                                                        1, 1000);

    i guess nearplaneDistance was to small
    thnx everyone for help
Page 1 of 1 (18 items) Previous Next