6 #include "interpolation.h"
18 Color255(std::string src) {
19 std::vector<std::string> strings;
22 if (strings.size() >= 1) r = ::atoi(strings[0].c_str());
23 if (strings.size() >= 2) g = ::atoi(strings[1].c_str());
24 if (strings.size() >= 3) b = ::atoi(strings[2].c_str());
25 if (strings.size() >= 4) a = ::atoi(strings[3].c_str());
29 class GradientTexture : public Texture{
35 //unsigned int texture_id;
37 GradientTexture(Color255 _c0, Color255 _c1, Color255 _c2) {
38 this->c0 = _c0; this->c1 = _c1; this->c2 = _c2;
40 glGenTextures(1, &this->texture_id);
42 unsigned char* data = (unsigned char*)malloc(256*4);
44 // Do texture generation
45 for (int i = 0; i < 256; i++) {
46 Color255* a = &this->c0;
47 Color255* b = &this->c1;
49 if (i >= 128) { a = b; b = &this->c2; }
51 data[i * 4 + 0] = lerpT(a->r, b->r, (float)(i % 128) / 128.0f);
52 data[i * 4 + 1] = lerpT(a->g, b->g, (float)(i % 128) / 128.0f);
53 data[i * 4 + 2] = lerpT(a->b, b->b, (float)(i % 128) / 128.0f);
54 data[i * 4 + 3] = lerpT(a->a, b->a, (float)(i % 128) / 128.0f);
57 glBindTexture(GL_TEXTURE_2D, this->texture_id);
58 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
61 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
69 /*void bindOnSlot(int slot = 0) {
70 glActiveTexture(GL_TEXTURE0 + slot);
71 glBindTexture(GL_TEXTURE_2D, this->texture_id);