7#include "Loader/STB/stb_image_write.h"
12 static int saveScreenshot(
const char* filename) {
14 glGetIntegerv(GL_VIEWPORT, viewport);
18 int width = viewport[2];
19 int height = viewport[3];
21 char* data =
new char[width * height * 4];
25 glReadBuffer(GL_COLOR_ATTACHMENT0);
26 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
28 int saved = stbi_write_bmp(filename, width, height, 4, data);
35 static int saveTexture(
const char* filename) {
37 glGetIntegerv(GL_VIEWPORT, viewport);
39 int* x = &viewport[0];
40 int* y = &viewport[1];
41 int* width = &viewport[2];
42 int* height = &viewport[3];
44 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, viewport[0], viewport[1], viewport[2], viewport[3], 0);
46 char* data =
new char[(*width) * (*height) * 4];
49 glPixelStorei(GL_PACK_ALIGNMENT, 1);
50 glReadPixels(*x, *y, *width, *height, GL_RGBA, GL_UNSIGNED_BYTE, data);
52 int saved = stbi_write_bmp(filename, *width, *height, 4, data);
59 static int savePng(
const char* filename,
int width,
int height,
int chennel,
void* data) {
60 int saved = stbi_write_png(filename, width, height, chennel, data, 0);