glutBitmapCharacter - partial letters

  • Follow


Hi,

I use glutBitmapCharacter() to realize a TextEntry Widget. I solve the
problem on text strings which are longer than the Widgets width by
displaying only the active scrolled part of the text. But a problem is
that I could only display a full letter or not. So how could I display
an partial letter? Could I render the font somewhere else in a not on
screen region and then copy only a part of this letters in a texture
somewhere?

Or any other ideas how to solve this.

regards
Andreas
0
Reply Andreas 5/6/2006 5:19:52 PM

Andreas Volz wrote:
> I use glutBitmapCharacter() to realize a TextEntry Widget. I solve the
> problem on text strings which are longer than the Widgets width by
> displaying only the active scrolled part of the text. But a problem is
> that I could only display a full letter or not. So how could I display
> an partial letter? Could I render the font somewhere else in a not on
> screen region and then copy only a part of this letters in a texture
> somewhere?
>
> Or any other ideas how to solve this.

Enable GL_SCISSOR_TEST, than change clipping region with glScissor.

w.
0
Reply Wojciech 5/6/2006 7:07:52 PM


Am Sat, 6 May 2006 19:07:52 +0000 (UTC) schrieb Wojciech Muła:

> Andreas Volz wrote:
> > I use glutBitmapCharacter() to realize a TextEntry Widget. I solve
> > the problem on text strings which are longer than the Widgets width
> > by displaying only the active scrolled part of the text. But a
> > problem is that I could only display a full letter or not. So how
> > could I display an partial letter? Could I render the font
> > somewhere else in a not on screen region and then copy only a part
> > of this letters in a texture somewhere?
> >
> > Or any other ideas how to solve this.
> 
> Enable GL_SCISSOR_TEST, than change clipping region with glScissor.

The idea does work, but I've a little problem with it. I use GLUT and
it seems GLUT has a mirrored y-axis. Because of this reason I do this
before I draw my overlay widgets:

  // invert the y axis, down is positive (GLUT has different Y than openGL) 
  glScalef (1, -1, 1);
  // move the origin from the bottom left corner
  // to the upper left corner (GLUT has different Y than openGL)
  glTranslatef (0, -h, 0);

This works for most OpenGL draw commands, but not glScissor. So mirror 
the y-axis I would need each time the window height. But the problem is 
that it's a little hard to access the windows height from inside the widgets
draw routine. Any ideas? Is there a GLUT version of glScissor with its own
axis?

regards
Andreas
0
Reply Andreas 5/7/2006 10:42:56 AM

Andreas Volz wrote:
> The idea does work, but I've a little problem with it. I use GLUT and
> it seems GLUT has a mirrored y-axis.

Do you use glOrtho/gluOrtho2D?  Maybe you called one of these functions
with wrong parameters.

w.
0
Reply Wojciech 5/7/2006 11:35:42 AM

Am Sun, 7 May 2006 11:35:42 +0000 (UTC) schrieb Wojciech Muła:

> Andreas Volz wrote:
> > The idea does work, but I've a little problem with it. I use GLUT
> > and it seems GLUT has a mirrored y-axis.
> 
> Do you use glOrtho/gluOrtho2D?  Maybe you called one of these
> functions with wrong parameters.

I use this function before drawing widgets:

//Set orthographic projection before draw the widgets
void cgutils::enableOrthographicProjection ()
{
  //Get the actual windows size
  int w;
  int h;
  GLint viewport[4];
  glGetIntegerv(GL_VIEWPORT, viewport);
  w = viewport[2];
  h = viewport[3];

  // switch to projection mode
  disableLightingDeepTest ();
  glMatrixMode (GL_PROJECTION);
  // save projection matrix
  glPushMatrix ();
  // reset matrix
  glLoadIdentity ();
  // set a 2D orthographic projection
  glOrtho (0, w, 0, h, -2, 1);
  // invert the y axis, down is positive (GLUT has different Y than
openGL) glScalef (1, -1, 1);
  // move the origin from the bottom left corner
  // to the upper left corner (GLUT has different Y than openGL)
  glTranslatef (0, -h, 0);
  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity ();
}

and this after drawing all widgets:

//Restore the projection after drawed the widget
void cgutils::disableOrthographicProjection ()
{
  glMatrixMode (GL_PROJECTION);
  glPopMatrix ();
  enableLightingDeepTest ();
}

But don't ask me about details. I didn't write this both functions myself.
Someone else wrote this part of the library. Is there a problem?

regards
Andreas
0
Reply Andreas 5/7/2006 12:22:20 PM

