Exemplo n.º 1
0
int main(int argc, char** argv)
{
    bool run = GL_TRUE;

    if(!glfwInit())
    {
        exit(EXIT_FAILURE);
    }

    if(!glfwOpenWindow(windows_width, windows_height, 8, 8, 8, 8, 24, 0, GLFW_WINDOW))
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glewInit();
    if (!glewIsSupported( "GL_VERSION_2_0 "
                          "GL_ARB_pixel_buffer_object"
                        )) {
        fprintf( stderr, "ERROR: Support for necessary OpenGL extensions missing.");
        fflush( stderr);
        return false;
    }

    //glfwSetKeyCallback(Viewer::keyCallback);
    //glfwSetMouseButtonCallback(Viewer::mouseButtonCallback);
    //glfwSetMousePosCallback(Viewer::mousePosCallback);
    //glfwSetMouseWheelCallback(Viewer::mouseWheelCallback);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    FluidSim sph;
    sph.initialize();
    sph.resetFrameNum();
    sph.outputObj(true);

    vec3 center(0.0f, -0.15f, 0.0f);
    Viewer::camera()->setFocal(center.x, center.y, center.z);
    Viewer::camera()->resetLookAt();

    old_now = glfwGetTime();
    while(run)
    {
        unsigned int frame_num = sph.getFrameNum();
        if(frame_num > 450)
            exit(0);
        Viewer::camera()->aim();

        printf("frame number: %d\n", frame_num);
        sph.compute(0.004);
        sph.draw();

        utils::drawAxis();
        utils::grabScreen(windows_width, windows_height, sph.getFrameNum());
        now = glfwGetTime();
        char fpsInfo[256];
        sprintf(fpsInfo, "Frame: %u. Time cost per frame: %f", frame_num, now - old_now);
        old_now = now;
        glfwSetWindowTitle(fpsInfo);

        glfwSwapBuffers();

        run = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}