[Solved] Weird texture bug.

Well this one is beyond me.

Win 10, desktop gl project.

I draw this it works.

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            GraphicsDevice.SamplerStates[0] = new SamplerState() { Filter = TextureFilter.Point, AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp };
            GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true, DepthBufferFunction = CompareFunction.LessEqual };

            GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.Solid, CullMode = CullMode.None };
            effect.Texture = BasicTextures.green;
            effect.World = worldGrid;
            gridUp.Draw(GraphicsDevice, effect);

            base.Draw(gameTime);
        }

…

I add a couple more draws and the first draw goes black ?

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            GraphicsDevice.SamplerStates[0] = new SamplerState() { Filter = TextureFilter.Point, AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp };
            GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true, DepthBufferFunction = CompareFunction.LessEqual };

            GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.Solid, CullMode = CullMode.None };
            effect.Texture = BasicTextures.green;
            effect.World = worldGrid;
            gridUp.Draw(GraphicsDevice, effect);

            GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.Solid, CullMode = CullMode.None };
            effect.Texture = BasicTextures.checkerBoard;
            effect.World = worldSurface;
            surfaceTerrain.meshSurface.Draw(GraphicsDevice, effect);

            GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };
            effect.Texture = BasicTextures.red;
            effect.World = worldSurface;
            surfaceTerrain.meshControlGrid.Draw(GraphicsDevice, effect);

            base.Draw(gameTime);
        }

…

The first draw is basically the same as the second.
Well its using a different ivertex structure, could that cause this ?

        public void Draw(GraphicsDevice gd, Effect effect)
        {
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, (indices.Length / 3), VertexPositionTexture.VertexDeclaration);
            }
        }

        public void Draw(GraphicsDevice gd, Effect effect)
        {
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, (indices.Length / 3), VertexPositionNormalTexture.VertexDeclaration);
            }
        }

God… never mind i just saw the bug in my own post.

effect.Texture = BasicTextures.green.

.
Its drawing aqua in my picture.

.
.
Had a ref misnamed cause i copy pasted the refs and forgot to rename one.
basically i had missassigned aqua twice and my green was never assigned so it was null
I been looking at this for 2 hours scratching my head.

Glad you figured it out :slight_smile: Sometimes you just need to “talk” to someone about it and you find your own solution, haha.

1 Like