1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-20 15:40:26 +00:00

fixed SDL2 (with GLEW) on Windows

This commit is contained in:
Zeno Rogue 2022-06-10 18:45:15 +02:00
parent 3fa23afdce
commit 91b6628922
2 changed files with 20 additions and 2 deletions

View File

@ -172,6 +172,8 @@ EX SDL_Renderer *s_renderer, *s_software_renderer;
#endif #endif
EX SDL_Texture *s_texture; EX SDL_Texture *s_texture;
EX SDL_Window *s_window; EX SDL_Window *s_window;
EX SDL_GLContext s_context;
EX bool s_have_context;
#endif #endif
EX color_t qpixel_pixel_outside; EX color_t qpixel_pixel_outside;
@ -1148,6 +1150,9 @@ EX void close_renderer() {
EX void close_window() { EX void close_window() {
#if CAP_SDL2 #if CAP_SDL2
close_renderer(); close_renderer();
if(s_have_context) {
SDL_GL_DeleteContext(s_context), s_have_context = false;
}
if(s_window) SDL_DestroyWindow(s_window), s_window = nullptr; if(s_window) SDL_DestroyWindow(s_window), s_window = nullptr;
#endif #endif
} }
@ -1277,8 +1282,13 @@ EX void setvideomode() {
auto create_win = [&] { auto create_win = [&] {
#if CAP_SDL2 #if CAP_SDL2
if(s_window && current_window_flags != (flags | sizeflag)) if(s_window && current_window_flags != (flags | sizeflag)) {
if(s_have_context) {
SDL_GL_DeleteContext(s_context), s_have_context = false;
glhr::glew = false;
}
SDL_DestroyWindow(s_window), s_window = nullptr; SDL_DestroyWindow(s_window), s_window = nullptr;
}
if(s_window) if(s_window)
SDL_SetWindowSize(s_window, vid.xres, vid.yres); SDL_SetWindowSize(s_window, vid.xres, vid.yres);
else else
@ -1315,6 +1325,7 @@ EX void setvideomode() {
} }
#if CAP_SDL2 #if CAP_SDL2
if(s_renderer) SDL_DestroyRenderer(s_renderer), s_renderer = nullptr;
s_renderer = SDL_CreateRenderer(s_window, -1, vid.current_vsync ? SDL_RENDERER_PRESENTVSYNC : 0); s_renderer = SDL_CreateRenderer(s_window, -1, vid.current_vsync ? SDL_RENDERER_PRESENTVSYNC : 0);
SDL_GetRendererOutputSize(s_renderer, &vid.xres, &vid.yres); SDL_GetRendererOutputSize(s_renderer, &vid.xres, &vid.yres);
@ -1341,6 +1352,12 @@ EX void setvideomode() {
glDisable(GL_MULTISAMPLE_ARB); glDisable(GL_MULTISAMPLE_ARB);
} }
#if CAP_SDL2
if(s_have_context) SDL_GL_DeleteContext(s_context), s_have_context = false;
if(!s_have_context) s_context = SDL_GL_CreateContext(s_window);
s_have_context = true; glhr::glew = false;
#endif
glViewport(0, 0, vid.xres, vid.yres); glViewport(0, 0, vid.xres, vid.yres);
glhr::init(); glhr::init();
resetGL(); resetGL();

View File

@ -153,7 +153,7 @@ struct glmatrix {
#endif #endif
bool glew = false; EX bool glew = false;
bool current_depthtest, current_depthwrite; bool current_depthtest, current_depthwrite;
ld fogbase; ld fogbase;
@ -697,6 +697,7 @@ void init() {
#if CAP_GLEW #if CAP_GLEW
if(!glew) { if(!glew) {
glew = true; glew = true;
glewExperimental = GL_TRUE;
printf("Initializing GLEW\n"); printf("Initializing GLEW\n");
GLenum err = glewInit(); GLenum err = glewInit();
if (GLEW_OK != err) { if (GLEW_OK != err) {