From b9b099f440ee04de3fb9abefe4f5e06cc4d2a9b3 Mon Sep 17 00:00:00 2001 From: devseed Date: Tue, 14 Feb 2023 22:25:15 +0900 Subject: [PATCH] fix gles render in windows --- .vscode/c_cpp_properties.json | 2 +- .vscode/launch.json | 1 + README.md | 1 + src/onsyuri/ONScripter.cpp | 11 ++++++++++- src/onsyuri/renderer/gles_renderer.cpp | 4 ---- src/onsyuri/renderer/gles_renderer.h | 19 ++++++++++++------- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 014603d..e4ebc93 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -8,7 +8,7 @@ { "name": "Mingw32", "includePath": [ - "${workspaceFolder}/src/onsjh/**", + "${workspaceFolder}/src/onsyuri/**", "${msys2sdk}/mingw32/include" ], "defines": [ diff --git a/.vscode/launch.json b/.vscode/launch.json index 84ce788..e427cc7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,7 @@ "program": "${workspaceRoot}/build_mingw32/onsyuri.exe", "args": ["--debug:0", // "--fullscreen2", // "--width", "960", "--height", "544", + "--sharpness", "1.1", "--root", "test", "--font", "test/default.ttf", "--save-dir", "${workspaceFolder}/save"], "stopAtEntry": false, "cwd": "${workspaceRoot}/asset", diff --git a/README.md b/README.md index b4bffd1..7647f70 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ New features or plans: - render - [x] support fullscreen by `--fullscreen` or `alt+enter`, scretch to fullscreen by `--fullscreen2` or `f11` - [x] support arbitary resolution `--width`, `--height` + - [x] gles2 sharpness rendering by `--sharpness 1.0` parameter, fix bug on windows - [ ] video support (future plan) - other - [x] support `nt2`, `nt3` encryption format by Mine diff --git a/src/onsyuri/ONScripter.cpp b/src/onsyuri/ONScripter.cpp index 210feba..00a8f75 100644 --- a/src/onsyuri/ONScripter.cpp +++ b/src/onsyuri/ONScripter.cpp @@ -201,8 +201,11 @@ void ONScripter::initSDL() SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); -#if defined(USE_GLES2) +#if defined(USE_GLES) if (!isnan(sharpness)) { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); } #endif @@ -214,6 +217,12 @@ void ONScripter::initSDL() window_flag |= SDL_WINDOW_ALLOW_HIGHDPI; #endif +#if defined(USE_GLES) + if (!isnan(sharpness)) { + window_flag |= SDL_WINDOW_OPENGL; + } +#endif + int window_x = SDL_WINDOWPOS_CENTERED, window_y = SDL_WINDOWPOS_CENTERED; window = SDL_CreateWindow(NULL, window_x, window_y, screen_device_width, screen_device_height, window_flag); diff --git a/src/onsyuri/renderer/gles_renderer.cpp b/src/onsyuri/renderer/gles_renderer.cpp index b0b9e87..b095f27 100644 --- a/src/onsyuri/renderer/gles_renderer.cpp +++ b/src/onsyuri/renderer/gles_renderer.cpp @@ -88,10 +88,6 @@ void GlesRenderer::initVertexData() { GlesRenderer::GlesRenderer(SDL_Window *window, SDL_Texture *texture, const float input_size[2], const float output_size[2], const float sharpness) { #if defined(IOS) || defined(ANDROID) //#define SDL_PROC(ret,func,params) func=func; -#else -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "gles2funcs.h" -#undef SDL_PROC #endif this->window = window; this->texture = texture; diff --git a/src/onsyuri/renderer/gles_renderer.h b/src/onsyuri/renderer/gles_renderer.h index 22e967b..8dc9dbc 100644 --- a/src/onsyuri/renderer/gles_renderer.h +++ b/src/onsyuri/renderer/gles_renderer.h @@ -23,15 +23,12 @@ #include #if defined(_WIN32) && !defined(_MSC_VER) -#define _MSC_VER 1200 +#define SDL_USE_BUILTIN_OPENGL_DEFINITIONS #include -#undef _MSC_VER #else #include #endif - - class GlesRenderer { SDL_Window *window; SDL_Texture *texture; @@ -46,10 +43,18 @@ class GlesRenderer { int output_size[2]; bool _pause = false; #if !(defined(IOS) || defined(ANDROID)) -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; -#include "gles2funcs.h" -#undef SDL_PROC + + #if defined(WIN32) || defined(_WIN32) + #define SDL_PROC(ret,func,params) \ + ret (APIENTRY *func) params = (ret (APIENTRY *) params) SDL_GL_GetProcAddress(#func); + #else + #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; + #endif + + #include "gles2funcs.h" + #undef SDL_PROC #endif + GLuint createShader(GLenum shader_type, const GLchar* shader_src); void initVertexData(); public: