-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
131 lines (107 loc) · 4.1 KB
/
main.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
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
131
#include "main.h"
#include "effects.h"
#include "text2d.hpp"
// Global state
static GLFWwindow* window = NULL;
sync_device* rocket;
HSTREAM stream;
// Basic error handler
static void glfwErrorHandler(int error, const char* description) {
std::cerr << "Error " << error << ": " << description << std::endl;
exit(-1);
}
// Basic input handler ("escape closes window")
static void glfwInputHandler(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
}
// Startup
static void initializeApplication() {
// Start up GLFW and set up error handling
if (!glfwInit()) {
printf("Error in init\n");
exit(-1);
}
glfwSetErrorCallback(glfwErrorHandler);
// Open a window and set up OpenGL
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
window = glfwCreateWindow(screenWidth, screenHeight, "extremely basic window", glfwGetPrimaryMonitor(), NULL);
// Set up input handling
glfwSetKeyCallback(window, glfwInputHandler);
// Set up OpenGL
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwGetFramebufferSize(window, &screenWidth, &screenHeight);
glViewport(0, 0, screenWidth, screenHeight);
// Set up BASS
BASS_Init(-1, 44100, 0, 0, 0);
// Set up rocket
rocket = syncStartup();
}
// Teardown
static void terminateApplication() {
sync_destroy_device(rocket);
BASS_StreamFree(stream);
BASS_Free();
glfwDestroyWindow(window);
glfwTerminate();
}
// Main
int main(int argc, char** argv) {
initializeApplication();
// Music!
//stream = BASS_StreamCreateFile(false, "grey_matter.it", 0, 0, BASS_STREAM_PRESCAN);
//stream = BASS_StreamCreateFile(false, "sbit5.ogg", 0, 0, BASS_STREAM_PRESCAN);
stream = BASS_MusicLoad(false, "grey_matter.it", 0, 0, BASS_MUSIC_PRESCAN | BASS_SAMPLE_LOOP, 0);
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_MUSIC_PSCALER, 256);
BASS_Start();
BASS_ChannelPlay(stream, false);
int curEffect = 0;
effectBlobsInitialize();
const sync_track* switch_track = sync_get_track(rocket, "global:switch");
initText2D("texture/font.tga");
// Demo main loop
while (!glfwWindowShouldClose(window)) {
// TODO: postprod / fbos
syncUpdate(rocket, stream);
float bassRow = (float)bassGetRow(stream);
// Switch
int nextEffect = sync_get_val(switch_track, bassRow);
if (nextEffect != curEffect) {
if (curEffect == 1) {
curEffect = 0;
effectTrithingTerminate();
effectBlobsInitialize();
}
else {
curEffect = 1;
effectBlobsTerminate();
effectTrithingInitialize();
}
}
// Test effect
if (curEffect == 0) {
effectBlobsRender();
}
else {
effectTrithingRender();
}
// Text!
glClear(GL_DEPTH_BUFFER_BIT);
printText2D("this excellent SVatG party production has been brought to you by halcy and Saga Musix. How many SVatG engineers does it take to create a bitmap font? Two. Greetings to: k2 ~ TiTAN ~ SunSpire ~ cncd ~ Nuance ~ logicoma ~ mercury ~ spacepigs ~ jvb ~ Poo-Brain ~ RNO ~ dotUser ~ Suricrasia Online ~ Alcatraz ~ Wursthupe ~ Kaltgetraenkekabel We hope you have a great party here at Nordlicht 2019 in sunny Bremen (ha ha) this scroller will now repeat...", -bassRow * 35.0 + 3000, sin(bassRow) * 60 + 120, 30);
// Draw to screen
glfwSwapBuffers(window);
// Allow GLFW to do event handling
glfwPollEvents();
}
// Test effect
if (curEffect == 0) {
effectBlobsTerminate();
}
else {
effectTrithingTerminate();
}
terminateApplication();
}