View Full Version : How to get number of units?

01-11-2007, 05:11 PM
Hi All,

I was wondering if there is a way to get the number of units on a window? For example, if my viewport is 600 pixels wide, can I somehow convert this to OpenGL units? So instead of drawing at origin 0,0 ( the center ) I want to start drawing 1 unit from the left of the screen. How do I figure that out?

many many thanks for your help!


01-11-2007, 08:30 PM
The units are determined by the parameters to the projection matrix, so you already know, and have total control over, the units because you're tellning OpenGL what units you want.

Simplest case is the orthographic projection matrix. Units ranges from [left, right] in horizontal direction, where left and right are the corresponding parameters to glOrtho/gluOrtho2D, and same for vertical direction, but witht he bottom and top parameters.

01-12-2007, 05:20 PM
Hmmmm... I don't think I understand. If I use something like gluOrtho2D(0.0,screen_width,0.0,screen_height);
it's still in pixels, right? But when I draw to the screen, the units are definitely not in pixel units. It's some other unit that I don't understand how it's defined. Anyway... I don't need 2D. Are you saying I can define the units myself? How is this done?

thanks for your reply!


01-12-2007, 10:59 PM

It is much better then I can explain :-)