Login  Register

Need help understanding use of TextRenderer

Posted by Ryan McFall on Feb 07, 2021; 7:51pm
URL: https://forum.jogamp.org/Need-help-understanding-use-of-TextRenderer-tp4041009.html

I am a mostly self-taught OpenGL programmer teaching Computer Graphics at a small college - so I'm definitely not an expert OpenGL programmer by any means.

I am trying to develop an implementation of the board game "Monopoly", and am trying to write code that can render an individual property.  If you're not familiar with Monopoly, here's an image of the board

Image of a monopoly board

A "property" is one of the individual rectangles with a colored border at the top, such as "Connecticut Avenue" at the bottom left corner of the image.  Rendering the property itself is no problem, obviously.  Adding in the text using JOGL's TextRenderer is proving difficult, however.

The TextRenderer class seems to want to use pixels as the units for world coordinate system, as the documentation mentions that calling beginRendering will set up an orthographic projection based on the width/height passed to beginRenderering.  The documentation suggests passing the width and height of the GLAutoDrawable being drawn into as the parameters for beginRenderering.

If I pass drawable.getWidth() and drawable.getHeight(), and then draw text at (getWidth()/2, getHeight()/2), it draws text whose lower left corner is in the center of the drawable as expected.

I have learned to model domain objects, like the Monopoly properties, in their own coordinate space, usually placing their origin in the center of the object.  Then modeling transformations can be applied to transform the object appropriate based on the coordinate system representing the world being rendered.  For the property, I've modeled it using (0, 0) as the center, with the 4 vertices representing the property's coordinates being the appropriate combinations of (± WIDTH/2, ± HEIGHT/2).

I'm not sure how to model these domain objects independently like this and still use JOGL's TextRenderer code to render the property name and price.

What I have thought to do is to invert both the modelview and projection matrices to obtain a matrix that will allow me to know where in the viewport the property's vertices are being rendered, and using that to help me determine an appropriate (x, y) location to use within the coordinate system set up by TextRenderer.beginRendering.

I haven't yet tried this - is this an appropriate approach, or am I making the problem too difficult?

Thanks in advance for any ideas,
Ryan