a.samii's picture

problem with using text alongside the graphics

Hey 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

Comment viewing options

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

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:

ITextPrinter printer = new TextPrinter();
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 10f));

Also, remove the printer.Prepare statement and draw text like this:

printer.Begin();
printer.Draw(zRot.ToString(), font);
printer.End();

These changes will improve performance and there's a chance they could help with this issue.

a.samii's picture

"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.