
problem with using text alongside the graphics
Posted Saturday, 20 September, 2008 - 19:40 by a.samii inHey everyone,
I am working on an engineering visualization program using OpenTK. I should display the amount of model rotation around x,y and z axes in every output that I get from my program. I am using the following sample code as the text and model renderer (both is done in the same function):
private void glControl1_Paint(object sender, PaintEventArgs e)
{
if (!loaded) return;
GL.MatrixMode(MatrixMode.Modelview);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.PushMatrix();
// When the user presses the arrow keys, zRot changes relevantly //
GL.Rotate(zRot, 0.0f, 0.0f, 1.0f);
ITextPrinter printer = new TextPrinter();
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 10f));
TextHandle[] handle = new TextHandle[1];
GL.Color3(0f, 1f, 0f);
printer.Prepare(zRot.ToString(), font, out handle[0]);
printer.Begin();
printer.Draw(handle[0]);
printer.End();
handle[0].Dispose();
font.Dispose();
//...
// ... Creating my simple models ...
//...
GL.PopMatrix();
glControl1.SwapBuffers();
}
The program , works fine, but after some rotation, the model stops rotating but the counter goes on counting. How I can solve the problem.
Thanks in forward.


Comments
Re: problem with using text alongside the graphics
Try placing a couple of
GL.GetError()calls and check if they return non-0. Maybe some state gets invalidated and it shows up this way.The following is probably not related, but try moving the following code outside the Paint function:
Also, remove the
printer.Preparestatement and draw text like this:These changes will improve performance and there's a chance they could help with this issue.
I got the problem
"GL.popmatrix" should be placed above the text renderer. It seems that text objects change the ModelView matrix. So the current ModelView matrix should be stored before the text renderer.