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

oh that's it, I don't have to change my code?

the Fiddler's picture

No, it's simply an implementation of the OpenGL API. Almost everything will work out of the box.

Edit: Sorry, I wasn't paying attention. You don't have to switch to GLUT or change your code at all. Mesa3d will simply 'intercept' your OpenGL calls and emulate them in software.

nicolas's picture

yeah I noticed that, but it drastically slows down my app.
actually it freezes my app haha. not good.

edit: mesa3d doesn't freeze my whole app, just the 3d control inside it

the Fiddler's picture

Ah, yes, there's some kind of incompatibility between Mesa3d and the GLControl. AFAICT, this is a Mesa3d issue - the following patch fixes it:

@@ -1662,16 +1662,10 @@ void WMesaSwapBuffers( HDC hdc )
/* If we're swapping the buffer associated with the current context
* we have to flush any pending rendering commands first.
*/
- if (pwc->hDC == hdc) {
- _mesa_notifySwapBuffers(ctx);
+ _mesa_notifySwapBuffers(ctx);
 
- BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,
- pwfb->dib_hDC, 0, 0, SRCCOPY);
- }
- else {
- /* XXX for now only allow swapping current window */
- _mesa_problem(NULL, "wmesa: can't swap non-current window");
- }
+ BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height,
+ pwfb->dib_hDC, 0, 0, SRCCOPY);
}

In plain english, remove the conditional found in wmesa.c, line 1662 (i.e. change the code so _mesa_notifySwapBuffers and BitBlt are always called).

nicolas's picture

hmm now it sort of renders my 3d screen on my test pc, except there's a bug when I resize. on the terminal the 3d screen is plain black (empty).

this is the code in wmesa.c:

void WMesaSwapBuffers( HDC hdc )
{
    GET_CURRENT_CONTEXT(ctx);
    WMesaContext pwc = wmesa_context(ctx);
    WMesaFramebuffer pwfb = wmesa_lookup_framebuffer(hdc);
 
    if (!pwfb) {
        _mesa_problem(NULL, "wmesa: swapbuffers on unknown hdc");
        return;
    }
 
	_mesa_notifySwapBuffers(ctx);
 
	BitBlt(pwfb->hDC, 0, 0, pwfb->Base.Width, pwfb->Base.Height, pwfb->dib_hDC, 0, 0, SRCCOPY);
}
nicolas's picture

I tried again without Mesa3d and found the line in my own code where the error is thrown

this is the entire rendering code (I put the GL.TexCoord2 stuff in a list to try to speed up the process)

the error is thrown on the 2nd line i.e. the first PushMatrix call

GL.MatrixMode(MatrixMode.Projection); //Select The Projection Matrix
GL.PushMatrix(); //Store The Projection Matrix
GL.LoadIdentity(); //Reset The Projection Matrix
 
GL.Ortho(0, WindowSize.Width, 0, WindowSize.Height, -1, 1); //Set Up An Ortho Screen
 
GL.MatrixMode(MatrixMode.Modelview); //Select The Modelview Matrix
GL.PushMatrix(); //Store The Modelview Matrix
GL.LoadIdentity(); //Reset The Modelview Matrix
 
GL.Color3(Color.White);
 
GL.Translate(Location.X, Location.Y, 0);
 
GL.CallList(render);
 
GL.MatrixMode(MatrixMode.Projection); //Select The Projection Matrix
GL.PopMatrix(); //Restore The Old Projection Matrix
GL.MatrixMode(MatrixMode.Modelview); //Select The Modelview Matrix
GL.PopMatrix();
nicolas's picture

Update: I replaced the PushMatrix calls with the workaround you mentioned on the previous page. Now my code looks like this:

System.Collections.Generic.Stack<Matrix4> projection_matrix_stack = new System.Collections.Generic.Stack<Matrix4>();
System.Collections.Generic.Stack<Matrix4> modelview_matrix_stack = new System.Collections.Generic.Stack<Matrix4>();
Matrix4 matrix;
 
matrix = new Matrix4(); 
GL.GetFloat(GetPName.ProjectionMatrix, out matrix.Row0.X);
projection_matrix_stack.Push(matrix);
GL.MatrixMode(MatrixMode.Projection); //Select The Projection Matrix
GL.LoadIdentity(); //Reset The Projection Matrix
 
GL.Ortho(0, WindowSize.Width, 0, WindowSize.Height, -1, 1); //Set Up An Ortho Screen
 
matrix = new Matrix4(); 
GL.GetFloat(GetPName.ModelviewMatrix, out matrix.Row0.X);
modelview_matrix_stack.Push(matrix);
GL.MatrixMode(MatrixMode.Modelview); //Select The Modelview Matrix
GL.LoadIdentity(); //Reset The Modelview Matrix
 
GL.Translate(Location.X, Location.Y, 0);
 
GL.Color3(Color.White);
GL.CallList(render);
 
matrix = modelview_matrix_stack.Pop();
GL.LoadMatrix(ref matrix);
 
matrix = projection_matrix_stack.Pop();
GL.LoadMatrix(ref matrix);

Funny enough it works on the terminal, but I only if I change the camera view to top view. In 3d view I get a blank screen. But at least it stopped crashing.