Problem with Transparency

lord_8's picture

I have used your library to add an in game console to my game, and have been very impressed. I do have a problem thoughin that after the first time I render a line of text, all black parts of my model become see through and the lighting visibly changes. Do you know why? I am just using the DrawString method and have followed your intro tutorial.

Thanks,

Mike 

Cygon's picture

Some RenderStates are changed...

That's a common problem because the Effect used by Nuclex.Fonts changes some render states that are likely to affect your drawing commands.

The render states changed are:

  • AlphaBlendEnable = true

  • DepthEnable = false

  • DepthWriteEnable = false

  • StencilEnable = false

  • CullMode = None

It would be possible to save and restore the render states during the DrawString() call, but I didn't do so because some state changes are rather costly in terms of performance.

The best solution for you would be to use the new TextManager class and perform your DrawString() calls through this class. It will queue any drawing operations until the end of the frame (or until you call its Draw()) method yourself. After that, you can restore the render states indicated above. As a side effect, you will also get a performance increase :)

lord_8's picture

Thanks for the help. I have

Thanks for the help. I have now succesfully migrated to the TextManager class and while I was at it version 1.2 as well!

The line that was causing me the difficulties was:

device.RenderState.StencilEnable = true;

with this at the start of my draw method it was problem solved. Thanks very much,

Mike

 

Anonymous's picture

what is this TextManager

what is this TextManager class u speak of... cus it seems to be used in the Nuclex.fonts however im still getting the problem and i cant type device.RenderState.StencilEnable = true;

 is there a download i need, or a tutorial i can look at?

Cygon's picture

It's Part of Nuclex.Fonts

TextManager is a GameComponent that's provided with the latest Nuclex.Fonts release. The demo application already shows you how to use it.

The TextManager will not magically solve the problem. You still have to put device.RenderState.StencilEnable = true and the other settings I posted above after you've finished drawing text or alternative when a new frame is drawn.

If you're get an error when typing device.RenderState.StencilEnable = true; try this.graphics.GraphicsDevice.RenderState.StencilEnable = true; instead. device is just just some variable / field in Mike's code.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <br> <a> <em> <strong> <u> <i> <b> <cite> <blockcode> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <pre> <span>
  • You can highlight code with any of the following tags: <blockcode>

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.