forked from amundhov/legendary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux.cpp
137 lines (114 loc) · 3.53 KB
/
linux.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
132
133
134
135
136
#include <X11/keysymdef.h>
#include "linux.h"
#include "sound.h"
#include "msg.h"
Display *display;
Window root;
GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
Colormap cmap;
XSetWindowAttributes swa;
XWindowAttributes gwa;
LinuxEngine *Engine;
LinuxEngine::LinuxEngine() :
m_elapsed(0),
m_sound(new Sound("default", ""))
{
init();
LOG("LINUX ENGINE LOADED");
m_sound->play();
}
LinuxEngine::~LinuxEngine() {
delete m_sound;
}
int LinuxEngine::msgBox(std::string msg) {
//printf("ATTENTION: %s\n", msg);
system(std::string("zenity --info --text='" + msg + "'").c_str());
//Forward to Log
LOG(msg.c_str());
return 0;
}
void LinuxEngine::updateTimer() {
struct timeval now;
gettimeofday(&now, NULL);
suseconds_t cur = (now.tv_sec * 1000000) + now.tv_usec;
m_elapsed = cur - m_lastTick;
//Log("FPS: %i\n", int(1000000.0/ m_elapsed));
m_lastTick = cur;
//m_sound->getBass();
}
int main() {
Engine = new LinuxEngine;
display = XOpenDisplay(NULL);
if (!display) {
LOG("Couldn't open display, terminating.");
delete Engine;
return 1;
}
root = DefaultRootWindow(display);
XVisualInfo *visualInfo = glXChooseVisual(display, 0, att);
if (!visualInfo) {
LOG("FATAL: Unable to acquire visual!");
delete Engine;
return 1;
}
cmap = XCreateColormap(display, root, visualInfo->visual, AllocNone);
swa.colormap = cmap;
swa.event_mask = ExposureMask | KeyPressMask;// | ResizeRedirectMask;
Window win = XCreateWindow(display, root, 0, 0, 1024, 600, 0, visualInfo->depth, InputOutput, visualInfo->visual, CWColormap | CWEventMask, &swa);
XMapWindow(display, win);
XStoreName(display, win, "tenn0");
GLXContext context = glXCreateContext(display, visualInfo, NULL, GL_TRUE);
glXMakeCurrent(display, win, context);
if (glewInit()) {
LOG("FATAL! glewInit failed!\n");
return 0;
}
if (!glewIsSupported("GL_VERSION_2_0")) {
LOG("FATAL! Needs OpenGL 2.0 or later!");
return 255;
}
//if (!glewIsSupported("GL_EXT_geometry_shader4")) {
// LOG("FATAL! Needs geometry shader support!");
// return 255;
//}
Engine->initRender();
Engine->setViewport(1024,768);
XEvent xev;
while (1) {
Engine->drawFrame();
glXSwapBuffers(display, win);
if (!XPending(display))
continue;
XNextEvent(display, &xev);
//XResizeRequestEvent *rev = reinterpret_cast<XResizeRequestEvent*>(&xev);
switch (xev.type) {
case Expose:
XGetWindowAttributes(display, win, &gwa);
Engine->setViewport(gwa.width, gwa.height);
Engine->drawFrame();
glXSwapBuffers(display, win);
break;
case KeyPress:
switch (XLookupKeysym(&xev.xkey, 0)) {
case XK_Escape:
case XK_space:
glXMakeCurrent(display, None, NULL);
glXDestroyContext(display, context);
XDestroyWindow(display, win);
XCloseDisplay(display);
delete Engine;
return(1);
case XK_F2:
Engine->toggleFrame();
break;
case XK_F3:
Engine->reloadShaders();
break;
default:
continue;
}
default:
break;
}
}
}