Exemplo n.º 1
0
void reshape(int n_w, int n_h)
{
    simConfig.setWindow( n_h, n_w );
    //Change the viewport to be correct
    glViewport( 0, 0, simConfig.getWindowWidth(), simConfig.getWindowHeight());

}
Exemplo n.º 2
0
//--Main
int main(int argc, char **argv)
{
    //set config data
    simConfig.setWindow(800, 1280);

    // Initialize glut
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize( simConfig.getWindowWidth(), simConfig.getWindowHeight());
    glutInitWindowPosition( 100, 100);
    // Name and create the Window
    glutCreateWindow("Air Hockey");
    glutFullScreen();

    // Now that the window is created the GL context is fully set up
    // Because of that we can now initialize GLEW to prepare work with shaders
    GLenum status = glewInit();
    if( status != GLEW_OK)
    {
        std::cerr << "[F] GLEW NOT INITIALIZED: ";
        std::cerr << glewGetErrorString(status) << std::endl;
        return -1;
    }

    // Set all of the callbacks to GLUT that we need
    //glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF); //disable key spamming for now
    glutDisplayFunc(render);// Called when its time to display
    glutReshapeFunc(reshape);// Called if the window is resized
    glutIdleFunc(update);// Called if there is nothing else to do
    glutMouseFunc(mouse);// Called if there is mouse input
    glutMotionFunc(mouseChange);
    glutPassiveMotionFunc(mouseChange);
    glutKeyboardFunc(keyPressed);// Called if there is keyboard input
    glutKeyboardUpFunc(keyUp);// Called if there is keyboard anti-input
    glutSpecialFunc(keyboardPlus);// for stuff without ascii access characters like arrow keys

    //setup inputs
    menuID = glutCreateMenu(menu_test);
    glutAddMenuEntry("Resume", 4);
    glutAddMenuEntry("Pause", 3);
    glutAddMenuEntry("Restart", 2);
    glutAddMenuEntry("Quit", 1);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    //misc setup
    simEntities.simConfig = &simConfig;

    // Initialize all of our resources(config, geometry)
    bool init = initialize();

    //load model data
    #ifdef TESTING
    simEntities.loadData("../bin/data/test_load_list.dat"); // don't want to load all those machines if I'm just testing
    #else
    simEntities.loadData("../bin/data/load_list.dat");
    #endif

    //run our shader loader now
    init = init && simShaderManager.loadShaders(argc,argv);

    //call some other resources to initialize after the shader, separately
    init = init && postInitialize();

    if(init)
    {
        t1 = std::chrono::high_resolution_clock::now();
        glutMainLoop();
    }

    // Clean up after ourselves
    cleanUp();
    return 0;
}