+
+static unsigned int gen_grad_tex(int sz, const Vec3 &c0, const Vec3 &c1)
+{
+ unsigned char *pixels = new unsigned char[sz * 3];
+ for(int i=0; i<sz; i++) {
+ float t = (float)i / (float)(sz - 1);
+ Vec3 color = c0 + (c1 - c0) * t;
+ pixels[i * 3] = color.x * 255;
+ pixels[i * 3 + 1] = color.y * 255;
+ pixels[i * 3 + 2] = color.z * 255;
+ }
+
+ unsigned int tex;
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_1D, tex);
+
+ glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+
+ glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, sz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+
+ delete [] pixels;
+
+ return tex;
+}