-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreen.cpp
52 lines (44 loc) · 1.06 KB
/
Screen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Screen.cpp
*/
#include <iostream>
#include <FreeImage.h>
#include "Screen.h"
Screen::Screen()
{
}
Screen::~Screen()
{
delete[] pixelArray;
}
void Screen::init(const int width, const int height)
{
this->width = width;
this->height = height;
pixelArray = new Byte[width*height*3];
}
void Screen::writePixel(const glm::dvec3& color, const int x, const int y)
{
glm::dvec3 newColor = glm::clamp(color, 0.0, 1.0);
for (int i = 0; i < 3; i++) {
pixelArray[(width*y+x)*3 + 2 - i] = (Byte) (newColor[i]*255.0);
}
}
void Screen::saveScreenshot(const char* outputFilename)
{
FreeImage_Initialise();
FIBITMAP *img = FreeImage_ConvertFromRawBits(pixelArray, width, height, width * 3,
24, 0xFF0000, 0x00FF00, 0x0000FF, false);
std::cout << "Saving screenshot: " << outputFilename << "\n";
FreeImage_Save(FIF_PNG, img, outputFilename, 0);
delete img;
FreeImage_DeInitialise();
}
int Screen::getWidth()
{
return width;
}
int Screen::getHeight()
{
return height;
}