CSEngine
Loading...
Searching...
No Matches
CaptureDef.h
1//
2// Created by ounols on 19. 5. 5.
3//
4
5#pragma once
6
7#include "Loader/STB/stb_image_write.h"
8#include "../OGLDef.h"
9
10namespace CSE {
11
12 static int saveScreenshot(const char* filename) {
13 GLint viewport[4];
14 glGetIntegerv(GL_VIEWPORT, viewport);
15
16 int x = viewport[0];
17 int y = viewport[1];
18 int width = viewport[2];
19 int height = viewport[3];
20
21 char* data = new char[width * height * 4];
22
23
24// glPixelStorei(GL_PACK_ALIGNMENT, 1);
25 glReadBuffer(GL_COLOR_ATTACHMENT0);
26 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
27
28 int saved = stbi_write_bmp(filename, width, height, 4, data);
29
30 delete[] data;
31
32 return saved;
33 }
34
35 static int saveTexture(const char* filename) {
36 GLint viewport[4];
37 glGetIntegerv(GL_VIEWPORT, viewport);
38
39 int* x = &viewport[0];
40 int* y = &viewport[1];
41 int* width = &viewport[2];
42 int* height = &viewport[3];
43
44 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, viewport[0], viewport[1], viewport[2], viewport[3], 0);
45
46 char* data = new char[(*width) * (*height) * 4];
47
48
49 glPixelStorei(GL_PACK_ALIGNMENT, 1);
50 glReadPixels(*x, *y, *width, *height, GL_RGBA, GL_UNSIGNED_BYTE, data);
51
52 int saved = stbi_write_bmp(filename, *width, *height, 4, data);
53
54 delete[] data;
55
56 return saved;
57 }
58
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);
61 return saved;
62 }
63}