Video Tutorial 1, ship textures are transparent?

Last post 04-30-2008, 2:49 AM by Nick Gravelyn. 1 replies.
Sort Posts: Previous Next
  •  04-30-2008, 2:45 AM

    Video Tutorial 1, ship textures are transparent?

    I've been making some modifications to the code from Tutorial 1 - Displaying a 3D model on screen.  I wanted to show my camera position on-screen, so I looked in the XNA help and came up with this code:
            protected override void Draw(GameTime gameTime)
    {
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    // Show camera position on-screen
    spriteBatch.Begin();
    string posText = String.Format("cameraPos: {0}x {1}y {2}z", cameraPosition.X, cameraPosition.Y, cameraPosition.Z);
    Vector2 fontOrigin = gameFont.MeasureString(posText);
    spriteBatch.DrawString(gameFont, posText, textPos, Color.Black, 0, fontOrigin, 0.8f, SpriteEffects.None, 0.5f);
    spriteBatch.End();

    // Copy any parent transforms.
    Matrix[] transforms = new Matrix[myModel.Bones.Count];
    myModel.CopyAbsoluteBoneTransformsTo(transforms);

    // Draw the model. A model can have multiple meshes, so loop.
    foreach (ModelMesh mesh in myModel.Meshes)
    {
    // This is where the mesh orientation is set, as well as our camera and projection.
    foreach (BasicEffect effect in mesh.Effects)
    {
    effect.EnableDefaultLighting();
    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationX(modelXRotation) * Matrix.CreateRotationY(modelYRotation)
    * Matrix.CreateTranslation(modelPosition);
    effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 100000.0f);
    }
    // Draw the mesh, using the effects set above.
    mesh.Draw();
    }

    base.Draw(gameTime);
    }

    It works for displaying the text on-screen, but when the text is displayed, the textures of my model are semi-transparent.  If I comment out the code between spriteBatch.Begin and spriteBatch.End, the model textures go back to normal.  Any explanation why drawing some text on-screen affects the rendering of my model?
  •  04-30-2008, 2:49 AM

    Re: Video Tutorial 1, ship textures are transparent?

View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback