How to maintain object size when resizing a window???

Hi All,

I am trying to figure out how to maintain an objects size when resizing a window?

ex. A rectangle is 40 pixels high and 40 pixels wide when my window is 600x600. I want it to be 40 pixels high and 40 pixels wide when I shrink the window to 300x300.

Thanks for any replies.
jpummill

Easy…
h0 = original height of the window
h1 = new height of the window
fov0 = original field of view
fov1 = new field of view

fov1 = atan( tan( fov0 / 2.0 ) * h1 / h0 ) * 2.0;
gluPerspective( fov1, w1/h1, near, far );

[This message has been edited by Jambolo (edited 06-28-2002).]

Thanks for the reply Jambolo.

The reason that I was asking is because I want to create a user interface that alwasy stays the same size, even when my window is being resized.

Am I going about this all wrong? Is there a better way.

If you’re doing something 2d like a gui there is a much easier way. call gluOrtho2D(width/-2, width/2, height/-2, height/2)where width and height are the window dimensions in pixels. Then each vertex should approximately map to each pixel. It should exactly map to each pixel if the width and height are equal to the renderable space of the window and both are even numbers.

or:

gluOrtho2d(0,width,0,height);

so every integral coordinate maps to a pixel.(0,0) is the lower left corner and (width,height) the upper right one.

Thanks guys,

The glortho information sounds like what I was really looking for. I will give it a shot.

I really appreciate all the help!