diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-05-20 07:41:03 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-05-20 07:41:03 +0200 |
| commit | 09a819b2ef927adf5239a73f91cdfcefd6774688 (patch) | |
| tree | 8602814faa153aae01acc95a557d45b24c028f3b /src/color.c | |
| parent | 70bf7ac330545f14ab9babddfdf0cb5df9e9ee69 (diff) | |
| download | mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.tar.gz mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.tar.bz2 mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.zip | |
Added colors with 1D texture
Diffstat (limited to 'src/color.c')
| -rw-r--r-- | src/color.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/color.c b/src/color.c index 2ad4bad..24ca2f2 100644 --- a/src/color.c +++ b/src/color.c @@ -5,22 +5,36 @@ static Color color_hsl_to_rgb(ColorHSL color_hsl); -Color *color_palette_new(Color *palette, int iterations) +unsigned int color_texture_new(int count) { - ColorHSL hsl; + ColorHSL hsl; + Color *palette; + unsigned int texture; - palette = realloc(palette, sizeof(Color) * (iterations + 1)); + palette = malloc(sizeof(Color) * count); if (palette == NULL) - return NULL; - for (int i = 0; i < iterations; i++) + return 0; + for (int i = 0; i < count; i++) { - hsl.h = (int)(255.0 * ((double)i / (double)iterations)); + hsl.h = (uint8_t)(255.0 * ((double)i / (double)count)); hsl.s = 150; hsl.l = 127; palette[i] = color_hsl_to_rgb(hsl); } - palette[iterations].data = 0x0; - return palette; + for (int i = 0, j = count - 1; i < j; i++, j--) + { + Color tmp = palette[i]; + palette[i] = palette[j]; + palette[j] = tmp; + } + + GL_CALL(glGenTextures(1, &texture)); + GL_CALL(glBindTexture(GL_TEXTURE_1D, texture)); + GL_CALL(glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); + GL_CALL(glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); + GL_CALL(glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, count + 1, 0, GL_RGB, GL_UNSIGNED_BYTE, palette)); + free(palette); + return texture; } static Color color_hsl_to_rgb(ColorHSL color_hsl) |
