Exemple #1
0
//--Main
int main(int argc, char **argv) 
{
    //Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(w, h);
        
    Lighting.Init();////////////// ADD

    // Name and create the Window
    glutCreateWindow("LABYRINTH PROGRAM");

    //temp Mesh model
    Mesh tempMesh;
    
    //add the number of holes values
    numOfHoles.push_back(1);
    numOfHoles.push_back(3);
    numOfHoles.push_back(6);
    level = 0;

    //initialize textures
    char metal_file[] = "../textures/metal.png";
    char white_marble_file[] = "../textures/MarbleWhite.png";
    char black_marble_file[] = "../textures/gold.png";
    char red_solid_file[] = "../textures/red.png";
    char green_solid_file[] = "../textures/green.png";
    char black_solid_file[] = "../textures/black.png";
    char brown_solid_file[] = "../textures/brown.png";

    //load textures
    Magick::InitializeMagick(*argv);
    
    loadTexture(metal_file, metal);
    loadTexture(black_marble_file, black_marble);
    loadTexture(white_marble_file, white_marble);
    loadTexture(red_solid_file, red_solid);
    loadTexture(black_solid_file, black_solid);
    loadTexture(green_solid_file, green_solid);
    loadTexture(brown_solid_file, brown_solid);

    GLenum status = glewInit(); //check glut status
    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
    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
    glutKeyboardFunc(keyboard); // Called if there is keyboard input
    glutMouseFunc(mouse);
    glutMotionFunc(mouseOnTheMove);

    //Initialize all of our resources
    shaderManager = new ShaderManager();

    bool init = initialize(); //initialize shaders and load models

    //build mesh objects
    tempMesh.initialize("board");
    tempMesh.initial_bound = meshManager.getBounds("board");
    tempMesh.current_position = tempMesh.initial_bound;
    boardMesh = tempMesh;

    tempMesh.initialize("sphere");
    tempMesh.initial_bound = meshManager.getBounds("sphere");
    tempMesh.current_position = tempMesh.initial_bound;
    sphereMesh = tempMesh;


    //initialize maze
    buildMaze(  abs(boardMesh.initial_bound.second.z - boardMesh.initial_bound.first.z) - 1,
                abs(boardMesh.initial_bound.second.x - boardMesh.initial_bound.first.x) - 1);
    
    //translate the ball to the start position
    ballSetStart();
    
    //initialize menus
    createMenus();

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

    return 0;
}