try WindowSDL3
This commit is contained in:
35
flake.nix
35
flake.nix
@@ -91,6 +91,41 @@
|
||||
|
||||
};
|
||||
|
||||
WindowModuleSDL = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "WindowModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
sdl3
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_SDL3 \
|
||||
-DWINDOWMODULE_DYNAMIC \
|
||||
-lGL -lsdl -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
WindowModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "WindowModule";
|
||||
|
||||
@@ -26,15 +26,15 @@ namespace Archimedes {
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
|
||||
SDL_Window* window = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
|
||||
if (window == nullptr)
|
||||
w = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
|
||||
if (w == nullptr)
|
||||
{
|
||||
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||
std::abort();
|
||||
}
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
SDL_SetWindowPosition(w, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
gl_context = SDL_GL_CreateContext(window);
|
||||
gl_context = SDL_GL_CreateContext(w);
|
||||
|
||||
if (gl_context == nullptr)
|
||||
{
|
||||
@@ -42,12 +42,27 @@ namespace Archimedes {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(window, gl_context);
|
||||
SDL_AddEventWatch([](void* ptr, SDL_Event* e) -> bool {
|
||||
|
||||
WindowData& d = (WindowData&) *ptr;
|
||||
|
||||
switch(e->type) {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}, &data);
|
||||
|
||||
|
||||
SDL_GL_MakeCurrent(w, gl_context);
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
SDL_ShowWindow(window);
|
||||
SDL_ShowWindow(w);
|
||||
}
|
||||
|
||||
~WindowSDL3() {
|
||||
SDL_GL_DestroyContext(gl_context);
|
||||
SDL_DestroyWindow(w);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
|
||||
@@ -56,21 +71,67 @@ namespace Archimedes {
|
||||
SDL_PollEvent(&e);
|
||||
|
||||
switch(e.type) {
|
||||
|
||||
|
||||
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
|
||||
case SDL_EVENT_QUIT:
|
||||
d.sendEvent(new CloseWindowEvent(d.window));
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
w = e.window.data1;
|
||||
h = e.window.data2;
|
||||
d.sendEvent(new ResizeWindowEvent(e.window.data1, e.window.data2));
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||
d.sendEvent(new FocusedWindowEvent(d.window));
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
|
||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||
d.sendEvent(new FocusLostWindowEvent(d.window));
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
d.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0));
|
||||
break;
|
||||
case SDL_EVENT_KEY_UP:
|
||||
d.sendEvent(new KeyReleasedWindowEvent(e.key.key));
|
||||
break;
|
||||
case SDL_EVENT_TEXT_EDITING:
|
||||
break;
|
||||
case SDL_EVENT_TEXT_INPUT:
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
d.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
d.sendEvent(new MouseButtonPressedWindowEvent(e.button.button));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||
d.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
d.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void restoreContext() { SDL_GLMakeCurrent(window, gl_context); }
|
||||
void restoreContext() { SDL_GLMakeCurrent(w, gl_context); }
|
||||
|
||||
void getSize(int& w, int& h) {
|
||||
w = this->w;
|
||||
h = this->h;
|
||||
}
|
||||
|
||||
SDL_Window* getWindow() { return w; }
|
||||
|
||||
SDL_GLContext getContext() { return gl_context; }
|
||||
|
||||
WindowData data;
|
||||
|
||||
private:
|
||||
SDL_Window* w;
|
||||
int w = 0, h = 0;
|
||||
SDL_GLContext gl_context;
|
||||
SDL_Event e;
|
||||
|
||||
|
||||
@@ -54,7 +54,9 @@ bool WindowModule::onEvent(const Archimedes::Event& e) {
|
||||
unsigned int type = app->getEventType(e);
|
||||
|
||||
if(type == app->getEventType(Archimedes::ResizeWindowEvent())) {
|
||||
window->getSize(renderer->w, renderer->h);
|
||||
Archimedes::ResizeWindowEvent& event = (Archimedes::ResizeWindowEvent&) e;
|
||||
renderer->w = event.width;
|
||||
renderer->h = event.height;
|
||||
return true;
|
||||
} else if(type == app->getEventType(Archimedes::CloseWindowEvent())) {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
|
||||
Reference in New Issue
Block a user