7#define STB_IMAGE_WRITE_IMPLEMENTATION
9#include "Loader/STB/stb_image_write.h"
14 static int saveScreenshot(
const char* filename) {
16 glGetIntegerv(GL_VIEWPORT, viewport);
20 int width = viewport[2];
21 int height = viewport[3];
23 char* data =
new char[width * height * 4];
27 glReadBuffer(GL_COLOR_ATTACHMENT0);
28 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
30 int saved = stbi_write_bmp(filename, width, height, 4, data);
37 static int saveTexture(
const char* filename) {
39 glGetIntegerv(GL_VIEWPORT, viewport);
41 int* x = &viewport[0];
42 int* y = &viewport[1];
43 int* width = &viewport[2];
44 int* height = &viewport[3];
46 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, viewport[0], viewport[1], viewport[2], viewport[3], 0);
48 char* data =
new char[(*width) * (*height) * 4];
51 glPixelStorei(GL_PACK_ALIGNMENT, 1);
52 glReadPixels(*x, *y, *width, *height, GL_RGBA, GL_UNSIGNED_BYTE, data);
54 int saved = stbi_write_bmp(filename, *width, *height, 4, data);