Add `delta_time_seconds` to the SDL OpenGL renderers (#671)

RE: #627
This commit is contained in:
PROP 65 2024-08-28 15:18:48 +00:00 committed by GitHub
parent b1c2227fa9
commit b3b400895d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 8 deletions

View File

@ -51,6 +51,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
float time_of_last_frame;
} sdl;
NK_INTERN void
@ -74,6 +75,10 @@ nk_sdl_render(enum nk_anti_aliasing AA)
int display_width, display_height;
struct nk_vec2 scale;
float now = ((float)SDL_GetTicks64()) / 1000;
sdl.ctx.delta_time_seconds = now - sdl.time_of_last_frame;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
scale.x = (float)display_width/(float)width;

View File

@ -67,6 +67,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
float time_of_last_frame;
} sdl;
#ifdef __APPLE__
@ -192,11 +193,16 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
int display_width, display_height;
struct nk_vec2 scale;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
{ 2.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, -2.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
float now = ((float)SDL_GetTicks64()) / 1000;
sdl.ctx.delta_time_seconds = now - sdl.time_of_last_frame;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
ortho[0][0] /= (GLfloat)width;

View File

@ -71,6 +71,7 @@ static struct nk_sdl {
struct nk_sdl_device ogl;
struct nk_context ctx;
struct nk_font_atlas atlas;
float time_of_last_frame;
} sdl;
@ -180,11 +181,16 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
int display_width, display_height;
struct nk_vec2 scale;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
{ 2.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, -2.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f, 1.0f },
};
float now = ((float)SDL_GetTicks64()) / 1000;
sdl.ctx.delta_time_seconds = now - sdl.time_of_last_frame;
sdl.time_of_last_frame = now;
SDL_GetWindowSize(sdl.win, &width, &height);
SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height);
ortho[0][0] /= (GLfloat)width;