GLFW SetWindowIcon

Viewed 10330

So, I am trying to set the window icon for my glfw window (obviously) but I am having trouble doing so because I don't know how to set an icon using GLFWimage. The code in the docs is as shown:

GLFWimage images[2];
images[0] = load_icon("my_icon.png");
images[1] = load_icon("my_icon_small.png");
glfwSetWindowIcon(window, 2, images);

But there, it doesn't show how to use or create a "load_icon" function. So, can anyone help cause I have been searching for months.

2 Answers

If you are using "stb_image.h", this is the code you should be using:

GLFWimage images[1]; 
images[0].pixels = stbi_load("PATH", &images[0].width, &images[0].height, 0, 4); //rgba channels 
glfwSetWindowIcon(window, 1, images); 
stbi_image_free(images[0].pixels);
Related