teichgraf's picture

TextPrinter implementation [commited]

I read the code of the Utilities / TextPrinter, because I need a similar Begin() / End() state saving. In Begin() I see that you are calling:

//...
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
//...

I think this changes the current BlendFunc, which won't be reset afterwards in End()? Maybe it would be better to call

GL.PushAttrib(GL_COLOR_BUFFER_BIT);

before and GL.PopAttrib(GL_COLOR_BUFFER_BIT) in End().
See ManPage PushAttrib

And why is the viewport member defined to have the length 6? The viewport could only contain 4 floats or am I wrong?
See ManPage GlGet

Edit 04-07-2008:
Added tiny patch for TextPrinter:

GL.PushAttrib(AttribMask.TextureBit);
GL.PushAttrib(AttribMask.EnableBit);
GL.PushAttrib(AttribMask.ColorBufferBit);

changed to:

GL.PushAttrib(AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit);

This reduces the 6 calls for push / pop to 2 calls. Not that much, but better than none.

AttachmentSize
TextPrinter.zip411 bytes

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Thanks, good catches. Fixed.

teichgraf's picture

I added a tiny patch to the first post (see above).

the Fiddler's picture

Thanks, implemented. Every little bit helps :)

teichgraf's picture

You forgot to change the TextPrinter.End() method from

...
GL.PopAttrib();
GL.PopAttrib();
GL.PopAttrib();
...

to one Pop.

...
GL.PopAttrib();
...

As a result I get a StackUnderflow OpenGLError, because we do just one GL.PushAttrib(...);

the Fiddler's picture

Oops!

logixoul's picture

Hi,
i've got a related issue
TextPrinter.End() leaves the MatrixMode at Projection, which i found very unexpected and it wreaked some havoc in my code :)

i think the pushes/pops should be reordered so the MatrixMode is left at Modelview.

the Fiddler's picture

Thanks for catching this, it's a bug. Will fix!