Jump to content
• Advertisement

# Positsioning units with 2D

This topic is 3996 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

##### Share on other sites
Advertisement
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

##### Share on other sites
2. Either use glColor3i as suggested or use the more intuitive one, glColor3ub(255, 128, 0) - that is, glColor3ub(RGB byte color values).

#### Share this post

##### Share on other sites
Quote:
 Original post by biggoron2) 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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013592
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!