Sign in to follow this  

Positsioning units with 2D

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How to use pixels instead of positioning units(0.5f) with 2D. Or does anyone have macro to convert pixels to and via versa. Also how to set color units(1.0f - 0.0f) to RGB (255) or hex (0x000000)

Share this post


Link to post
Share on other sites
1) Make sure an orthographic projection is used (glOrtho / gluOrtho2D) and make sure the width and height of the projection are the same as the width and height of the viewport.

E.g.:

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, 0, h);

Where 'w' and 'h' are the width and height of the desired viewport, respectively.

2) IIRC, when glColor*i is used, the largest integer passed becomes the peak of the scale. So if I wrote "glColor3i(100, 50, 0);", it would be equivalent to "glColor3f(1.0, 0.5, 0.0);".

Share this post


Link to post
Share on other sites
Quote:
Original post by biggoron
2) IIRC, when glColor*i is used, the largest integer passed becomes the peak of the scale. So if I wrote "glColor3i(100, 50, 0);", it would be equivalent to "glColor3f(1.0, 0.5, 0.0);".

Integer colors are scaled according to the maximum possible value of the integer type, not the maximum value of the parameters passed. If that was the case, how could you ever set the color to something where none of the components are at maximum? What would the glColor3i version of glColor3f(0.5, 0.5, 0.5) be, for example?

glColor3i(100, 50, 0) is the same as glColor2f(0.00000004657, 0.00000002328, 0), assuming a 31-bit range on signed integers.

And note that the ub-variant is no different than any other integer-type function. glColor3ub(255, 128, 0) is the same as glColor3f(255/255, 128/255, 0/255), which is glColor3f(1, 0.5020, 0). There's no special treatment for ub-variants. It's range just happens to be "intuitive" becuase it's range is commonly used, that's all.

Share this post


Link to post
Share on other sites

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this