Skip to content

Commit

Permalink
fix gles render in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizuku committed Feb 14, 2023
1 parent 84ae516 commit b9b099f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"name": "Mingw32",
"includePath": [
"${workspaceFolder}/src/onsjh/**",
"${workspaceFolder}/src/onsyuri/**",
"${msys2sdk}/mingw32/include"
],
"defines": [
Expand Down
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/onsyuri/ONScripter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/onsyuri/renderer/gles_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 12 additions & 7 deletions src/onsyuri/renderer/gles_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@
#include <SDL2/SDL.h>

#if defined(_WIN32) && !defined(_MSC_VER)
#define _MSC_VER 1200
#define SDL_USE_BUILTIN_OPENGL_DEFINITIONS
#include <SDL2/SDL_opengles2.h>
#undef _MSC_VER
#else
#include <SDL2/SDL_opengles2.h>
#endif



class GlesRenderer {
SDL_Window *window;
SDL_Texture *texture;
Expand All @@ -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:
Expand Down

0 comments on commit b9b099f

Please sign in to comment.