-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (54 loc) · 1.87 KB
/
main.cpp
File metadata and controls
68 lines (54 loc) · 1.87 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define _CRT_SECURE_NO_WARNINGS // for STB
#define THIRTEEN_IMPLEMENTATION
#include "../../thirteen.h"
#include <stdio.h>
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "../stb/stb_image_write.h"
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
static const unsigned int c_width = 1024;
static const unsigned int c_height = 768;
static const bool c_fullscreen = false;
int main(int argc, char** argv)
{
Thirteen::SetApplicationName("Thirteen Demo - Simple");
unsigned char* pixels = Thirteen::Init(c_width, c_height, c_fullscreen);
if (!pixels)
{
printf("Could not initialize Thirteen\n");
return 1;
}
unsigned int frameIndex = 0;
do
{
// V to toggle vsync
if (Thirteen::GetKey('V') && !Thirteen::GetKeyLastFrame('V'))
Thirteen::SetVSync(!Thirteen::GetVSync());
// F to toggle full screen
if (Thirteen::GetKey('F') && !Thirteen::GetKeyLastFrame('F'))
Thirteen::SetFullscreen(!Thirteen::GetFullscreen());
// S to save a screenshot
if (Thirteen::GetKey('S') && !Thirteen::GetKeyLastFrame('S'))
stbi_write_png("screenshot.png", c_width, c_height, 4, pixels, 0);
for (size_t iy = 0; iy < c_height; ++iy)
{
for (size_t ix = 0; ix < c_width; ++ix)
{
size_t i = (iy * c_width + ix) * 4;
pixels[i + 0] = static_cast<unsigned char>(frameIndex + ix);
pixels[i + 1] = static_cast<unsigned char>(frameIndex + iy);
pixels[i + 2] = static_cast<unsigned char>(frameIndex);
pixels[i + 3] = 255;
}
}
frameIndex++;
}
while (Thirteen::Render() && !Thirteen::GetKey(VK_ESCAPE));
Thirteen::Shutdown();
return 0;
}