how to change the length of a unit?thank you !

First ,I defined the Orthographic Projection
gluOrtho2D (0.0 ,(GLdouble)w, 0.0,(GLdouble)h);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
and a window of size 500*500. At last, a unit equals the size of a pixel.But when the window
become bigger,the unit become bigger too .

What i want to get is whenever the size of the window is changed ,a unit always corresponds to
a pixel.any suggestion is appreciative!

you need to do that every time your window dimensions change, with the new dimensions as parameters…

hello,charliejay ,thank you very much!
But i still don’t know how and where i should modify my program when the window dimensions change,would you please explain that in detail?
Furthermore,this is transformation part:
void reshape (int w, int h)
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0 ,(GLdouble)w, 0.0,(GLdouble)h);
glMatrixMode (GL_MODELVIEW);
Thank you so much!

The code you posted should work as it is.

Of course, you have to register the reshape function after creating the window:

ok,i understand .
thank you all very much!