Window Resizing

Hello,
I am just getting started with OpenGL, and I need to fix the following problem with some existing code.
The program has white boxes around text. The text stays at a constant size no matter how the window is resized. I need to keep the white boxes surrounding the text at a constant size too, so the text is always surrounded by the box.
However, when I resize a window, the boxes change in dimensions. How can I keep these boxes at a constant size, regardless of the dimensions of the window?

Thanks.

-Brennan Rusnell

I assume you mean you are drawing the box using GL_LINES or something? And thus the perspective view of the box gets smaller when the window gets smaller while the 2D text remains the same size?

If so, instead of drawing the box with fixed coordinates, you need to find the 2D screen coords of the text and use gluUnproject() to find the object/world space coords for your box. Then draw your box using these coords.

This way no matter your perspective, the box stays the same size on the screen.

I am using GL_POLYGON to draw the boxes.
And yes, the perspective view of the box gets smaller when the window gets smaller while the 2D text remains the same size.

How can I find the 2D screen coords?
How can I use gluUnproject()?

Thanks!

Originally posted by PickleWorld:
[b]I assume you mean you are drawing the box using GL_LINES or something? And thus the perspective view of the box gets smaller when the window gets smaller while the 2D text remains the same size?

If so, instead of drawing the box with fixed coordinates, you need to find the 2D screen coords of the text and use gluUnproject() to find the object/world space coords for your box. Then draw your box using these coords.

This way no matter your perspective, the box stays the same size on the screen.[/b]

“How can I find the 2D screen coords?”

Well this depends on how you are putting text on the screen? If you are lucky, the functions you are using will have a call to get the coords. If not you will just have to use trial and error I guess… assuming the text is always in the same place then the screen coords will always be the same.

If you are doing a glRasterPos() call then you are 1/2 way there, the coords for it will be the screen coords for one of the corners of your Quad.

“How can I use gluUnproject()?”

glUnProject(winX, winY, winZ, mv_matrix, proj_matrix, viewport, x, y, z);

winX, winY, winX are your screen coords (you can just use 0 for Z assuming you want it at the front).

mv_matrix is the modelview matrix, you can get it using glGetDoublev(GL_MODELVIEW_MATRIX, mv_matrix);

Do the same for proj_matrix (the projection matrix) and for the viewport use glGetIntegerv.

x, y, and z will be the returned world space coordinates.

Thanks!

This will take some time to digest - I just started with OpenGL two days ago.

I will post more if I need it.

Thanks again.