int GlfwApplication::Run() { CHECK_STATE(glfwInit() != -1); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if (minimized) { window = glfwCreateWindow(kMinimizedWidth, kMinimizedHeight, title.c_str(), nullptr, nullptr); } else { window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); } CHECK_STATE(window != nullptr); glfwSetKeyCallback(window, HandleKeyboard); glfwSetMouseButtonCallback(window, HandleMouseButton); glfwSetFramebufferSizeCallback(window, HandleReshape); glfwMakeContextCurrent(window); glfwSwapInterval(1); std::cout << glGetString(GL_VERSION) << std::endl; std::cout << glfwGetJoystickName(GLFW_JOYSTICK_1) << std::endl; renderer.Create(); int framebuffer_width, framebuffer_height; glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height); HandleReshape(window, framebuffer_width, framebuffer_height); controller.Setup(); while (!glfwWindowShouldClose(window)) { if (keyboard.GetKeyVelocity(GLFW_KEY_TAB) > 0) { if (minimized) { glfwSetWindowSize(window, width, height); glfwShowWindow(window); } else { glfwHideWindow(window); glfwSetWindowSize(window, kMinimizedWidth, kMinimizedHeight); } minimized = !minimized; } if (minimized) { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } else { renderer.Render(); } controller.Update(); keyboard.Update(); mouse.Update(); double x, y; glfwGetCursorPos(window, &x, &y); mouse.OnCursorMove(glm::vec2(x, y)); joystick.Update(); input.Update(); glfwSwapBuffers(window); glfwPollEvents(); if (minimized) { usleep(16666); } } glfwTerminate(); return 0; }
static void StartDisplay(void) { const int width = kParams.canvas_width; const int height = kParams.canvas_height; glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(width, height); glutCreateWindow("WebP viewer"); glutDisplayFunc(HandleDisplay); glutIdleFunc(NULL); glutKeyboardFunc(HandleKey); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glClearColor(GetColorf(kParams.bg_color, 0), GetColorf(kParams.bg_color, 8), GetColorf(kParams.bg_color, 16), GetColorf(kParams.bg_color, 24)); HandleReshape(width, height); glClear(GL_COLOR_BUFFER_BIT); DrawCheckerBoard(); }