Sign in to follow this  

Moving from XNA 3.1 to XNA 4.0. Nothing is now drawn on the screen for any of my draw methods?

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I decided to upgrade to XNA 4.0 and have spent this weekend getting rid of all the errors. Unfortunately nothing that used to draw correctly in 3.1 will draw at all in 4.0.

My forward rendering draw method is as follows:

[code]

protected override void Draw(GameTime gameTime)
{
graphicsDevice.Clear(clearColour);

SetSharedParameters(activeCamera);

// [Deferred Rendering]
//deferredRendering.Draw(gameTime);

// [Forward Rendering]

// [Draw 3D]
modelDrawer.Begin(activeCamera);
quadrangleDrawer.Begin(activeCamera);
shapeDrawer.Begin(activeCamera);
wireShapeDrawer.Begin(activeCamera);

octree.Draw(gameTime);


modelDrawer.End();
quadrangleDrawer.End();
shapeDrawer.End();
wireShapeDrawer.End();
}
[/code]

The octree used to draw all the entities in view of the camera, but now it draws nothing.

Here is an example of a draw method for wire shapes:

[code]

private void FlushDrawing()
{
if (IndexCount > 0)
{
//game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
game.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;

Effect effect = game.Effects["PreTransformed"];

// Set parameters for current camera
game.SetSharedParameters(camera);

vertexBuffer.SetData(Vertices, 0, VertexCount, SetDataOptions.Discard);
indexBuffer.SetData(Indices, 0, IndexCount, SetDataOptions.Discard);

game.GraphicsDevice.Indices = indexBuffer;
game.GraphicsDevice.SetVertexBuffer(vertexBuffer);

effect.CurrentTechnique.Passes[0].Apply();

game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, VertexCount, 0, IndexCount / 2);
}

IndexCount = 0;
VertexCount = 0;
}
[/code]

The shared parameters are set to an .fx file that uses the 'shared' keyword:

[code]

public void SetSharedParameters(Camera camera)
{
Vector2 halfPixel = new Vector2();
halfPixel.X = 1.0f / graphicsDevice.Viewport.Width;
halfPixel.Y = -1.0f / graphicsDevice.Viewport.Height;

parameter_CameraPosition.SetValue(camera.Position);
parameter_CameraUp.SetValue(camera.Up);
parameter_HalfPixel.SetValue(halfPixel);
parameter_InverseViewProjection.SetValue(Matrix.Invert(camera.ViewProjectionMatrix));
parameter_Projection.SetValue(camera.ProjectionMatrix);
parameter_View.SetValue(camera.ViewMatrix);
parameter_ViewProjection.SetValue(camera.ViewProjectionMatrix);
}
[/code]

The .fx file for drawing lines is as follows:

[code]

//=============================================
//----------- [XNA to HLSL Variables] ---------
//=============================================

shared float4x4 ViewProjection;

//=============================================
//------------------ [Structs] ----------------
//=============================================

struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Colour : COLOR0;
};

struct VertexShaderOutput
{
float4 Position : POSITION0;
float4 Colour : COLOR0;
};

struct PixelShaderOutput
{
float4 Colour : COLOR0;
};

//=============================================
//------------ Technique: Default -------------
//=============================================

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

output.Position = mul(input.Position, ViewProjection);
output.Colour = input.Colour;

return output;
}

PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
PixelShaderOutput output;

output.Colour = input.Colour;

return output;
}

technique Default
{
pass Pass0
{
AlphaBlendEnable = false; // No transparency

VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
[/code]

What haven't I set correctly?

Share this post


Link to post
Share on other sites

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this