-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
130 lines (105 loc) · 2.53 KB
/
main.cpp
File metadata and controls
130 lines (105 loc) · 2.53 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
DO NOT MODIFY THIS FILE.
Use test.cpp instead.
*/
#include <stdio.h>
#include <windows.h>
#include "GL/glut.h"
#include "nvToolsExt.h"
#include "test.h"
int originalWindow = 0, currentWindow;
void platform::drawPoint(float x, float y, float r, float g, float b, float a)
{
glColor4f(r, g, b, a);
glVertex2f(x, y);
}
void display(void)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
nvtxRangePush("test::render()");
glBegin(GL_POINTS);
test::render();
glEnd();
nvtxRangePop();
glutSwapBuffers();
};
void idle(void)
{
nvtxRangePush(__FUNCTION__);
int time = glutGet(GLUT_ELAPSED_TIME);
static int lastTime = 0;
int delta = time - lastTime;
lastTime = time;
// check memory
{
static int nextStats = -1;
if (nextStats < time)
{
MEMORYSTATUSEX memStatus;
ZeroMemory(&memStatus, sizeof(MEMORYSTATUSEX));
memStatus.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memStatus);
int totalVirtual = (memStatus.ullTotalVirtual / 1024) / 1024;
int availVirtual = (memStatus.ullAvailVirtual / 1024) / 1024;
int usedVirtual = totalVirtual - availVirtual;
printf("Virtual memory info. Total: %dMb, Free: %dMb, Used: %dMb\n", totalVirtual, availVirtual, usedVirtual);
nextStats = time + 3000;
}
}
{
static int nextAnim = -1;
static int animPos = 0;
const char *animation = "-\\|/-\\|/";
if (nextAnim < time)
{
printf("\b\b%c ", animation[animPos]);
animPos = (animPos+1) % (8);
nextAnim = time + 60;
}
}
nvtxRangePush("test::update()");
test::update(delta);
nvtxRangePop();
glutPostWindowRedisplay(currentWindow);
nvtxRangePop();
};
void visible(int vis)
{
glutIdleFunc((vis == GLUT_VISIBLE) ? idle : NULL);
};
void mouse(int button, int state, int x, int y)
{
if (state == GLUT_UP && button == 0)
{
nvtxRangePush("test::on_click()");
test::on_click(x, y);
nvtxRangePop();
}
};
void initWindow(void)
{
glutDisplayFunc(display);
glutVisibilityFunc(visible);
glutMouseFunc(mouse);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, test::SCREEN_WIDTH, 0, test::SCREEN_HEIGHT, 0, 40);
glMatrixMode(GL_MODELVIEW);
glPointSize(3.0);
currentWindow = glutGetWindow();
};
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize((int)test::SCREEN_WIDTH, (int)test::SCREEN_HEIGHT);
originalWindow = glutCreateWindow("asteroids");
initWindow();
test::init();
atexit(test::term);
glutMainLoop();
return 0;
}