lets save that renderstate dammit

badkarma's picture

hi there, firstly id like to say that the nuclex fonts component is very very nice, i love the quality of the output, which is why im determined to get this working properly.

to see my problem, take the tutorial as basic code and add one model to render, a decent model with a couple of textures and watch the chaos as you render your scene. 

i really really really want to get this working properly.  i tired encapsulating the drawstring method within a spritebatch.begin and spritebatch.end to preserve the renderstate, but it seems as though the drawstring method is changing something else which affects 3d rendering.

 

any ideas? 

Cygon's picture

Maybe the TextManager class can do this

Outch, sorry for the late answer :)

Saving and restoring the render state each time the DrawString() method is called would cause a severe performance impact, this is why the BitmapFont class doesn't do this in its current state.

The 1.1.0 release has a new helper GameComponent class, the TextManager. This class queues text drawing until the end of the frame (so it's drawn on top of everything else). This might be the ideal place to save and restore the render states, because this way, it needs to be done only once.

I'll see what I can do for the upcoming 1.1.1 release!

Anonymous's picture

I just lost one day of dev.

I just lost one day of dev. time because of this retarded feature. Maybe you should say that your library change the whole fcking rendering state...

Cygon's picture

Maybe you should take a...

Maybe you should take a closer look at the design of XNA. It's just not feasible to save and restore the render state just in case. And, btw, using a SpriteBatch or any advanced rendering effect for a model would fuck up you render states just as well.

Also, see this post by Shawn Hargreaves

I'll see if I can put up a big fat notice about the render state changes, but it's really something you should get used to when working with effect files.

badkarma's picture

thanks for your reply mr

thanks for your reply mr nuclex person,

i see what u r saying in your post, but i guess the question still remains is, what states are being changed to cause the rendering issues, rendering text last doesnt seem to hold any benefit in regards to the rendering problems, so i still need to know what values to set my render states to afterwards.

Cygon's picture

Here's a List

I included the effect used by Nuclex.Fonts in the post 1.0.0 releases (see Nuclex.Fonts/Source/Effects/FontEffect.cs) The exact render states changed are:

  • AlphaBlendEnable = true

  • DepthEnable = false

  • DepthWriteEnable = false

  • StencilEnable = false

  • CullMode = None

This best option to handle this would be to use the TextManager class for queueing, call its Draw() method manually (instead of adding the TextManager to the game's GameComponent collection) and then reset those render states.

The default values for a new graphics device are, as far as I can tell, false, true, true, false, Clockwise (in the same order as the render states indicated above).

badkarma's picture

as borat would say, "itsa

as borat would say, "itsa verry niiice"

 thx :)

grasmo's picture

great:)

Thanks for your work, it's very cool!

One sidenote: the default cullmode is CullMode.CullCounterClockwiseFace.

I wrote two tiny functions that save the 4 renderstate-members and set it back - now it works like a charm:)

greets

grasmo

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