-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (68 loc) · 2.08 KB
/
main.cpp
File metadata and controls
86 lines (68 loc) · 2.08 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
#include <iostream>
#include <cmath>
#if defined(WIN32)
#define NOMINMAX
#include <windows.h>
#include <GL/gl.h>
#include <gl/GLU.h>
#elif defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#include <OpenGL/glu.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
#endif
// MinVR header
#include <api/MinVR.h>
using namespace MinVR;
/** MyVRApp changes the clear color as frames progress. */
class MyVRApp : public VRApp {
public:
MyVRApp(int argc, char** argv, const std::string& configFile) : VRApp(argc, argv, configFile) {}
void onVREvent(const VREvent &event) {
event.print();
// Get the time since application began
if (event.getName() == "FrameStart") {
time = event.getDataAsDouble("ElapsedSeconds");
return;
}
// Quit if the escape button is pressed
if (event.getName() == "KbdEsc_Down") {
shutdown();
}
}
void onVRRenderGraphicsContext(const VRGraphicsState &renderState) {
// Print out when the window was opened and closed
if (renderState.isInitialRenderCall()) {
std::cout << "Window opened." << std::endl;
// Create VBOs, VAOs, Textures, Shaders, and FrameBuffers
}
if (!isRunning()) {
std::cout << "Window closed." << std::endl;
}
}
void onVRRenderGraphics(const VRGraphicsState &renderState) {
// Get projection an view matrices
const float* projectionMatrix = renderState.getProjectionMatrix();
const float* viewMatrix = renderState.getViewMatrix();
// Show gradient of red color over four seconds then restart
float red = std::fmod(time/4.0,1.0);
glClearColor(red, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Draw calls here
}
private:
double time;
};
int main(int argc, char **argv) {
if (argc < 2) {
std::cout << "Please enter a MinVR config file..." << std::endl;
std::cout << "Example Usage: \n\tbuild/bin/MinGraphicsExample examples/MinGraphicsExample/desktop.xml" << std::endl;
return 1;
}
// The second argument is the config file path for this example
MyVRApp app(argc, argv, argv[1]);
app.run();
return 0;
}