Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

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 2702 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:



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();
}


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:



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;
}


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



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);
}


The .fx file for drawing lines is as follows:



//=============================================
//----------- [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();
}
}


What haven't I set correctly?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!