
2D-Text at world coodinates
Posted Wednesday, 13 May, 2009 - 08:54 by entity inHello,
I need text annotations in 3d space. Using the startup tutorial, I calculated my screen coordinates from world coordinates using Glu.Project.
But unfortunately the triangle and text rotate in opposite directions. What is wrong here? Is this approach efficient for a decent number of strings, say 100?
float angle = 0; public override void OnRenderFrame(RenderFrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); angle += 0.1f; Glu.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); GL.Rotate(angle, Vector3.UnitZ); GL.Begin(BeginMode.Triangles); GL.Color3(Color.LightYellow); GL.Vertex3(-1.0f, -1.0f, 4.0f); GL.Color3(Color.LightYellow); GL.Vertex3(1.0f, -1.0f, 4.0f); GL.Color3(Color.LightSkyBlue); GL.Vertex3(0.0f, 1.0f, 4.0f); GL.End(); int[] Viewport = new int[4]; double[] ModelViewMatrix = new double[16]; double[] ProjectionMatrix = new double[16]; GL.GetInteger(GetPName.Viewport, Viewport); GL.GetDouble(GetPName.ModelviewMatrix, ModelViewMatrix); GL.GetDouble(GetPName.ProjectionMatrix, ProjectionMatrix); Vector3 winPos; Glu.Project(new Vector3(-1.0f,-1.0f,4.0f), ModelViewMatrix, ProjectionMatrix, Viewport, out winPos); printer.Begin(); GL.Translate(winPos); printer.Print("Vertex 1", sans_serif, Color.SpringGreen); printer.End(); SwapBuffers(); }
Thanks,
entity


Comments
Re: 2D-Text at world coodinates
TextPrinter.Begin()sets up an ortho projection with the Y-axis inverted: (0, 0) is the top-left corner of the screen. This was done to match the coordinate system used by GDI+ (and almost every other 2d library out there) and simplify the process of text layout.You could either take this into account, or you could simply avoid
TextPrinter.Begin()/End()and set up your own projection. If you opt for the latter approach, note that you have to scale text by2.0f / Widthand2.0f / Heightto make it render with the correct size.Re: 2D-Text at world coodinates
If TextPrinter.Begin() / End() are optional and only modify the projection matrix, maybe they should have names that communicate this more directly?
Re: 2D-Text at world coodinates
I'm open to suggestions.
Re: 2D-Text at world coodinates
If Begin()/End() is not used, where will the text go?
I mean, is it placed in the xy plane, centered around origo, or where?
Re: 2D-Text at world coodinates
If you don't use Begin()/End(), this becomes your responsibility. The TextPrinter will then use the projection, modelview and texture matrices you have set up.
Re: 2D-Text at world coodinates
But the text will go somewhere.
If I print an 'A' given Identity matrix in projection/modelview, what will it's coordinates be (x,y,z)?