Callback functions in GLFW

Callback functions in GLFW


These are almost all the callback functions I read in the documentation of GLFW 3.2, excluding the callback functions about the Joystick input.
The subtitle indicates which guide the callback functions come from.


refer to the documentation, if you do not know how to correctly use these callback functions. About some Joystic input, I haven’t read it this time.


Introduction to the API

glfwSetErrorCallback(error_callback);
void error_callback(int error, const char* description)
{
    puts(description);
}

Monitor guide

glfwSetMonitorCallback(monitor_callback);
void monitor_callback(GLFWmonitor* monitor, int event)
{
    if (event == GLFW_CONNECTED)
    {
        // The monitor was connected
    }
    else if (event == GLFW_DISCONNECTED)
    {
        // The monitor was disconnected
    }
}

Window guide

glfwSetWindowCloseCallback(window, window_close_callback);
void window_close_callback(GLFWwindow* window)
{
    if (!time_to_close)
        glfwSetWindowShouldClose(window, GLFW_FALSE);
}

glfwSetWindowSizeCallback(window, window_size_callback);
void window_size_callback(GLFWwindow* window, int width, int height)
{
}

glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    glViewport(0, 0, width, height);
}

glfwSetWindowPosCallback(window, window_pos_callback);
void window_pos_callback(GLFWwindow* window, int xpos, int ypos)
{
}

glfwSetWindowIconifyCallback(window, window_iconify_callback);
void window_iconify_callback(GLFWwindow* window, int iconified)
{
    if (iconified)
    {
        // The window was iconified
    }
    else
    {
        // The window was restored
    }
}

glfwSetWindowFocusCallback(window, window_focus_callback);
void window_focus_callback(GLFWwindow* window, int focused)
{
    if (focused)
    {
        // The window gained input focus
    }
    else
    {
        // The window lost input focus
    }
}

glfwSetWindowRefreshCallback(m_handle, window_refresh_callback);
void window_refresh_callback(GLFWwindow* window)
{
    draw_editor_ui(window);
    glfwSwapBuffers(window);
}

Input guide

glfwSetKeyCallback(window, key_callback);
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_E && action == GLFW_PRESS)
        activate_airship();
}

glfwSetCharCallback(window, character_callback);
void character_callback(GLFWwindow* window, unsigned int codepoint)
{
}

glfwSetCharModsCallback(window, charmods_callback);
void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods)
{
}

glfwSetCursorPosCallback(window, cursor_pos_callback);
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos)
{
}

glfwSetCursorEnterCallback(window, cursor_enter_callback);
void cursor_enter_callback(GLFWwindow* window, int entered)
{
    if (entered)
    {
        // The cursor entered the client area of the window
    }
    else
    {
        // The cursor left the client area of the window
    }
}

glfwSetMouseButtonCallback(window, mouse_button_callback);
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
    if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
        popup_menu();
}

glfwSetScrollCallback(window, scroll_callback);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
}

glfwSetDropCallback(window, drop_callback);
void drop_callback(GLFWwindow* window, int count, const char** paths)
{
    int i;
    for (i = 0;  i < count;  i++)
        handle_dropped_file(paths[i]);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章