0
\$\begingroup\$

I'm trying to toggle between wireframe and full mode while drawing a 3d model. So far I have this

 rs = new RasterizerState();

In my update method:

  if (state.IsKeyDown(Keys.V))
        {
            rs.FillMode = FillMode.WireFrame;
        }

        if (state.IsKeyDown(Keys.C))
        {
            rs.FillMode = FillMode.Solid;
        }

and in my draw method:

  GraphicsDevice.RasterizerState = rs;

But I get the error:

 Cannot change read-only RasterizerState. State objects become read-only the first time they are bound to a GraphicsDevice. To change property values, create a new RasterizerState instance.

What am I doing wrong here?

\$\endgroup\$
2
\$\begingroup\$

The error you are getting appears to explain both the problem and the solution:

Cannot change read-only RasterizerState. State objects become read-only the first time they are bound to a GraphicsDevice. To change property values, create a new RasterizerState instance.

You can't change rasterizer state objects once you have bound them to a graphics device (which happens the first time you assign rs to GraphicsDevice.RenderState). Instead, create a new rasterizer state with your desired settings and assign that to the device.

Save the previous reference if you expect to ever want to reuse that old state (as you probably do, once you disable the wireframe mode).

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Oh awesome. I should read the errors more carefully \$\endgroup\$ – Christian Frantz Apr 9 '14 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.