Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Questions about GLUT bitmap fonts and scale

93 views
Skip to first unread message

John McDermon

unread,
Apr 27, 1998, 3:00:00 AM4/27/98
to

Using OpenGL 1.1 I'm trying to create a specialized 2D drawing program. It
will only be able to draw circles, but they will be in scale to one
another. Users will input the size and a label for several circles. The
program will render them to the screen in a default position and the user
will use the mouse to select and drag the circles to new positions.

Question 1: controlling scale of the circles
I create a 400 x 400 pixel clipping plane with these calls in init();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 400.0, 0.0, 400.0);
glMatrixMode(GL_MODELVIEW);

In main() I create the initial window to match this size with:
glutInitWindowSize(400, 400);
glutInitWindowPosition(50, 50);
glutCreateWindow("Single");

This creates a 2 x 2 unit window centered on (0, 0). I created a scaling
function that calculates the scale reduction I need to apply using the sum
of all the circles radii. I than use this number in the display() function
to be sure that all the circles will fit in the window:
glPushMatrix();
glScalef(scale_factor, scale_factor, 1.0);
drawCircle();
glPopMatrix();

Is there a better way to control the scale of the window? If for example
each circle represented a room in a home design, the equivilant of a 100' x
100' would be plenty big to hold all the rooms of a home. I'd like to use
the basic coordinates, wanting each unit to represent a foot. so I can
calculate the raduis and thus the vertices of each circle directly.

Question 2: putting a bitmapped font label in the center of each circle
I want each of the circles I described above to have a label, say "Living Room"
Using the following code I can display a bitmapped font in the circle:
p=temp;
glRasterPos2f(location[0], location[1]);
len = (int) strlen(p);
for (i = 0; i < len; i++) {
glutBitmapCharacter(FONT, p[i]);
But the test is left justified starting at the center of the circle and I'd
like it centered in the x-dimension.

I built a routine that calculated the width of the text string:
for (p=temp; *p; p++)
text_width += glutBitmapWidth(FONT, *p);
But this returns the width in pixels which have no relation to the scaled
circle's size. Is there a way to map from pixels width to the scaled
MODELVIEW matrix so I can divide the width of the text string by 2 and then
center it?

Question 3: is there a way to embed a NewLine that will work with a text
string passed to glutBitmapCharacter(FONT, p[i]); I got it to print "NL"
and "VT", but I haven't succeeded in getting two lines of text.

-- John
remove the nojunk from the return address to reply via email
+-----------------------------------------------------------+
| John McDermon, jmcd...@lanl.gov, New Mexico, USA |
| |
| "All the while I was alone, the past was close behind. |
| I've seen a lot of women, but she never escaped my mind, |
| and I just grewwww, tangled up in blue" Bob Dylan |
+-----------------------------------------------------------+


Andy Vesper

unread,
Apr 30, 1998, 3:00:00 AM4/30/98
to

John McDermon wrote:

: Using OpenGL 1.1 I'm trying to create a specialized 2D drawing


program. It
: will only be able to draw circles, but they will be in scale to one
: another.

I see you don't want your program to ever be considered 'square'. :-)

: Question 1: controlling scale of the circles


: I create a 400 x 400 pixel clipping plane with these calls in init();
: glMatrixMode(GL_PROJECTION);
: glLoadIdentity();
: gluOrtho2D(0.0, 400.0, 0.0, 400.0);
: glMatrixMode(GL_MODELVIEW);
:
: In main() I create the initial window to match this size with:
: glutInitWindowSize(400, 400);
: glutInitWindowPosition(50, 50);
: glutCreateWindow("Single");
:
: This creates a 2 x 2 unit window centered on (0, 0).

The call to gluOrtho2D should map object space coordinates of 0.0
to to 400.0 to window space coordinates 0.0 to 400.0. If
you draw a point at 200.0,200.0 it should be in the center of your
window.

:I created a scaling


: function that calculates the scale reduction I need to apply using the
sum
: of all the circles radii. I than use this number in the display()
function
: to be sure that all the circles will fit in the window:
: glPushMatrix();
: glScalef(scale_factor, scale_factor, 1.0);
: drawCircle();
: glPopMatrix();
:
: Is there a better way to control the scale of the window?

That's basically it.

:If for example


: each circle represented a room in a home design, the equivilant of a
100' x
: 100' would be plenty big to hold all the rooms of a home. I'd like to
use
: the basic coordinates, wanting each unit to represent a foot. so I can
: calculate the raduis and thus the vertices of each circle directly.

gluScalef will do that just fine. I hope you accept coordinates
in feet and inches, and don't make your users figure out the
decimal equivalents.

> Question 2: putting a bitmapped font label in the center of each circle
> I want each of the circles I described above to have a label, say "Living Room"
> Using the following code I can display a bitmapped font in the circle:
> p=temp;
> glRasterPos2f(location[0], location[1]);
> len = (int) strlen(p);
> for (i = 0; i < len; i++) {
> glutBitmapCharacter(FONT, p[i]);
> But the test is left justified starting at the center of the circle and I'd
> like it centered in the x-dimension.
>
> I built a routine that calculated the width of the text string:
> for (p=temp; *p; p++)
> text_width += glutBitmapWidth(FONT, *p);
> But this returns the width in pixels which have no relation to the scaled
> circle's size. Is there a way to map from pixels width to the scaled
> MODELVIEW matrix so I can divide the width of the text string by 2 and then
> center it?

You can do this, but I would continue to use glRasterPos2f
to set the raster position to the center of the circle, then call

glBitmap (0, 0, 0.0, 0.0, -text_width/2.0, 0.0, NULL);

which will move the raster position in window space.



> Question 3: is there a way to embed a NewLine that will work with a text
> string passed to glutBitmapCharacter(FONT, p[i]); I got it to print "NL"
> and "VT", but I haven't succeeded in getting two lines of text.

No, you need to move the raster position around yourself.

You could push the raster position at the left edge onto the
attribute stack, draw the first line, pop the raster position,
use glBitmap to move the raster position down one line, etc.

--
Andy V, OpenGL Alpha Geek (never a Digital spokesperson)
mailto:andrew...@digital.NoSpamPlease
(To send mail to me, change "NoSpamPlease" to "com".)


dumb


newsreader

software

junk

0 new messages