Example #1
1
int main( int argc, char *argv[] )
{
   glutInit( &argc, argv );
   glutInitWindowPosition( 200, 200 );
   glutInitWindowSize( 800, 500 );
   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
   glutCreateWindow("World of Awesome");
   glutReshapeFunc( ReshapeGL );
   glutDisplayFunc( Draw );
   glutKeyboardFunc( keyboard );
   glutMouseFunc( mouse );
   glutMotionFunc( mouseMove );
   glutPassiveMotionFunc( passiveMove );
   glutTimerFunc(TIMER_DELAY, tock, 0);

   g_width = g_height = 200;

#ifdef _WIN32 
   GLenum err = glewInit();
   if (GLEW_OK != err)
   {
      std::cerr << "Error initializing glew! " << glewGetErrorString(err) << std::endl;
      return 1;
   }
#endif
#ifdef __APPLE__
   glutSetCursor(GLUT_CURSOR_NONE); 
#endif

   backShade = glm::vec3(0.2,0.5,0.9);

   Initialize();
   
   //test the openGL version
   getGLversion();
   //install the shader
   if (!InstallShader(textFileRead((char *)"shaders/vert.glsl"), textFileRead((char *)"shaders/frag.glsl")))   {
      printf("Error installing shader!\n");
      return 0;
   }

   InitGeom();


   g_shadeType = PHONG;

   g_pitch = 0;
   g_yaw = M_PI / 2;
   float tx = cos(g_pitch)*cos(g_yaw);
   float ty = sin(g_pitch);
   float tz = cos(g_pitch)*cos(M_PI/2 - g_yaw);
   eye = glm::vec3(0, 2.5, 0);
   target = eye + glm::vec3(tx, ty, tz);
   sunDir = normalize(vec3(-0.2, -1.0, 0.0));


   sunShade = glm::vec3(1.0, 1.0, 0.9);

   glutMainLoop();
   return 0;
}
Example #2
0
int main( int argc, char *argv[] )
{
   	glutInit( &argc, argv );
   	glutInitWindowPosition( 20, 20 );
   	glutInitWindowSize( 400, 400 );
   	glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
   	glutCreateWindow("My first triangle");
   	glutReshapeFunc( ReshapeGL );
   	glutDisplayFunc( Draw );
   	Initialize();
	
	//test the openGL version
	getGLversion();
	//install the shader
	if (!InstallShader(textFileRead((char *)"GLSL_Lab1.glsl"))) {
		printf("Error installing shader!\n");
		return 0;
	}
		
	InitGeom();
  	glutMainLoop();
   	return 0;
}
Example #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);
}
Example #4
0
main()
{
	DB		db[2];		/* packet double buffer */
	DB		*cdb;		/* current db */
	MATRIX		rottrans;	/* rot-trans matrix */
	int		i;		/* work */
	int		dmy, flg;	/* dummy */
	CVECTOR		col[12];	/* cube color */
	u_long		cnt;

	etc.near_clip=500;
	etc.far_clip=5000;
	etc.clip_off=0;
	
	PadInit(0);             /* initialize PAD */
	ResetGraph(0);		/* reset graphic subsystem (0:cold,1:warm) */
	SetGraphDebug(0);	/* set debug mode (0:off, 1:monitor, 2:dump) */
	
	InitGeom();			/* initialize geometry subsystem */
	SetGeomOffset(320, 240);	/* set geometry origin as (160, 120) */
	SetGeomScreen(SCR_Z);		/* distance to viewing-screen */

	SetLightMatrix(&LLM);
	SetColorMatrix(&LCM);
	SetBackColor(BK.vx,BK.vy,BK.vz);
	SetFarColor(FC.vx,FC.vy,FC.vz);
	SetFogNear(1*SCR_Z,SCR_Z);
	
	/* initialize environment for double buffer (interlace)
	 *	buffer ID	VRAM address 
	 *-------------------------------------------------------
	 *	buffer #0	(0,  0)-(640,480)
	 *	buffer #1	(0,  0)-(640,480)
	 */
	SetDefDrawEnv(&db[0].draw, 0, 0, 640, 480);	
	SetDefDrawEnv(&db[1].draw, 0, 0, 640, 480);	
	SetDefDispEnv(&db[0].disp, 0, 0, 640, 480);	
	SetDefDispEnv(&db[1].disp, 0, 0, 640, 480);
	
	FntLoad(960,256);
	SetDumpFnt(FntOpen(64,64,256,200,0,512));
	SetRCnt(RCntCNT2,0xffff,RCntMdNOINTR|RCntMdFR);
	StartRCnt(RCntCNT2);

	/* set surface colors */
	for (i = 0; i < 12; i+=2) {
		col[i].r = col[i+1].r = 0xff/*rand()*/;	/* R */
		col[i].g = col[i+1].g = 0xff/*rand()*/;	/* G */
		col[i].b = col[i+1].b = 0xff/*rand()*/;	/* B */
		col[i].cd = col[i+1].cd = CODE_G3;	/* cd */
	}
	
	init_prim(&db[0]);	/* set primitive parameters on buffer #0 */
	init_prim(&db[1]);	/* set primitive parameters on buffer #1 */
	
	SetDispMask(1);		/* enable to display (0:inhibit, 1:enable) */
	
	while (pad_read(&rottrans) == 0) {
		cdb = (cdb==db)? db+1: db;	/* swap double buffer ID */
		ClearOTagR(cdb->ot, OTSIZE);	/* clear ordering table */

		/* add cube */
		ResetRCnt(RCntCNT2);

		add_cube(cdb->ot, cdb->s, v, n, col);

		cnt= GetRCnt(RCntCNT2);
		FntPrint("cnt=%d\n",cnt);
		
		/* swap buffer */
		DrawSync(0);	/* wait for end of drawing */
		VSync(0);	/* wait for the next V-BLNK */
	
		PutDrawEnv(&cdb->draw); /* update drawing environment */
		PutDispEnv(&cdb->disp); /* update display environment */

		DrawOTag(cdb->ot+OTSIZE-1);	/* draw */
		FntFlush(-1);
	}
        PadStop();
        exit();
}