Created
March 25, 2020 19:16
-
-
Save prideout/7b9697a984d676516d59c05ef42fbd0c to your computer and use it in GitHub Desktop.
GLFW+Filament
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void resizeCallback(GLFWwindow* win, int width, int height) { | |
void* nsview = platform_get_view(glfwGetCocoaWindow(win)); | |
app.engine->destroy(app.swap_chain); | |
app.swap_chain = app.engine->createSwapChain(nsview); | |
app.window_width = width; | |
app.window_height = height; | |
glfwGetWindowContentScale(win, &app.dpi_scale[0], &app.dpi_scale[1]); | |
app.gui->helper->setDisplaySize(width / app.dpi_scale[0], height / app.dpi_scale[1], | |
app.dpi_scale[0], app.dpi_scale[1]); | |
app.gui->camera->setProjection(filament::Camera::Projection::ORTHO, 0.0, | |
width / app.dpi_scale[0], height / app.dpi_scale[1], 0.0, 0.0, | |
1.0); | |
} | |
int main() { | |
glfwInit(); | |
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); | |
GLFWwindow* window = glfwCreateWindow(1280, 720, "Topoid Editor", 0, 0); | |
app.gui = new Gui({}); | |
app.gui->window = window; | |
app.tilesim = new TileSim({}); | |
app_init(&app); | |
int width, height; | |
glfwGetFramebufferSize(window, &width, &height); | |
resizeCallback(window, width, height); | |
glfwSetMouseButtonCallback(window, mouseButtonCallback); | |
glfwSetCursorPosCallback(window, cursorPosCallback); | |
glfwSetScrollCallback(window, scrollCallback); | |
glfwSetKeyCallback(window, keyCallback); | |
glfwSetCharCallback(window, charCallback); | |
glfwSetFramebufferSizeCallback(window, resizeCallback); | |
if (glfwJoystickPresent(GLFW_JOYSTICK_1)) { | |
printf("Joystick found: %s\n", glfwGetJoystickName(GLFW_JOYSTICK_1)); | |
} | |
double previous_time = glfwGetTime(); | |
while (!glfwWindowShouldClose(window)) { | |
const double current_time = glfwGetTime(); | |
const double seconds = current_time - previous_time; | |
previous_time = current_time; | |
app_update(&app, seconds); | |
// NOTE: Technically, resizeCallback might be triggered during beginFrame, but in practice | |
// this can be avoided by sleeping *before* polling for events. | |
std::this_thread::sleep_for(milliseconds(16)); | |
glfwPollEvents(); | |
pollJoystickArrowKeys(seconds); | |
} | |
app_destroy(&app); | |
delete app.gui; | |
glfwTerminate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment