To put it as simply as possible, every time you specify a y
value to CImg, you need to first flip the coordinate system from what you want to what it offers. Perhaps the easiest way to do this would be to write your own function that converts the y
value for you:
unsigned int flip_y( unsigned int y, unsigned int height ) {
return height - y;
}
This would mean that every place you would have to specify y
, you would have to remember to use the function:
img.draw_text( x, y, "hello world!", ...);
// becomes
img.draw_text( x, flip_y( y, img.height() ), "hello world!", ...);
Understandably, this would get very tedious very fast, and forgetting to use flip_y
in a single situation could be quite time consuming to track down and fix.
As an alternative, you could make your own subclass of CImg
and wrapping all the functions that take y
values and inverts y
before passing the values to the original CImg
method. This would have the advantage of being able to work when passing references to your subclass to library functions expecting a CImg
parameter.
Keep in mind that many graphical libraries use this style of coordinates, typically because it is much easier to do buffer addressing with that kind of coordinate system. If you plan on doing a lot more work with computer graphics in the future, I would recommend learning to use this coordinate system directly instead of trying to force it to a more mathematical one.