1

This is my first 3D application that I have created so sorry if this seems like such a simple question but I have searched the internet and these forums to try and find an answer.

I am attempting to draw a simple string to the screen using the spriteBatch.DrawString command.

The application is similar to Minecraft with a large quantity of cubes on the screen. To sort out lag issues all the cubes are created via vertices and hardware instancing has been implemented.

The issue is when ever I call spriteBatch.Begin() all the other cubes appear differently. I am aware that spritebatch changes some states so the following lines have been added

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

Bellow is the code used to draw the player

public void Draw(Matrix view, Matrix projection)
    {
        effect.CurrentTechnique = effect.Techniques["TexturedNoShading"];
        effect.Parameters["xView"].SetValue(view);
        effect.Parameters["xProjection"].SetValue(projection);
        effect.Parameters["xWorld"].SetValue(world);
        effect.Parameters["xTexture"].SetValue(texture);

        device.SetVertexBuffer(myVertexBuffer);
        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
        }
    }

This is the code used in the main class to draw everything

        RasterizerState rs = new RasterizerState();  
        rs.CullMode = CullMode.None;
        rs.FillMode = FillMode.Solid;
        device.RasterizerState = rs;

        GraphicsDevice.BlendState = BlendState.Opaque;
        GraphicsDevice.DepthStencilState = DepthStencilState.Default;
        _map.Draw(_camera.GetCamera(), projection);
        _player.Draw(_camera.GetCamera(), projection);


        spriteBatch.Begin();
        spriteBatch.DrawString(Text, "test", new Vector2(100, 100), Color.White);
        spriteBatch.End();

I would like to post screenshots of the problem to show it more clearly but as this is my first post I do not have the rights to post images. I'm happy to email the images to people.

I'm happy to include any other information but it seems like such a simple problem.

Thanks for any help that you may be able to provide.

Sam Vickery

4

1 に答える 1

0

I can see where you set your vertex buffer, but can't see you setting the index buffer anywhere?

it would normally be right around where you set your vertexbuffer. something like this:'

device.SetVertexBuffer(myVertexBuffer);
device.Indices = myIndexBuffer;
于 2013-02-27T14:49:48.507 に答える