I feel like i'm missing something obvious here.
I am unable to get CImg's color-interpolated 2D triangle to work as expected. To add to the confusion, it behaves differently on my system version of CImg (cimg_version 245) to the latest in Github (cimg_version 300).
If i draw a simple filled triangle, everything works as expected. If i specify a colour for each vertex, there is a difference depending what CImg version i use:
cimg_version 245: Interpolation works to some extent but colour channels are clamped to 255 for values greater than 0. You can see this by comparing the center and right triangles in the image titled "CImg version: 245". The center image fades from {0, 0, 0} to {255, 255, 255} whereas the right image goes from {100, 100, 100} to {255, 255, 255}.
cimg_version 300: In this version, i was unable to get any interpolation to work.
So, am i missing a setting to enable interpolation or should i file a bug report?
#include <iostream>
#include <stdio.h>
#include "CImg.h"
using namespace cimg_library;
#define TITLE_LEN 100
int main() {
char title [TITLE_LEN];
snprintf(title, TITLE_LEN, "CImg version: %d", cimg_version);
std::cout << title << "\n";
CImg<unsigned char> image(600, 200, 1, 3, 0);
CImgDisplay main_disp(image, title);
const unsigned char black[3] = {0, 0, 0};
const unsigned char grey[3] = {100, 100, 100};
const unsigned char white[3] = {255, 255, 255};
// Left
image.draw_triangle(100, 10, 10, 190, 190, 190, grey);
// Center
image.draw_triangle(300, 10, 210, 190, 390, 190, white, black, white);
// Right
image.draw_triangle(500, 10, 410, 190, 590, 190, white, grey, white);
image.display(main_disp);
while (!main_disp.is_closed()) {
main_disp.wait();
}
return 0;
}
[EDIT] Forgot to include what i'm running on:
$ lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:printing-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
$ uname -a
Linux lapdancer 5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
developer of CImg here. It looks like a bug indeed. I'll try to fix it ASAP. Thanks. Do not hesitate to fill an issue on our github site (https://github.com/dtschump/CImg/issues) when you encounter such strange behaviors.
EDIT : This should be fixed now, with github.com/dtschump/CImg/issues/332. New pre-release have been pushed on the CImg website.