Hi to everyone, I’m trying to build some kind of GUI for my small geometry viewer nad trying to understand how to do it in the most efficient way. I attach a picture of what I’m going to do something like this:
[ATTACH=CONFIG]1549[/ATTACH]
That is, text must begin always at the point with coordinates (5,5) pixels from the left bottom corner, no matter how the window is reshaped.
For now, I’ve found the only one solution to do this:
GLint Width = 600, Height = 600;
GLsizei CurrentWidth = 960, CurrentHeight = 600;
void display(void)
{
// Drawing geometry
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_LINES, 0, 12);
// Drawing text
glViewport(5, 5, CurrentWidth - 5, CurrentHeight - 5);
glRasterPos2f(-1, -1);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, sample_character);
glViewport((CurrentWidth - Width) / 2, (CurrentHeight - Height) / 2, Width, Height);
glFlush();
}
and the following code is used for reshaping function:
void reshape(GLsizei w, GLsizei h)
{
CurrentWidth = w, CurrentHeight = h;
glViewport((w - Width) / 2, (h - Height) / 2, Width, Height);
}
I use glViewport several times, first is to draw geometry in the centre of window, second is to draw the text and then to restore it to the previous state. It feels this approach is not so good, it would be amazing if someone can review this chunk of code and maybe suggest some better way to deal with it.
p.s. I’m allowed only to use the old glut.
Thank you for your replies.