Exemplo n.º 1
0
// uiloop
void ui_loop(const ym_string& filename, const ym_string& imfilename,
             yo_scene* scene, ysr_scene* rigid_scene, float dt, int w, int h,
             bool camera_lights, float amb, bool no_ui) {
    // view data
    view_params* view = init_view_params(
        filename, imfilename, scene, rigid_scene, dt, w, h, camera_lights, amb);

    // glfw
    if (!glfwInit()) exit(EXIT_FAILURE);
    GLFWwindow* window = glfwCreateWindow(view->w, view->h, "yshade", 0, 0);
    glfwMakeContextCurrent(window);
    glfwSetWindowUserPointer(window, view);

    // callbacks
    glfwSetCharCallback(window, text_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    glfwSetMouseButtonCallback(window, mouse_button_callback);
    glfwSetCursorPosCallback(window, mouse_pos_callback);
    glfwSetWindowRefreshCallback(window, window_refresh_callback);

// init gl extensions
#ifndef __APPLE__
    if (glewInit() != GLEW_OK) exit(EXIT_FAILURE);
#endif

    // init shade state
    view->shade_prog = yg_stdshader_make_program();
    view->shade_txt.resize(scene->textures.size());
    for (int i = 0; i < scene->textures.size(); i++) {
        yo_texture* txt = &scene->textures[i];
        view->shade_txt[i] =
            yg_make_texture(txt->pixels.data(), txt->width, txt->height,
                            txt->ncomp, false, true);
    }

    // ui loop
    while (!glfwWindowShouldClose(window)) {
        window_refresh_callback(window);

        if (view->simulating) {
            simulate_step(view);
            glfwPollEvents();
        } else {
            glfwWaitEvents();
        }
    }

    glfwDestroyWindow(window);
    glfwTerminate();

    delete view;
}
Exemplo n.º 2
0
// uiloop
void
ui_loop(int nimgs, view_img* imgs) {
    // view params
    view_params* view = init_view_params(nimgs, imgs);

    // window
    if (!glfwInit()) exit(EXIT_FAILURE);
    GLFWwindow* window = glfwCreateWindow(view->w, view->h, "imview", 0, 0);
    glfwMakeContextCurrent(window);
    glfwSetWindowUserPointer(window, view);

    // callbacks
    glfwSetCharCallback(window, text_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    glfwSetMouseButtonCallback(window, mouse_button_callback);
    glfwSetCursorPosCallback(window, mouse_pos_callback);
    glfwSetWindowRefreshCallback(window, window_refresh_callback);

    // init gl extensions
#ifdef YG_USING_GLEW
    if (glewInit() != GLEW_OK) exit(EXIT_FAILURE);
#endif
    
    // load textures
    for (int i = 0; i < nimgs; i++) {
        imgs[i].tex_glid = yg_make_texture(imgs[i].pixels, imgs[i].w, imgs[i].h,
                                           imgs[i].nc, true, false);
    }

    // ui loop
    while (!glfwWindowShouldClose(window)) {
        window_refresh_callback(window);
        glfwWaitEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();

    free(view);
}