@ -18,7 +18,6 @@
// Emscripten requires to have full control over the main loop. We're going to store our SDL book-keeping variables globally.
// Emscripten requires to have full control over the main loop. We're going to store our SDL book-keeping variables globally.
// Having a single function that acts as a loop prevents us to store state in the stack of said function. So we need some location for this.
// Having a single function that acts as a loop prevents us to store state in the stack of said function. So we need some location for this.
SDL_Window * g_Window = NULL ;
SDL_Window * g_Window = NULL ;
SDL_GLContext g_GLContext = NULL ;
// For clarity, our main loop code is declared at the end.
// For clarity, our main loop code is declared at the end.
static void main_loop ( void * ) ;
static void main_loop ( void * ) ;
@ -49,13 +48,14 @@ int main(int, char**)
SDL_DisplayMode current ;
SDL_DisplayMode current ;
SDL_GetCurrentDisplayMode ( 0 , & current ) ;
SDL_GetCurrentDisplayMode ( 0 , & current ) ;
SDL_WindowFlags window_flags = ( SDL_WindowFlags ) ( SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI ) ;
SDL_WindowFlags window_flags = ( SDL_WindowFlags ) ( SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI ) ;
g_W indow = SDL_CreateWindow ( " Dear ImGui SDL+Emscripten example " , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , 1280 , 720 , window_flags ) ;
SDL_Window * w indow = SDL_CreateWindow ( " Dear ImGui SDL+Emscripten example " , SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED , 1280 , 720 , window_flags ) ;
g_GLC ontext = SDL_GL_CreateContext ( g_W indow) ;
SDL_GLContext gl_c ontext = SDL_GL_CreateContext ( w indow) ;
if ( ! g_GLC ontext )
if ( ! gl_c ontext )
{
{
fprintf ( stderr , " Failed to initialize Web GL context! \n " ) ;
fprintf ( stderr , " Failed to initialize GL context! \n " ) ;
return 1 ;
return 1 ;
}
}
SDL_GL_MakeCurrent ( window , gl_context ) ;
SDL_GL_SetSwapInterval ( 1 ) ; // Enable vsync
SDL_GL_SetSwapInterval ( 1 ) ; // Enable vsync
// Setup Dear ImGui context
// Setup Dear ImGui context
@ -74,7 +74,7 @@ int main(int, char**)
//ImGui::StyleColorsLight();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
// Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForOpenGL ( g_Window , g_GLC ontext) ;
ImGui_ImplSDL2_InitForOpenGL ( window , gl_c ontext) ;
ImGui_ImplOpenGL3_Init ( glsl_version ) ;
ImGui_ImplOpenGL3_Init ( glsl_version ) ;
// Load Fonts
// Load Fonts
@ -98,6 +98,7 @@ int main(int, char**)
# endif
# endif
// This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
// This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
g_Window = window ;
emscripten_set_main_loop_arg ( main_loop , NULL , 0 , true ) ;
emscripten_set_main_loop_arg ( main_loop , NULL , 0 , true ) ;
}
}
@ -167,7 +168,6 @@ static void main_loop(void* arg)
// Rendering
// Rendering
ImGui : : Render ( ) ;
ImGui : : Render ( ) ;
SDL_GL_MakeCurrent ( g_Window , g_GLContext ) ;
glViewport ( 0 , 0 , ( int ) io . DisplaySize . x , ( int ) io . DisplaySize . y ) ;
glViewport ( 0 , 0 , ( int ) io . DisplaySize . x , ( int ) io . DisplaySize . y ) ;
glClearColor ( clear_color . x * clear_color . w , clear_color . y * clear_color . w , clear_color . z * clear_color . w , clear_color . w ) ;
glClearColor ( clear_color . x * clear_color . w , clear_color . y * clear_color . w , clear_color . z * clear_color . w , clear_color . w ) ;
glClear ( GL_COLOR_BUFFER_BIT ) ;
glClear ( GL_COLOR_BUFFER_BIT ) ;