I baked a texture with code. I then baked the same texture in blender.
The problem is, the image is upside down when I baked with code. This is how I am saving the output after baking a texture with cycles. Any clue where I went wrong?
int w = buffer_params.width;
int h = buffer_params.height;
int channels = 4;
ImageSpec spec(w, h, channels, TypeDesc::FLOAT);
out->open(file_path, spec);
int scanlinesize = w * channels * sizeof(float);
out->write_image(TypeDesc::FLOAT,
(char *)pixels + ((h - 1) * scanlinesize), // offset to last
AutoStride, // default x stride
-scanlinesize, // special y stride
AutoStride); // default z stride
out->close();