Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:28:55+00:00 2026-06-14T18:28:55+00:00

I’m having a bizarre problem with XNA. I’ve been going through the following tutorial:

  • 0

I’m having a bizarre problem with XNA.

I’ve been going through the following tutorial:
http://www.i-programmer.info/projects/119-graphics-and-games/1108-getting-started-with-3d-xna.html

I’ve finished the tutorial but my finished cube renders like so:
enter image description here

enter image description here

enter image description here

As you can see, some of the vertices don’t render depending on the rotation of the cube.

If rotation is removed, the cube renders like so:
enter image description here

My full code is below (UPDATE: This is the fixed code, rendering properly):

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _3DTutorial {
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        // Tut items
        private BasicEffect effect;
        private VertexPositionNormalTexture[] cube;
        private float angle = 0;

        public Game1() {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize() {
            // TODO: Add your initialization logic here

            effect = new BasicEffect(graphics.GraphicsDevice);

            effect.AmbientLightColor = new Vector3(0.0f, 1.0f, 0.0f);
            effect.DirectionalLight0.Enabled = true;
            effect.DirectionalLight0.DiffuseColor = Vector3.One;
            effect.DirectionalLight0.Direction = Vector3.Normalize(Vector3.One);

            effect.LightingEnabled = true;

            Matrix projection = Matrix.CreatePerspectiveFieldOfView(
                (float)Math.PI / 4.0f,
                (float)this.Window.ClientBounds.Width / (float)this.Window.ClientBounds.Height,
                1f, 
                10f
            );

            effect.Projection = projection;
            Matrix V = Matrix.CreateTranslation(0f, 0f, -10f);
            effect.View = V;

            RasterizerState rs = new RasterizerState();
            rs.FillMode = FillMode.WireFrame;
            graphics.GraphicsDevice.RasterizerState = rs;

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent() {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            cube = MakeCube();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent() {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime) {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            angle = angle + 0.005f;
            if (angle > 2 * Math.PI) {
                angle = 0;
            }

            Matrix R = Matrix.CreateRotationY(angle) * Matrix.CreateRotationX(.4f);
            Matrix T = Matrix.CreateTranslation(0.0f, 0f, 5f);
            effect.World = R * T;

            base.Update(gameTime);
        }

        /// <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) {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            foreach (EffectPass pass in effect.CurrentTechnique.Passes) {
                pass.Apply();
                graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube, 0, (cube.Length / 3));
            }

            base.Draw(gameTime);
        }

        protected VertexPositionNormalTexture[] MakeCube() {
            VertexPositionNormalTexture[] vertexes = new VertexPositionNormalTexture[36];
            Vector2 Texcoords = new Vector2(0f, 0f);

            // A square made of two triangles
            Vector3[] face = new Vector3[6];
            // First triangle - bottom left
            face[0] = new Vector3(-1f, -1f, 0.0f);
            // First triangle - top left
            face[1] = new Vector3(-1f, 1f, 0.0f);
            // First triangle - top right
            face[2] = new Vector3(1f, 1f, 0.0f);
            // Second triangle - top right
            face[3] = new Vector3(1f, 1f, 0.0f);
            // Second triangle - bottom right
            face[4] = new Vector3(1f, -1f, 0.0f);
            // Second triangle - bottom left
            face[5] = new Vector3(-1f, -1f, 0.0f);

            Matrix RotY90 = Matrix.CreateRotationY(-(float)Math.PI / 2f);
            Matrix RotX90 = Matrix.CreateRotationX(-(float)Math.PI / 2f);

            for (int i = 0; i <= 2; i++) {

                // Front face
                vertexes[i] = new VertexPositionNormalTexture(
                    face[i] + Vector3.UnitZ, 
                    Vector3.UnitZ,
                    Texcoords
                );
                vertexes[i + 3] = new VertexPositionNormalTexture(
                    face[i + 3] + Vector3.UnitZ,
                    Vector3.UnitZ,
                    Texcoords
                );
                // Back face
                vertexes[i + 6] = new VertexPositionNormalTexture(
                    face[2 - i] - Vector3.UnitZ,
                    -Vector3.UnitZ,
                    Texcoords
                );
                vertexes[i + 6 + 3] = new VertexPositionNormalTexture(
                    face[5 - i] - Vector3.UnitZ,
                    -Vector3.UnitZ,
                    Texcoords
                );

                // Left face
                vertexes[i + 12] = new VertexPositionNormalTexture(
                     Vector3.Transform(face[i], RotY90) - Vector3.UnitX,
                     -Vector3.UnitX, 
                     Texcoords
                );
                vertexes[i + 12 + 3] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[i + 3], RotY90) - Vector3.UnitX,
                    -Vector3.UnitX, 
                    Texcoords
                );
                // Right face
                vertexes[i + 18] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[2 - i], RotY90) + Vector3.UnitX,
                    Vector3.UnitX,
                    Texcoords
                );
                vertexes[i + 18 + 3] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[5 - i], RotY90) + Vector3.UnitX,
                    Vector3.UnitX,
                    Texcoords
                );

                // Top face
                vertexes[i + 24] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[i], RotX90) + Vector3.UnitY,
                    Vector3.UnitY,
                    Texcoords
                );
                vertexes[i + 24 + 3] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[i + 3], RotX90) + Vector3.UnitY,
                    Vector3.UnitY,
                    Texcoords
                );
                // Bottom face
                vertexes[i + 30] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[2 - i], RotX90) - Vector3.UnitY,
                    -Vector3.UnitY,
                    Texcoords
                );
                vertexes[i + 30 + 3] = new VertexPositionNormalTexture(
                    Vector3.Transform(face[5 - i], RotX90) - Vector3.UnitY,
                    -Vector3.UnitY,
                    Texcoords
                );

            }

            return vertexes;
        }
    }
}

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:28:56+00:00Added an answer on June 14, 2026 at 6:28 pm

    I would put this in a comment but i dont have the prividge to do so yet.

    I do not have XNA installed here so i cannot test this, but it looks as if your faces are drawn to face the wrong direction.

    Faces will always have a visible and a see through side. go through your faces and flip them over. you will see that they appear and disappear when you do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have been unable to fix a problem with Java Unicode and encoding. The
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.