1 #define GL_GLEXT_PROTOTYPES 1
9 #include "texture_enum.h"
11 #define HSV_WHEEL_SIZE 128
13 void draw_hsv_wheel(float y, float rad, float theta, float value)
15 glUseProgramObjectARB(0);
17 glActiveTexture(GL_TEXTURE0);
19 glEnable(GL_TEXTURE_2D);
21 glBindTexture(GL_TEXTURE_2D, HSV_WHEEL);
23 glActiveTexture(GL_TEXTURE1);
25 glBindTexture(GL_TEXTURE_2D, 0);
27 glActiveTexture(GL_TEXTURE0);
30 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
36 glTexCoord2f(0.0f, 1.0f);
39 glTexCoord2f(1.0f, 1.0f);
40 glVertex2f(0.2f * 9.0f / 16.0f, y);
42 glTexCoord2f(1.0f, 0.0f);
43 glVertex2f(0.2f * 9.0f / 16.0f, y + 0.2f);
45 glTexCoord2f(0.0f, 0.0f);
46 glVertex2f(0.0f, y + 0.2f);
51 glDisable(GL_TEXTURE_2D);
52 glColor3f(0.0f, 0.0f, 0.0f);
55 glVertex2f((0.1f + rad * cos(theta) * 0.1f) * 9.0f / 16.0f, y + 0.1f - rad * sin(theta) * 0.1f);
59 glDisable(GL_TEXTURE_2D);
62 glColor3f(0.0f, 0.0f, 0.0f);
63 glVertex2f(0.22f * 9.0f / 16.0f, y);
64 glVertex2f(0.24f * 9.0f / 16.0f, y);
66 glColor3f(1.0f, 1.0f, 1.0f);
67 glVertex2f(0.24f * 9.0f / 16.0f, y + 0.2f);
68 glVertex2f(0.22f * 9.0f / 16.0f, y + 0.2f);
73 glColor3f(0.0f, 0.0f, 0.0f);
76 glVertex2f(0.23f * 9.0f / 16.0f, y + value * 0.2f);
79 glColor3f(1.0f, 1.0f, 1.0f);
82 void draw_saturation_bar(float y, float saturation)
84 glUseProgramObjectARB(0);
88 glDisable(GL_TEXTURE_2D);
91 glColor3f(0.0f, 0.0f, 0.0f);
92 glVertex2f(0.0f * 9.0f / 16.0f, y + 0.02f);
93 glVertex2f(0.0f * 9.0f / 16.0f, y);
95 glColor3f(1.0f, 1.0f, 1.0f);
96 glVertex2f(0.2f * 9.0f / 16.0f, y);
97 glVertex2f(0.2f * 9.0f / 16.0f, y + 0.02f);
102 glColor3f(0.0f, 0.0f, 0.0f);
105 glVertex2f(0.2f * (saturation / 4.0f) * 9.0f / 16.0f, y + 0.01f);
108 glColor3f(1.0f, 1.0f, 1.0f);
111 void make_hsv_wheel_texture()
113 static unsigned char hsv_pix[HSV_WHEEL_SIZE * HSV_WHEEL_SIZE * 4];
114 for (int y = 0; y < HSV_WHEEL_SIZE; ++y) {
115 for (int x = 0; x < HSV_WHEEL_SIZE; ++x) {
116 float yf = 2.0f * y / (float)(HSV_WHEEL_SIZE) - 1.0f;
117 float xf = 2.0f * x / (float)(HSV_WHEEL_SIZE) - 1.0f;
118 float rad = hypot(xf, yf);
119 float theta = atan2(yf, xf);
122 hsv2rgb(theta, rad, 1.0f, &r, &g, &b);
123 hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 0] = lrintf(r * 255.0f);
124 hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 1] = lrintf(g * 255.0f);
125 hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 2] = lrintf(b * 255.0f);
128 hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 3] = 0;
130 hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 3] = 255;
136 glBindTexture(GL_TEXTURE_2D, HSV_WHEEL);
138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
140 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, HSV_WHEEL_SIZE, HSV_WHEEL_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, hsv_pix);
144 void read_colorwheel(float xf, float yf, float *rad, float *theta, float *value)
146 if (xf < 0.2f && yf < 0.2f) {
147 float xp = 2.0f * xf / 0.2f - 1.0f;
148 float yp = -(2.0f * yf / 0.2f - 1.0f);
149 *rad = hypot(xp, yp);
150 *theta = atan2(yp, xp);
154 } else if (xf >= 0.22f && xf <= 0.24f) {