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 6477537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:57:38+00:00 2026-05-25T06:57:38+00:00

I am making (another) MineCraft clone, and I’ve run into an interesting problem. I

  • 0

I am making (another) MineCraft clone, and I’ve run into an interesting problem. I have a public enum that lists all the cube types a particular cube can be, and I have a 3d array that holds cubes. Each cube has a specific type, and I iterate through this array to get the vertices for each cube, then pass those vertices to a vertex buffer designated for a particular cube type. When I create a random array of cubes, or a single cube, and tell it what texture it should be everything draws as expected. I’m now trying to figure out how to draw a random “surface” of grass cubes, and fill everything below those on the y-axis with dirt cubes. The strangest thing is happening though, the top most cube is dirt and it fills all the bottom ones with grass cubes! When I disable the loop to fill the underground with dirt, the top most cube is displaying grass as intended.

Here is what I believe to be the relevant parts of the code. Here is where the cube type is set:

            // Create a random surface level
        Perlin perlin = new Perlin();

        for (int x = 0; x < Game.ChunkWidth_X; x++)
        {
            for (int z = 0; z < Game.ChunkDepth_Z; z++)
            {
                double XVal = Convert.ToDouble(x) * 1.1;
                double ZVal = Convert.ToDouble(z) * 1.1;
                double YVal = Game.ChunkHeight_Y / 2 * 1.1;

                double PerlinValue = perlin.GetValue(XVal, YVal, ZVal);
                int YVal_new = Convert.ToInt32(YVal + (PerlinValue * 10));
                if (YVal_new > Game.ChunkHeight_Y - 1) { YVal_new = Game.ChunkHeight_Y - 1; }
                if (YVal_new < 0) { YVal_new = 0; }

                // Set the grass cube
                Cube NewCube = new Cube(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(x, YVal_new, z));
                NewCube.cubeType = CubeType.Grass;
                CubeGrid[x, YVal_new, z] = NewCube;

                // Fill below it with dirt
                for (int y = YVal_new - 1; y >= 0; y--)
                {
                    Cube NewCube2 = new Cube(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(x, y, z));
                    NewCube2.cubeType = CubeType.Dirt;
                    CubeGrid[x, y, z] = NewCube2;
                }

                // Fill above it with air
                for (int y = YVal_new + 1; y < Game.ChunkHeight_Y; y++)
                {
                    Cube NewCube2 = new Cube(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(x, y, z));
                    NewCube2.cubeType = CubeType.Air;
                    CubeGrid[x, y, z] = NewCube2;
                }

            }
        }

This is where I pull the vertices to put into the appropriate buffer:

            Dictionary<CubeType, List<VertexPositionNormalTexture>> DrawableVertices = new Dictionary<CubeType, List<VertexPositionNormalTexture>>();

        // Get the proper vertices for each cube type and put in the appropriate dictionary
        for (int x = 0; x < Game.ChunkWidth_X; x++)
        { 
            for (int z = 0; z < Game.ChunkDepth_Z; z++)
            {
                for (int y = 0; y < Game.ChunkHeight_Y; y++)
                {
                    CubeGrid[x,y,z].CreateVertices();
                    string test = CubeGrid[x, y, z].cubeType.ToString();

                    foreach (VertexPositionNormalTexture TargetVertex in CubeGrid[x, y, z].DisplayableVertices)
                    {
                        if (!DrawableVertices.ContainsKey(CubeGrid[x, y, z].cubeType))
                        {
                            List<VertexPositionNormalTexture> NewList = new List<VertexPositionNormalTexture>();
                            NewList.Add(TargetVertex);
                            DrawableVertices.Add(CubeGrid[x, y, z].cubeType, NewList);
                        }
                        else
                        {
                            DrawableVertices[CubeGrid[x, y, z].cubeType].Add(TargetVertex);
                        }
                    }
                }
            }
        }

Here is the second part of it:

            foreach (KeyValuePair<CubeType, List<VertexPositionNormalTexture>> KVP in DrawableVertices)
        {
            VertexBuffer cubeBuffer = new VertexBuffer(device, typeof(VertexPositionNormalTexture), KVP.Value.Count, BufferUsage.WriteOnly);
            cubeBuffer.SetData(KVP.Value.ToArray());

            // Update our collection of vertex buffers
            CubeType_VertexBuffers[KVP.Key] = cubeBuffer;

            // Get the triangle count for the buffer
            CubeType_TriangleCount[KVP.Key] = KVP.Value.Count / 3;

        }

Lastly, here is my draw:

            // Go through each vertex buffer we have created, and draw it.
        foreach (KeyValuePair<CubeType, VertexBuffer> KVP in CubeType_VertexBuffers)
        {
            foreach (EffectPass pass in testEffect.CurrentTechnique.Passes)
            {
                if (CubeType_TriangleCount[KVP.Key] > 0) // if this buffer has triangles, draw it.
                {
                    pass.Apply();
                    testEffect.View = camera.ViewMatrix;
                    testEffect.TextureEnabled = true;
                    testEffect.Projection = camera.ProjectionMatrix;
                    testEffect.World = worldMatrix;
                    testEffect.Texture = CubeType_Texture[KVP.Key];

                    device.SetVertexBuffer(KVP.Value);
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, CubeType_TriangleCount[KVP.Key]);
                }
            }
        }


        base.Draw(gameTime);

The weirdest thing is that when I manually set cube types everything draws with the proper texture as expected. What other things should I try to troubleshoot? I tried making a specific effect for each cube type to no avail.

  • 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-05-25T06:57:39+00:00Added an answer on May 25, 2026 at 6:57 am

    After trying a bunch of random things in desperation, I found a fix for this. It turns out that if you use the same BasicEffect for different textures, it only uses the last texture assigned to it. I was iterating through a list of VertexBuffers and assigning a different texture for each one. By the time everything made it over to the video card, only the last texture used was rendered, or so it appears.

    The solution was to create a separate BasicEffect for each texture I needed and assign only the VertexBuffers needed to the particular BasicEffect.

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

Sidebar

Related Questions

I'm making another Pong clone using HTML5 canvas and JavaScript. The problem I'm having
I'm making another app's window topmost to ensure that a click in my app
I am making a POST to another php file that I want to render
I am writing a program that creates a stack using linked lists. I have
Im making an asynchronous call from a class to another. Here is my actual
I am making a plugin for another program and so I am trying to
I'm making a game. Now if my player goes to another level the music
I'm making an insert statement, the id field has auto_increment, another field must get
Making my first steps with NHibernate, I'm trying to have it creating my Tables
Making an adobe flex ui in which data that is calculated must use proprietary

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.