0

For a fullfledge GUI I can use Qt or GTK. If I want OpenGL or Vulkan, GLFW will do. What is the most appropriate choice if all I want to do is

  1. Open a window
  2. Read image dimensions from stdin
  3. Read pixel data from stdin (until EOF), and put to the window.

A reasonable way of doing it would be to use GLFW + Cairo, but then I will have a hard dependency towards the display server anyways.

2
  • Which OS? Portable? Which price? Which image format (PNG, JPG, ...)? Why would you read the dimensions from stdin? All image formats I know contain the size in the file already. Aug 29, 2022 at 20:17
  • Also: Which C++ Standard? Aug 29, 2022 at 20:27

2 Answers 2

1

I suggest looking into CImg. It is

  • open source, CeCILL-C license (like GNU GPL)
  • easy to use, because you just need to include a single header. No complex setup.

Bad news:

  • AFAIK, you need to publish the source code of your software if someone asks you for it. Make sure you understand the impact of the license.

Here's code that creates an image of specific size in memory and draws some pixels:


#include "CImg.h"
using namespace cimg_library;

int main()
{
    CImg<unsigned char> imgDrawPixel(100,200,1,3, false);
    const unsigned char color[] = { 255,0,255 };
    for (int i = 0; i < 50; i++)
    {
        imgDrawPixel.draw_point(i + 20, i + 20, color);
    }

    CImgDisplay main_disp(imgDrawPixel, "This is an image");
    while (!main_disp.is_closed()) {
        main_disp.wait();
    }
    return 0;
}

Result:

Resulting image

(The grey area is not part of the image. It's there because I can't make the window smaller.)

1
  • Though currently only for X11 (not Wayland)
    – user877329
    Aug 30, 2022 at 20:01
0

I will suggest SDL https://www.libsdl.org/ because it is cross platform and it can easily display pixels on the screen.

Here is how you may draw pixels on the screen: https://stackoverflow.com/questions/20579658/how-to-draw-pixels-in-sdl-2-0 .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.