nicolas's picture

TextPrinter problem

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

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?


Comments

Comment viewing options

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

this isn't on the terminal with the S3 card, it's on my pc which has an Intel Q35 chipset

the Fiddler's picture

To use NPOT textures, your drivers need to fully implement OpenGL 2.1 (corrected my previous post). If they do not, as was the case with the intel drivers last time I checked, you either have to fall back to ARB_texture_non_power_of_two or modify your textures to obey the power-of-two requirement.

nicolas's picture

edit: I changed the dimensions of my jpeg from 50x90 to 64x128 and behold, it worked. Pretty lame solution though, haha. Thanks for the help in any case.

nicolas's picture

Maybe I should start a new topic for this since the TextPrinter route is obviously not an option...

But anyway I resized my bitmap to POT dimensions but it looks pretty weird upon rendering - see attachments.

GL.Enable(EnableCap.Texture2D);
 
GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
 
GL.GenTextures(1, out texture);
GL.BindTexture(TextureTarget.Texture2D, texture);
 
BitmapData data = bmpLegend.LockBits(new System.Drawing.Rectangle(0, 0, bmpLegend.Width, bmpLegend.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
 
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width / 2, data.Height / 2, 0, OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
 
bmpLegend.UnlockBits(data);
 
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

...

GL.Begin(BeginMode.Quads);
GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(0.0f, bmpLegend.Height);
GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(bmpLegend.Width, bmpLegend.Height);
GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(bmpLegend.Width, 0.0f);
GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(0.0f, 0.0f);
GL.End();

bmpLegend width and height is 64x128

AttachmentSize
screenshot.jpg6.94 KB
legend.jpg6.19 KB
the Fiddler's picture

This line:
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width / 2, data.Height / 2, 0, OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
should probably be:
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

The TextPrinter should work after the latest changes. If it doesn't, and you can reproduce problem with Examples.exe (or another simple test case), I'll probably be able to fix the problem from the stacktrace, as long as it includes the actual error line in OpenTK.Utilities.dll (you'll need OpenTk.Utilities.pdb for that).

nicolas's picture

the textures fix works fine, thanks!

I'll try the textwriter next

nicolas's picture

ok the texturing still make my terminal crash, always the same error. I copied both opentk and opentk utilities pdb files to that location but I only get a stacktrace for opentk:

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

the Fiddler's picture

This exception is not a bug, it just informs you that OpenTK has detected an OpenGL error. This is to make your life easier while developing your application - otherwise, you'd have to call GL.GetError by hand to detect errors, which is both time-consuming and error-prone.

The next step is to follow the stacktrace up from there and find where exactly the error occurs in your application. Note that there's a good chance your code is correct and you are simply hitting a driver bug. In that case, you'll have to add a workaround - very annoying, but this is the current state of afairs in the world of graphics.

How do you know if it's a driver bug? Test on different hardware: if the error only occurs on one specific video card, there's a good chance it's a driver bug. If you don't have hardware to test, try using the Mesa3D OpenGL renderer. This is a very solid implementation of OpenGL 2.1+ that is easy to build and deploy (comes with a visual studio solution - simply build and copy the 4 dlls to your project directory).

nicolas's picture

that's probably it since it doesn't crash on my development pc, only on the terminal.

so if I use Mesa3d, my application will use this software opengl renderer instead of the driver's? does that mean I have to use GLUT instead of OpenTK?

the Fiddler's picture

Yes - simply copy the Mesa3d dlls to the same directory as the exe. Mesa3d is rather slow, but it is stable. It's a good way to test modern OpenGL features on environments that don't support them, like virtual machines or old video cards.