nicolas's picture

TextPrinter problem

private readonly TextPrinter printer = new TextPrinter(TextQuality.Default);
private readonly Font font = new Font("Verdana", 10);
GL.Translate(300F, 270F, 0F);
printer.Print("TEST", font, Color.White);

this works fine on my development pc running vista (intel duo cpu 3ghz, 2gb ram) but not on my test pc running xp (via nehemiah cpu 666 mhz, 240 mb ram). this test pc is actually a touchscreen terminal. on this terminal I see a bunch of dots and lines, seemingly the top pixel line of "TEST" but I'm not sure. the video adapter on the terminal is "S3 graphics twister".

is this a performance issue? is my test pc too weak to run textprinter?


Comment viewing options

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

Now, that's strange - the PushMatrix/PopMatrix calls are balanced. Three things could cause this:

  1. Calling TextPrinter.Begin() without calling .End(). Since it works on your other PC, this is not it.
  2. The (texture) matrix stack is too small. I say texture, because this is the only PushMatrix call that was added between 0.9.7 (where it worked) and 0.9.x-dev (where it fails).
  3. This is yet another driver bug.

This may be a lot to ask, but are there line numbers connected to the exception? I would like to see which GL.PushMatrix call is at fault here.

The error is easy to work around, but I'd like to make sure I'm not barking at the wrong tree.

nicolas's picture

no no line number sorry, this is all I get

the Fiddler's picture

I think you need to copy the "OpenTK.Utilities.pdb" file along with the executable.

nicolas's picture

************** Exception Text **************
OpenTK.Graphics.OpenGLErrorException: StackOverflow
at OpenTK.Graphics.GraphicsContext.CheckErrors() in C:\VS2008Projects\Test Projects\opentk\Source\OpenTK\Graphics\GraphicsContext.cs:line 284
at OpenTK.Graphics.ErrorHelper.Dispose() in C:\VS2008Projects\Test Projects\opentk\Source\OpenTK\Graphics\GL\ErrorHelper.cs:line 69
at OpenTK.Graphics.GL.PushMatrix() in C:\VS2008Projects\Test Projects\opentk\Source\OpenTK\Graphics\GL\GL.cs:line 18834
at OpenTK.Graphics.Text.GL1TextOutputProvider.Begin() in C:\VS2008Projects\Test Projects\opentk\Source\Utilities\Graphics\Text\GL1TextOutputProvider.cs:line 193
at OpenTK.Graphics.TextPrinter.Begin() in C:\VS2008Projects\Test Projects\opentk\Source\Utilities\Graphics\TextPrinter.cs:line 237

the Fiddler's picture

Alright, thanks! So this is happening when pushing the projection matrix - strange. I'll do some tests and see what comes up.

nicolas's picture

Regarding texturing: when I try to adapt your "test" program from wednesday into using my own generated bitmap instead of "logo.jpg", I don't see anything, just a white rectangle on a blue background.

I then tried converting it to jpeg but still nothing on the screen. I've attached the file I'm trying to texture. I already changed the the pixelformat to match that of the jpeg file:

GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
GL.GenTextures(1, out texture);
GL.BindTexture(TextureTarget.Texture2D, texture);
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
GL.PixelStore(PixelStoreParameter.UnpackRowLength, bitmap.Width);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, data.Width/2, data.Height/2, 0, OpenTK.Graphics.PixelFormat.Rgb, PixelType.UnsignedByte, data.Scan0);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Linear);

I even tried replacing logo.jpg with a random jpeg and that didn't work either. Does this have something to do with alpha levels? I'm pretty new to texturing, as you might be able to tell.

legend.jpg1.98 KB
the Fiddler's picture

Try this:

BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
// No pixel store necessary here, as we are loading the whole image
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width/2, data.Height/2, 0, OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

Always use Rgba textures (the hardware doesn't support Rgb anyway - it has to make them Rgba first). Also, (System.Drawing) PixelFormat.Format32bppArgb is actually OpenTK.Graphics.PixelFormat.Bgra.

nicolas's picture

Nope still nothing

this is my render code:

            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.TexCoord2(0.0f, 1.0f);
            GL.Vertex2(-0.6f, -0.4f);
            GL.TexCoord2(1.0f, 1.0f);
            GL.Vertex2(0.6f, -0.4f);
            GL.TexCoord2(1.0f, 0.0f);
            GL.Vertex2(0.6f, 0.4f);
            GL.TexCoord2(0.0f, 0.0f);
            GL.Vertex2(-0.6f, 0.4f);
the Fiddler's picture

You have to enable texturing (GL.Enable) and disable mipmaps (GL.TexParameter(...) with TextureMinFilter.Linear).

nicolas's picture

I know, I am using your test script. Like I said, it works fine with the included "logo.jpg" but not with any other image file.

Any news on the TextPrinter issues?