-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathds_sdl.cpp
More file actions
101 lines (67 loc) · 2.18 KB
/
Copy pathds_sdl.cpp
File metadata and controls
101 lines (67 loc) · 2.18 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
// Copyright 2019 David Butler <croepha@gmail.com>
#include <easy/profiler.h>
#define EGL_EGLEXT_PROTOTYPES
#include <EGL/egl.h>
#include <EGL/eglext.h>
#define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include "common.hpp"
extern EGLDisplay egl_display;
extern EGLSurface egl_surface;
void egl_init1();
void egl_init2();
void egl_init3(void* native_window);
void egl_frame();
extern bool _debug_should_quit;
extern bool _debug_ignoring_events;
SDL_Window* sdl_window;
void ds_platform_init() {
egl_init1();
egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
egl_init2();
SDL_Init(SDL_INIT_VIDEO);
char* window_title = "ASDFASDF";
sdl_window = SDL_CreateWindow(
window_title,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
SDL_SysWMinfo window_info;
SDL_VERSION(&window_info.version);
SDL_GetWindowWMInfo(sdl_window,&window_info);
assert(window_info.subsystem == SDL_SYSWM_X11);
egl_init3((void*)window_info.info.x11.window);
SDL_EnableScreenSaver();
assert(!*SDL_GetError());
}
void ds_platform_frame() {
EASY_FUNCTION();
egl_frame();
SDL_Event _sde;
while (SDL_PollEvent(&_sde)) {
switch (_sde.type) {
case SDL_QUIT: {
_debug_should_quit = 1;
} break;
case SDL_KEYDOWN: {
if (_sde.key.keysym.sym == SDLK_ESCAPE) {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
} break;
case SDL_WINDOWEVENT: {
switch(_sde.window.event) {
case SDL_WINDOWEVENT_FOCUS_GAINED: {
_debug_ignoring_events = 0;
SDL_SetRelativeMouseMode(SDL_TRUE);
} break;
case SDL_WINDOWEVENT_FOCUS_LOST: {
_debug_ignoring_events = 1;
} break;
}
} break;
};
}
}