Beispiel #1
0
int Graphics::initialize(int argc, char *argv[]){
  // initialize GLUT
  glutInit(&argc, argv);
  // initialize the window size
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

  glutInitWindowSize(w_, h_);
  // set the window postion
  //glutInitWindowPosition(350, 350);
  // create the window
  glutCreateWindow("CollideFx");
  //glutEnterGameMode();

  glInitialize();
    
  // set the idle function - called when idle
  glutIdleFunc(idle);
  // set the display function - called when redrawing
  glutDisplayFunc(display);
  // set the reshape function - called when client area changes
  glutReshapeFunc(reshape);
  // set the mouse function - called on mouse stuff
  glutMouseFunc(mouse);
  glutMotionFunc(mouseMotion);
  glutKeyboardFunc(keyboard);
  time_pre = -1;


  return 0;
}
Beispiel #2
0
Ptr<Window> App::addWindow(std::string const & title)
{
	OwnPtr<Window> window;
	window.setNew(title);
	if(windows.empty())
	{
		glContext = SDL_GL_CreateContext(window->getSDLWindow());
		glInitialize();
	}
	windows.insert(window);
	return window;
}
Beispiel #3
0
int main( int argc, char *argv[] )
{
    GLFWwindow *window;
    int Edit;
    //File name to load
    string fileName;
    //whether name inputtted is valid
    bool validFile = false;

    //Try to determine file input
    while(validFile == false) {
        printf("Type the file to load (Special options: 'd' = default, 'c' = clean):\n");
        scanf("%s", &fileName[0]);

        ifstream toLoad(&fileName[0]);
        validFile = toLoad.good();

        //If 'c' was entered, then load a clean level
        if(strcmp(&fileName[0], "c") == 0) {
            printf("Loading clean level...\n");
            fileName = "clean";
            validFile = true;
        }
        //If 'd' was entered, then deafult level
        else if(strcmp(&fileName[0], "d") == 0) {
            printf("Loading default level...\n");
            fileName = "default";
            validFile = true;
        }
        else if(validFile == false) {
            printf("Bad file, please type another file to load.\n");
        }
        else if(validFile == true) {
            toLoad.close();
        }
    }

    //Determine mode
    printf("Type 0 to play, any other int to edit\n");
    scanf("%i", &Edit);

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

    //If Edit Mode
    if(Edit) {
        //World Edit Init
        //initWorldEdit(window);
        window = glfwCreateWindow(800, 800, "World Editor", NULL, NULL);
        if (!window) {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        srand(time(0));
        glfwMakeContextCurrent(window);
        glfwSetWindowPos(window, 80, 80);
        glfwSetWindowSizeCallback(window, glfwWindowResize);
        glfwSetWindowSize(window,1600,800);
        g_height =800;
        g_width = 1600;
        setDistance(7);
        SetEdit(1);
        paused = false;

        glfwSetKeyCallback( window, glfwEditKeyPress);
        glfwSetCursorPosCallback( window, glfwEditGetCursorPos );
        glfwSetMouseButtonCallback( window, glfwEditMouse );
        glfwSetScrollCallback( window, glfwEditScroll );

        glewInit();
        glInitialize(window);
        physicsInit();
        InitGeom();
        initLevelLoader();
        loadLevel(fileName);
    }
    //If Play Mode
    else {
        //Game Play Init
        //initGamePlay(window);
        window = glfwCreateWindow(800, 800, "Grapple", NULL, NULL);
        if (!window) {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        srand(time(0));
        SetEye(vec3(0, 0, 0));
        glfwMakeContextCurrent(window);
        glfwSetWindowPos(window, 80, 80);
        glfwSetWindowSizeCallback(window, glfwWindowResize);
        glfwSetWindowSize(window,1600,800);
        g_height =800;
        g_width = 1600;
        setDistance(10);
        paused = false;

        glfwSetKeyCallback(window, glfwGameKeyPress);
        glfwSetCursorPosCallback( window, glfwGameGetCursorPos );

        glewInit();
        glInitialize(window);
        physicsInit();
        InitGeom();
        initLevelLoader();
        loadLevel(fileName);
    }

    ShadowMap *shadowMap = new ShadowMap();
    if (shadowMap->MakeShadowMap(g_width, g_height) == -1) {
        printf("SHADOW MAP FAILED\n");
        exit(EXIT_FAILURE);
    }

    // Start the main execution loop.
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
        if(Edit) {
            if(paused == false) {
                //Keep the cursor centered
                glfwSetCursorPos(window,g_width/2,g_height/2);
                renderScene(window, shadowMap);
                glfwEditGetCursorPos(NULL,g_width/2.0,g_height/2.0);
                //glfw Game Keyboard
                glfwEditKeyboard();
            }
        }
        else {
            if(paused == false) {
                //player appy physics controls
                SetLookAt(glm::vec3(physGetPlayerX(),physGetPlayerY(),physGetPlayerZ()));
                SetSpeed(.05*magnitude(getPlayerSpeed()));
                //Keep the cursor centered
                glfwSetCursorPos(window,g_width/2,g_height/2);
                physStep();
                //Draw stuff
                renderScene(window, shadowMap);
                glfwGameGetCursorPos(NULL,g_width/2.0,g_height/2.0);
                //glfw Game Keyboard
                glfwGameKeyboard();
            }
        }
        usleep(15000);
    }

    // Clean up after GLFW.
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}