View Full Version : how to change the length of a unit?thank you !

05-31-2006, 02:19 AM
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!

05-31-2006, 03:05 AM
you need to do that every time your window dimensions change, with the new dimensions as parameters...

05-31-2006, 03:44 AM
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!

05-31-2006, 05:58 AM
The code you posted should work as it is.

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

05-31-2006, 06:23 AM
ok,i understand .
thank you all very much!