support emscripten window resizing, F1 is now used over escape on web
parent
d18b48c9dd
commit
d2ba28fa1a
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
|
|
||||||
set(BLT_GRAPHICS_VERSION 0.11.1)
|
set(BLT_GRAPHICS_VERSION 0.11.2)
|
||||||
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
||||||
|
|
||||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||||
|
|
|
@ -118,6 +118,8 @@ namespace blt::gfx
|
||||||
std::int64_t getFrameDelta();
|
std::int64_t getFrameDelta();
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //BLT_WITH_GRAPHICS_TEMPLATE_WINDOW_H
|
#endif //BLT_WITH_GRAPHICS_TEMPLATE_WINDOW_H
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 231cbee0fc4f59dbe5b8b853a11b08dc84e57c65
|
Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5
|
|
@ -1 +1 @@
|
||||||
Subproject commit 111397c71a5f1c2c88e05da9c84edfdba2e472a4
|
Subproject commit 6675317107257c2cc16c947b359d557821d85bf2
|
|
@ -25,7 +25,13 @@ void blt::gfx::first_person_camera::update()
|
||||||
|
|
||||||
float speed_multi = 1;
|
float speed_multi = 1;
|
||||||
|
|
||||||
if (isKeyPressed(GLFW_KEY_ESCAPE) && keyPressedLastFrame())
|
int locking_key = GLFW_KEY_ESCAPE;
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
locking_key = GLFW_KEY_F1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (isKeyPressed(locking_key) && keyPressedLastFrame())
|
||||||
{
|
{
|
||||||
if (isCursorLocked())
|
if (isCursorLocked())
|
||||||
unlockCursor();
|
unlockCursor();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <blt/gfx/state.h>
|
#include <blt/gfx/state.h>
|
||||||
|
#include <blt/std/logging.h>
|
||||||
#include "blt/std/assert.h"
|
#include "blt/std/assert.h"
|
||||||
|
|
||||||
void blt::gfx::matrix_state_manager::update()
|
void blt::gfx::matrix_state_manager::update()
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
#include "backends/imgui_impl_glfw.h"
|
#include "backends/imgui_impl_glfw.h"
|
||||||
#include <blt/gfx/imgui/ImGuiUtils.h>
|
#include <blt/gfx/imgui/ImGuiUtils.h>
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
|
||||||
|
#include <emscripten/html5.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void error_callback(int error, const char* description)
|
void error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
BLT_ERROR("GLFW Error (%d): %s", error, description);
|
BLT_ERROR("GLFW Error (%d): %s", error, description);
|
||||||
|
@ -124,8 +130,9 @@ namespace blt::gfx
|
||||||
io.Fonts->AddFontFromMemoryCompressedBase85TTF(fontAwesomeRegular_compressed_data_base85, 13.0f, &config, icon_ranges);
|
io.Fonts->AddFontFromMemoryCompressedBase85TTF(fontAwesomeRegular_compressed_data_base85, 13.0f, &config, icon_ranges);
|
||||||
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeSolid_compressed_data, static_cast<int>(fontAwesomeSolid_compressed_size), 13.0, &config,
|
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeSolid_compressed_data, static_cast<int>(fontAwesomeSolid_compressed_size), 13.0, &config,
|
||||||
icon_ranges);
|
icon_ranges);
|
||||||
io.Fonts->AddFontFromMemoryCompressedTTF(fontAwesomeBrands_compressed_data, static_cast<int>(fontAwesomeBrands_compressed_size), 13.0, &config,
|
io.Fonts
|
||||||
icon_ranges);
|
->AddFontFromMemoryCompressedTTF(fontAwesomeBrands_compressed_data, static_cast<int>(fontAwesomeBrands_compressed_size), 13.0, &config,
|
||||||
|
icon_ranges);
|
||||||
|
|
||||||
//ImGui::StyleColorsLight();
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
|
@ -175,10 +182,26 @@ namespace blt::gfx
|
||||||
window_state.millisDelta = static_cast<double>(window_state.deltaTime) / 1e6f;
|
window_state.millisDelta = static_cast<double>(window_state.deltaTime) / 1e6f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
|
||||||
|
EM_BOOL emscripten_resize_callback(int, const EmscriptenUiEvent* event, void* data)
|
||||||
|
{
|
||||||
|
int width = event->windowInnerWidth;
|
||||||
|
int height = event->windowInnerHeight;
|
||||||
|
|
||||||
|
glfwSetWindowSize(window_state.window, width, height);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void init(const window_data& data)
|
void init(const window_data& data)
|
||||||
{
|
{
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n");
|
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n");
|
||||||
|
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false,
|
||||||
|
emscripten_resize_callback);
|
||||||
#endif
|
#endif
|
||||||
/* -- Set up Error Callback -- */
|
/* -- Set up Error Callback -- */
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
|
@ -223,7 +246,7 @@ namespace blt::gfx
|
||||||
* make sure you render at a proper smooth rate that lines up properly with the browser and monitor."
|
* make sure you render at a proper smooth rate that lines up properly with the browser and monitor."
|
||||||
* https://emscripten.org/docs/api_reference/emscripten.h.html
|
* https://emscripten.org/docs/api_reference/emscripten.h.html
|
||||||
*/
|
*/
|
||||||
emscripten_set_main_loop_arg(loop, (void*)&data, 0, true);
|
emscripten_set_main_loop_arg(loop, (void*) &data, 0, true);
|
||||||
#else
|
#else
|
||||||
/* -- General Loop -- */
|
/* -- General Loop -- */
|
||||||
while (!glfwWindowShouldClose(window_state.window))
|
while (!glfwWindowShouldClose(window_state.window))
|
||||||
|
|
Loading…
Reference in New Issue