Skip to content

Commit

Permalink
Add delta_time_seconds to the SDL OpenGL renderers (#671)
Browse files Browse the repository at this point in the history
RE: #627
  • Loading branch information
PROP65 authored Aug 28, 2024
1 parent b1c2227 commit b3b4008
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions demo/sdl_opengl2/nuklear_sdl_gl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions demo/sdl_opengl3/nuklear_sdl_gl3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions demo/sdl_opengles2/nuklear_sdl_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b3b4008

Please sign in to comment.