83 lines
2.1 KiB
C++
83 lines
2.1 KiB
C++
#include "pch.hpp"
|
|
|
|
#ifdef WINDOW_SDL3
|
|
#undef WINDOW_SDL3
|
|
|
|
#include "utils/Window/WindowEvents.h"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <SDL3/SDL_opengl.h>
|
|
|
|
namespace Archimedes {
|
|
|
|
class Window;
|
|
|
|
class WindowSDL3 {
|
|
|
|
public:
|
|
|
|
WindowSDL3(Window* p, const std::function<void(Event*)>& sendEvent) {
|
|
|
|
data.window = p;
|
|
data.sendEvent = sendEvent;
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
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)
|
|
{
|
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
|
std::abort();
|
|
}
|
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
|
|
|
gl_context = SDL_GL_CreateContext(window);
|
|
|
|
if (gl_context == nullptr)
|
|
{
|
|
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
|
std::abort();
|
|
}
|
|
|
|
SDL_GL_MakeCurrent(window, gl_context);
|
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
|
SDL_ShowWindow(window);
|
|
}
|
|
|
|
~WindowSDL3() {
|
|
}
|
|
|
|
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
|
|
|
|
void pollEvents() {
|
|
SDL_PollEvent(&e);
|
|
|
|
switch(e.type) {
|
|
|
|
}
|
|
}
|
|
|
|
void restoreContext() { SDL_GLMakeCurrent(window, gl_context); }
|
|
|
|
void getSize(int& w, int& h) {
|
|
}
|
|
|
|
SDL_Window* getWindow() { return w; }
|
|
|
|
WindowData data;
|
|
|
|
private:
|
|
SDL_Window* w;
|
|
SDL_GLContext gl_context;
|
|
SDL_Event e;
|
|
|
|
};
|
|
|
|
typedef WindowSDL3 WindowImpl;
|
|
}
|
|
|
|
#endif
|