-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.h
63 lines (46 loc) · 1.22 KB
/
Window.h
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
#pragma once
#include <Windows.h>
#include "Rendering.h"
#include "Aliasing.h"
#include "Inputs.h"
#include "GL/glut.h"
#include "GL/freeglut.h"
Color* rgbBuffers = static_cast<Color*>(malloc(2 * px * py * sizeof(Color)));
array_view<Color, 3> rgb(2, py, px, rgbBuffers);
bool LockedBuffer = false;
unsigned int framesInSec = 0;
time_t startTime = clock();
void drawFrame()
{
glDrawPixels(px, py, GL_RGBA, GL_UNSIGNED_BYTE, &rgbBuffers[px * py * !LockedBuffer]);
glutSwapBuffers();
}
completion_future pendingFrameCopy;
void triggerReDraw()
{
framesInSec++;
pendingFrameCopy = rgb[LockedBuffer].synchronize_async();
RenderScene(rgb[!LockedBuffer]);
FXAA(rgb[!LockedBuffer]);
if (clock() - startTime >= 1000)
{
printf_s("You averaged %d fps\n", framesInSec);
framesInSec = 0;
startTime = clock();
}
glutPostRedisplay();
LockedBuffer = !LockedBuffer;
pendingFrameCopy.wait();
}
void SetupFrame(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(px, py);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow("glDrawPixels example");
glutDisplayFunc(drawFrame);
glutIdleFunc(triggerReDraw);
glutPassiveMotionFunc(MouseMove);
glutKeyboardFunc(KeyboardDepressed);
glutMainLoop();
}