Andreas Volz wrote:
>> Do you use glOrtho/gluOrtho2D?  Maybe you called one of these
>> functions with wrong parameters.
>
> I use this function before drawing widgets:
> [...]
>   // set a 2D orthographic projection
>   glOrtho (0, w, 0, h, -2, 1);
>   // invert the y axis, down is positive (GLUT has different Y than
> openGL) glScalef (1, -1, 1);
>   // move the origin from the bottom left corner
>   // to the upper left corner (GLUT has different Y than openGL)
>   glTranslatef (0, -h, 0);

It looks good.  However it is strange, that GLUT swaps y-axis. I also
use GLUT (under Linux&Window) and draw simple GUI, and have never such
problem.  What happen when you comment both glScalef and glTranslate?

BTW check answer 9.030:
http://www.opengl.org/resources/faq/technical/transformations.htm

w.
0
Reply Wojciech 5/7/2006 1:10:00 PM

Wojciech Mu?a wrote:
> Andreas Volz wrote:
>> The idea does work, but I've a little problem with it. I use GLUT and
>> it seems GLUT has a mirrored y-axis.
> 
> Do you use glOrtho/gluOrtho2D?  Maybe you called one of these functions
> with wrong parameters.
> 

glScissor() isn't altered by the projection matrix.



-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

In science it often happens that scientists say, 'You know
that's a really good argument; my position is mistaken,'
and then they actually change their minds and you never
hear that old view from them again.  They really do it.
It doesn't happen as often as it should, because scientists
are human and change is sometimes painful.  But it happens
every day.  I cannot recall the last time something like
that happened in politics or religion.

- Carl Sagan, 1987 CSICOP keynote address

0
Reply fungus 5/7/2006 3:11:45 PM

Am Sun, 7 May 2006 13:10:00 +0000 (UTC) schrieb Wojciech Muła:

> Andreas Volz wrote:
> >> Do you use glOrtho/gluOrtho2D?  Maybe you called one of these
> >> functions with wrong parameters.
> >
> > I use this function before drawing widgets:
> > [...]
> >   // set a 2D orthographic projection
> >   glOrtho (0, w, 0, h, -2, 1);
> >   // invert the y axis, down is positive (GLUT has different Y than
> > openGL) glScalef (1, -1, 1);
> >   // move the origin from the bottom left corner
> >   // to the upper left corner (GLUT has different Y than openGL)
> >   glTranslatef (0, -h, 0);
> 
> It looks good.  However it is strange, that GLUT swaps y-axis. I also
> use GLUT (under Linux&Window) and draw simple GUI, and have never such
> problem.  What happen when you comment both glScalef and glTranslate?

Perhaps I found my problem. I assumed that the OpenGL 2D origin is
upper left, but it is lower left. It seems this is an common pitfall:

http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
-> 12. OpenGL's Lower Left Origin

All other widgets in our toolkit have upper left as orgin, this is the
reason why to rotate the y-axis. But I don't understand why the font is
rendered at the correct position with the same coordinates as the
glScissor. See how I draw the font:

void cgutils::drawString (const Point& inPoint, void *font, const
string& str, const Color& c) {
  glColor3f (c.red (), c.green (), c.blue ());
  glRasterPos2f (inPoint.getX(), inPoint.getY());

  for (string::const_iterator str_it = str.begin ();
       str_it != str.end ();
       str_it++)
  {
    char ch = *str_it;

    glutBitmapCharacter(font, ch);
  }
}

I assume glRasterPos2f() has the same 2D coordinate system as
glScissor(). Is this correct. So what is the problem?

I could easy solve it with glGetIntegerv(GL_VIEWPORT, viewport) and
mirroring the y-axis. But I think this is only a workaround.

regards
Andreas
0
Reply Andreas 5/7/2006 3:23:11 PM

Andreas Volz wrote:
> 
> I assume glRasterPos2f() has the same 2D coordinate system as
> glScissor(). Is this correct. So what is the problem?
> 

No.

RasterPos transforms the coordinate by the viewing
matrices. glScissor does not.




-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

In science it often happens that scientists say, 'You know
that's a really good argument; my position is mistaken,'
and then they actually change their minds and you never
hear that old view from them again.  They really do it.
It doesn't happen as often as it should, because scientists
are human and change is sometimes painful.  But it happens
every day.  I cannot recall the last time something like
that happened in politics or religion.

- Carl Sagan, 1987 CSICOP keynote address

0
Reply fungus 5/9/2006 9:02:54 AM

8 Replies
317 Views

(page loaded in 0.099 seconds)


Reply: