Positsioning units with 2D
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)
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);".
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);".
2. Either use glColor3i as suggested or use the more intuitive one, glColor3ub(255, 128, 0) - that is, glColor3ub(RGB byte color values).
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement