This repository has been archived by the owner on Jan 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glxwindow.h
205 lines (200 loc) · 4.4 KB
/
glxwindow.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//you arrived here from glxwindow.c
Display *dsply;
int attrib[64] = {GLX_RGBA,GLX_DEPTH_SIZE,24,GLX_DOUBLEBUFFER,None};
Window desktop;
Window glxwin;
XSetWindowAttributes swa;
XWindowAttributes GotWinAtt;
GLXContext glxctx;
XVisualInfo *xvi;
Colormap cmap;
ushortvector2 MWSIZE = {505,303};
#define MWASPECT ((float)MWSIZE.x/MWSIZE.y)
static void
glx__resize()
{
printf("resizing to %i x %i\n",MWSIZE.x,MWSIZE.y);
glViewport(0,0,MWSIZE.x,MWSIZE.y);
}
static signed short
glx__keysymswitch(monitor,windw,event)
Display *monitor;
Window windw;
XEvent event;
{
if (event.type == KeyPress)
{
int sym_keypressd = XLookupKeysym(&(event.xkey), 0);
switch (sym_keypressd)
{
case XK_KP_Add : noop();
case XK_plus :
{
CAMBUFFER.w--;
puts("Zoom In");
return STR_INT(0,'+',0);
break;
}
case XK_KP_Subtract : noop();
case XK_minus :
{
CAMBUFFER.w++;
puts("Zoom Out");
return STR_INT(0,'-',0);
break;
}
case XK_KP_7 : noop();
case XK_KP_Home : noop();
case XK_Home :
{
PLAYER->Torq.z = fmod((PLAYER->Torq.z + (CAMERA->coord.az * 2)),360);
puts("Align");
return STR_INT(0,'\r',0);
break;
}
case XK_KP_4 : noop();
case XK_KP_Left : noop();
case XK_Left :
{
CAMBUFFER.x++;
puts("Orbit <-");
printf("%i\n",CAMERA->coord.az);
return STR_INT(0,0x9b,'D');
break;
}
case XK_KP_6 : noop();
case XK_KP_Right : noop();
case XK_Right :
{
CAMBUFFER.x--;
puts("Orbit ->");
printf("%i\n",CAMERA->coord.az);
return STR_INT(0,0x9b,'C');
break;
}
case XK_KP_8 : noop();
case XK_KP_Up : noop();
case XK_Up :
{
CAMBUFFER.y++;
puts("Orbit Up");
printf("%i\n",CAMERA->coord.alt);
return STR_INT(0,0x9b,'A');
break;
}
case XK_KP_2 : noop();
case XK_KP_Down : noop();
case XK_Down :
{
CAMBUFFER.y--;
puts("Orbit Down");
printf("%i\n",CAMERA->coord.alt);
return STR_INT(0,0x9b,'B');
break;
}
case XK_KP_9 : noop();
case XK_KP_Page_Up : noop();
case XK_Page_Up :
{
CAMBUFFER.z++;
puts("Closer");
return STR_INT(0,0x9b,'S');
break;
}
case XK_KP_3 : noop();
case XK_KP_Page_Down : noop();
case XK_Page_Down :
{
CAMBUFFER.z--;
puts("Farther");
return STR_INT(0,0x9b,'T');
break;
}
case XK_KP_1 : noop();
case XK_KP_End : noop();
case XK_End :
{
CAMERA->coord.az=0;
CAMERA->coord.alt=0;
CAMERA->coord.z=0;
CAMERA->coord.fov=50;
puts("Reset Cam");
return STR_INT(0,0x19,0);
break;
}
case XK_Escape :
{
RUN++;
return STR_INT(0,033,0);
puts("Escape!!!");
break;
}
case XK_Pause :
{
toggle(PAUSE);
puts("!Pause");
return STR_INT(0,0x15,0);
break;
}
default :
{
return -1;
break;
}
}
}
else if (event.type == ConfigureNotify) //tfw = instead of ==
{
MWSIZE.x = event.xconfigure.width;
MWSIZE.y = event.xconfigure.height;
glx__resize();
return STR_INT(0,1,0);
}
}
/* esc = 0 @33 0
* ctrl = 0 $9F 0
* alt = 0 $9D 0
* shift = 0 $F 0
* f# = # 0 0
* caps = never caught
*
* data format (signed short):
* special indicator (1 bit)
* ISO-8859 character or control code (8 bits)
* ASCII character modifier (7 bits, usually absent)
*/
static void
glx__eventswitch(monitor,windw)
Display *monitor;
Window windw;
{
if (XPending(monitor))
{
XEvent event;
XNextEvent(monitor,&event);
glx__keysymswitch(monitor,windw,event);
}
}
void
glx__startup()
{
dsply = XOpenDisplay(NULL);
if (dsply == NULL) {HARD_ERROR_MACRO}
desktop = DefaultRootWindow(dsply);
XVisualInfo *xvi = glXChooseVisual(dsply, 0, attrib);
if (xvi == NULL) {HARD_ERROR_MACRO}
cmap = XCreateColormap(dsply,desktop,xvi->visual,AllocNone);
swa.colormap = cmap;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; //start here and finnagle around with it if unexpected results
glxwin = XCreateWindow(dsply,desktop,0,0,MWSIZE.x,MWSIZE.y,0,xvi->depth,InputOutput,xvi->visual,CWColormap | CWEventMask,&swa);
XMapWindow(dsply,glxwin);
glxctx = glXCreateContext(dsply,xvi,NULL,TRUE);
glXMakeCurrent(dsply,glxwin,glxctx);
glViewport(0,0,505,303);
glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
//some_func_setwrap_x(-360*60,360*60);
//some_func_setwrap_y(-360*60,360*60);
XStoreName(dsply, glxwin, VITALSTAT(REV_MAIN));
}