// Initialize GLUT & OpenSG and set up the scene
int main (int argc, char **argv)
{
    int i;
    float ca=-1,cb=-1,cc=-1;
    // OSG init
    osgInit(argc,argv);
    char *filename=NULL;

    // GLUT init
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    int winid = glutCreateWindow("OpenSG");
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(key);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // create the scene
    float x,y,z;
    scene = Node::create();
    beginEditCP(scene);
    scene->setCore(Group::create());
    endEditCP(scene);

    NodePtr file;

    for(i=1;i<argc;++i)
    {
        if(argv[i][0] =='-')
        {
            switch(argv[i][1])
            {
                case 'd':
                    useFaceDistribution=true;
                    break;
                case 'v':
                    viewVolume=true;
                    break;
                case 's':
                    serverCount=atoi(&argv[i][2]);
                    break;
                case 'l':
                    loop=atoi(&argv[i][2]);
                    break;
                case 'S':
                    simulateRendering=true;
                    break;
            }
        }
        else
        {
            if(argv[i][0] >='0' &&
               argv[i][0] <='9')
            {
                if(ca==-1)
                    ca=atoi(argv[i]);
                else
                    if(cb==-1)
                        cb=atoi(argv[i]);
                    else
                        if(cc==-1)
                            cc=atoi(argv[i]);
            }
            else
            {
                filename=argv[1];
            }
        }
    }
    if(ca == -1 && filename)
    {
        file = OSG::SceneFileHandler::the().read(filename);
        beginEditCP(scene);
        scene->addChild(file);
        endEditCP(scene);
    }
    else
    {
        if(ca==-1)
            ca=4;
        if(cb==-1)
            cb=ca;
        if(cc==-1)
            cc=cb;
        if(file == NullFC)
        {
            GeometryPtr geo=makeBoxGeo(.6,.6,.6,20,20,20);
            beginEditCP(geo);
            SimpleMaterialPtr mat=SimpleMaterial::create();
            beginEditCP(mat);
            mat->setAmbient(Color3f(.4,.4,.4));
            mat->setSpecular(Color3f(0,0,0));
            mat->setDiffuse(Color3f(1,1,1));
            endEditCP(mat);
            geo->setMaterial(mat);
            endEditCP(geo);
            NodePtr node;
            NodePtr geoNode;
            TransformPtr trans;
            for(x=-ca/2 ; x<ca/2 ; x++)
                for(y=-cb/2 ; y<cb/2 ; y++)
                    for(z=-cc/2 ; z<cc/2 ; z++)
                    {
                        trans=Transform::create();
                        node=Node::create();
                        geoNode=Node::create();
                        
                        beginEditCP(geoNode);
                        beginEditCP(trans);
                        beginEditCP(node);
                        
                        node->setCore(trans);
                        trans->getMatrix().setTranslate(x,y,z);
                        if(!filename)
                        {
                            geoNode=Node::create();
                            geoNode->setCore(geo);
                        }
                        else
                        {
                            geoNode = OSG::SceneFileHandler::the().read(filename);
                        }
                        node->addChild( geoNode );
                        beginEditCP(scene);
                        scene->addChild(node);
                        
                        endEditCP(geoNode);
                        endEditCP(scene);
                        endEditCP(trans);
                        endEditCP(node);
                    }
        }
    }
    // create the SimpleSceneManager helper
    mgr = new MySceneManager;

    mgr->setWindow( gwin );
    mgr->setRoot( scene );

    mgr->showAll();

    // GLUT main loop
    if(loop)
        glutIdleFunc(display);
//    glutReshapeWindow(720,576);
    glutReshapeWindow(1152,864);
    glutMainLoop();

    return 0;
}
Example #2
0
int main (int argc, char** argv) {
	// Standard stuff...
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Index Buffers");
	glutReshapeFunc(changeViewport);
	
	glewInit();

	initMatrices(); // New <========================================
	vao=gen_particles();

/*#ifdef USING_INDEX_BUFFER


	
#endif*/

	// Make a shader
	char* vertexShaderSourceCode = readFile("vertexShader1.vsh");
	char* fragmentShaderSourceCode = readFile("fragmentShader1.fsh");
	GLuint vertShaderID = makeVertexShader(vertexShaderSourceCode);
	GLuint fragShaderID = makeFragmentShader(fragmentShaderSourceCode);
	shaderProgramID = makeShaderProgram(vertShaderID, fragShaderID);

	/*/ / Create the "remember all"
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	// Create the buffer, but don't load anything yet
	//glBufferData(GL_ARRAY_BUFFER, 7*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
	glBufferData(GL_ARRAY_BUFFER, 6*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
	
	// Load the vertex points
	glBufferSubData(GL_ARRAY_BUFFER, 0, 3*NUM_VERTICES*sizeof(GLfloat), vertices);
	// Load the colors right after that
	//glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),4*NUM_VERTICES*sizeof(GLfloat), colors);
	glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),3*NUM_VERTICES*sizeof(GLfloat), normals);*/
	
	
/*#ifdef USING_INDEX_BUFFER
	glGenBuffers(1, &indexBufferID);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, NUM_INDICES*sizeof(GLuint), indices, GL_STATIC_DRAW);
#endif*/
	

	// Find the position of the variables in the shader
	//ositionID = glGetAttribLocation(shaderProgramID, "v_i");
	//colorID = glGetAttribLocation(shaderProgramID, "elapsed_system_time");
	
	// ============ New! glUniformLocation is how you pull IDs for uniform variables===============
	perspectiveMatrixID = glGetUniformLocation(shaderProgramID, "P");
	viewMatrixID = glGetUniformLocation(shaderProgramID, "V");
	emitterID=glGetUniformLocation(shaderProgramID, "emitter_pos_wor");
	timeID=glGetUniformLocation(shaderProgramID, "elapsed_system_time");
	
	//=============================================================================================

	/*glVertexAttribPointer(positionID, 3, GL_FLOAT, GL_FALSE, 0, 0);
	//glVertexAttribPointer(colorID, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices)));
	glVertexAttribPointer(colorID, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices)));
	printf ("BUFFER_OFFSET is: %d\n", sizeof(vertices));*/

	glUseProgram(shaderProgramID);
	//glEnableVertexAttribArray(positionID);
	//glEnableVertexAttribArray(colorID);
	//glEnable(GL_DEPTH_TEST);
    //glClearColor( 0.0, 0.0, 0.0, 0.2 );

	//current_seconds=Timer();
	glutDisplayFunc(render);

	glutKeyboardFunc( keyboard );
	glutMainLoop();
	
	return 0;
}
    FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name, int _width, int _height) {
		printf("freglutglview start");
	    renderer = (RendererWin32*) _renderer;

	    /* annoying useless setup for glutInit */

		char* argv[] = {_strdup(name.c_str())};
	    int argc = 1;
	
	    glutInit(&argc, argv);
	    glutInitContextVersion(3,3);
		
		printf("freglutglview start");
		glutInitWindowSize(_width, _height);
	    glutCreateWindow(name.c_str());

		//glew initialization
		glewExperimental = GL_TRUE;
		GLenum err = glewInit();
		if (GLEW_OK != err)	{
			cerr << "Error: " << glewGetErrorString(err) << endl;
		}
		else {
			if (GLEW_VERSION_3_3) {
				cout << "Driver supports OpenGL 3.3\nDetails:" << endl;
			}
		}
		err = glGetError(); //this is to ignore INVALID ENUM error 1282
	//	GL_CHECK_ERRORS


			//output hardware information
		cout << "\tUsing GLEW " << glewGetString(GLEW_VERSION) << endl;
		cout << "\tVendor: " << glGetString(GL_VENDOR) << endl;
		cout << "\tRenderer: " << glGetString(GL_RENDERER) << endl;
		cout << "\tVersion: " << glGetString(GL_VERSION) << endl;
		cout << "\tGLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;

		// call this ONLY when linking with FreeImage as a static library
		
		#ifdef FREEIMAGE_LIB
				FreeImage_Initialise();
				cout << "\tFreeImage: " << FreeImage_GetVersion() << endl;
		#endif
		

    //	glutGameModeString("1280x1024:32@60");
    //	glutEnterGameMode();
		
		renderer->setStartTick();
	    renderer->onCreate();

	    glutDisplayFunc(&display);
	    glutReshapeFunc(&reshape);
		glutKeyboardFunc(&keyboard);
	    glutMouseFunc(&pressed);
	    glutMotionFunc(&dragged);
	    glutPassiveMotionFunc(&moved);
		glutIdleFunc(&animate);
		printf("freglutglview start");
		//lastTime = std::clock();
		//std::time(&lastTime);
	    //gettimeofday(&lastTime, NULL);
		printf("freglutglview start");
	    glutMainLoop();

	    //glutInitDisplayMode(GL_RGBA);
	    //glutInitWindowSize(200,200);
	    //glutCreateWindow("test");
		printf("freglutglview start");
	    return NULL;
	    //return glView;
		
    }
Example #4
0
int main(int argc, char *argv[]) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH |
		GLUT_STENCIL);
	if((argc > 1) && (strcmpi(argv[1], "--helmet") == 0)) {
		/*left eye*/
		glutInitWindowPosition(0,0);
		glutInitWindowSize(640, 480);
		left_eye = glutCreateWindow("Escher World - Left Eye");

		glutSetWindow(left_eye);
		set_window_size(640, 480);
		glutDisplayFunc(displayleft);
		glutKeyboardFunc(keyfunc);
		glutMouseFunc(mouse_button);
		glutPassiveMotionFunc(passive_mouse_motion);
		glutMotionFunc(passive_mouse_motion);
		glutReshapeFunc(set_window_size);
/*		glutTimerFunc(10,child,1);*/

		/* right eye */
		glutInitWindowPosition(641,0);
		glutInitWindowSize(640, 480);
		right_eye = glutCreateWindow("Escher World - Right Eye");

		glutSetWindow(right_eye);
		set_window_size(640, 480);
		glutDisplayFunc(displayright);
		glutKeyboardFunc(keyfunc);
		glutMouseFunc(mouse_button);
		glutPassiveMotionFunc(passive_mouse_motion);
		glutMotionFunc(passive_mouse_motion);
		glutReshapeFunc(set_window_size);

		glutSetWindow(left_eye);
		create_menus();
		init();
		/* Initialize the scene */
		init_scene(FILENAME);

		glutSetWindow(right_eye);
		create_menus();
		create_menus();
		init();
		/* Initialize the scene */
		init_scene(FILENAME);

#ifdef USE_HELMET
/*		main_helmet();
		signal(SIGUSR1, cleanup);
*/		birdinit();
/*		glutTimerFunc(10,child,1);*/
#endif

	} else {
		glutInitWindowPosition(64,64);

		glutInitWindowSize(768, 832);
		glut_window = glutCreateWindow("Escher World");

		glutSetWindow(glut_window);
		set_window_size(768, 832);
		helmet = !helmet;
		glutDisplayFunc(displaymid);
		glutKeyboardFunc(keyfunc);
		glutMouseFunc(mouse_button);
		glutPassiveMotionFunc(passive_mouse_motion);
		glutMotionFunc(passive_mouse_motion);
		glutReshapeFunc(set_window_size);
		create_menus();
		init();
		/* Initialize the scene */
		init_scene(FILENAME);
	}

	glutMainLoop();

	return 0;
}
Example #5
0
int main(int argc, char **argv)
{
    int i;

    if (argc > 1) {		/* make sure at least 2 args, program and file */
      strncpy(filename, argv[argc - 1], sizeof(filename));	/* get the last arg as the file always */

	for (i = 0; i < argc; i++) {	/* check for startup params */
	    if (strstr(argv[i], "-s"))
		stereo = 1;
	    if (strstr(argv[i], "-f"))
		full_screen = 1;
	}
    } else {			/* user only entered program name, help them */

	printf("Usage: %s [-s] [-f] <obj filename>\n", argv[0]);
	exit(0);
    }


    glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

    glutInitWindowSize(1024, 768);	/*  Window Size If We Start In Windowed Mode */
    glutCreateWindow("Wavefront Obj File Viewer");
    if (full_screen)
	glutFullScreen();


    glutDisplayFunc(Display);
    glutKeyboardFunc(Keyboard);
    getMatrix();
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClearAccum(0.0, 0.0, 0.0, 0.0);
    glutReshapeFunc(Reshape);
    glutMouseFunc(Mouse);
    glutMotionFunc(Motion);
    glutIdleFunc(NULL);

    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    if (lighting)
	glEnable(GL_LIGHTING);
    if (lighting)
	glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_TEXTURE_2D);

	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

    if (!pmodel) {		/* load up the model */
	pmodel = glmReadOBJ(filename);
	if (!pmodel) {
	    printf("\nUsage: objviewV2 <-s> <obj filename>\n");
	    exit(0);
	}
	glmUnitize(pmodel);
	glmVertexNormals(pmodel, 90.0, GL_TRUE);
    }

    glutMainLoop();

    return 0;
}
Example #6
0
void RenderThread::operator()() {

    RENDER.SetTimeStamp(getElapsedTime());

    // -- Start the Clock ------------------------------------------- //
    g_ullAppStartTime = RENDER.GrabTimeStamp();
    PROF.StartProfiling(g_ullAppStartTime);


    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(GAMECONFIG.m_uiWindowWidth,
                       GAMECONFIG.m_uiWindowHeight);

    glutInit(&m_argc, m_argv);

    if (!GAMECONFIG.m_bWindowedMode)
    {
        char temp[64];
        sprintf_s(temp,
                "%dx%d:%d@%d",
                GAMECONFIG.m_uiWindowWidth,
                GAMECONFIG.m_uiWindowHeight,
                32,
                75);

        glutGameModeString(temp);

        // start fullscreen game mode
        glutEnterGameMode();
    }
    else
    {
        glutCreateWindow("Swarm: Rise of the Transactional Tripods");
    }

    atexit(gKillGame);
    glutKeyboardFunc(gKeyboard);
    glutDisplayFunc(gRender);
    glutReshapeFunc(gChangeSize);
    glutIdleFunc(gIdle);

    // -- VSync ----------------------------------------------------- //
    // Note that OpenGL by default blocks
    // rendering to match the actual monitor refresh rate
    //
    // We want to push frames ASAP, perhaps starting a new one
    // before the old one is presented to the monitor. This allows
    // for FPS of thousands on very simple apps.
    //
    // I do not know the linux equivalent of this code
#ifdef _MSC_VER
    if (!GAMECONFIG.m_bVSyncLock)
    {
        typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
        PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;

        wglSwapIntervalEXT =
            (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");

        if (wglSwapIntervalEXT)
            wglSwapIntervalEXT(0);
    }
#endif


    // -- Set GL for RENDER ----------------------------------------- //
    RENDER.ConfigureRenderer();

    // -- Give GLUT control of this thread forever ------------------ //
    glutMainLoop();
}
Example #7
0
int main(int argc, char *argv[])
{        
    // Initialise OpenGL
    glutInit(&argc, argv); 

    // Set window position, size & create window
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowPosition(50,50);
    glutInitWindowSize(width,height);
	windowId = glutCreateWindow("Ray Cast Volume Rendering");
	
	glewInit();

    // Set GLUT callback functions
	glutDisplayFunc(renderScene);
	//glutIdleFunc(updateScene);
	glutKeyboardFunc(keypress);

    // Setup OpenGL state & scene resources 
    init();

	//GLUI
    glui = GLUI_Master.create_glui( "Controls", 0, 865, 50); 

	movement_panel = new GLUI_Panel( glui, "Movement Parameters" );
    
	view_rot = new GLUI_Rotation( movement_panel, "Rotate", view_rotate );
	view_rot->set_spin( 1.0 );

	trans_z = new GLUI_Translation( movement_panel, "Zoom", GLUI_TRANSLATION_Z, &zoom );
	trans_z->set_speed( .05 );

	raycastPGM = new GLUI_Checkbox(glui, "Raycast /w XToon & Alpha Interpolation", &raycastEnable, RAYCAST, controlCB);
	xtoonPGM = new GLUI_Checkbox(glui, "Raycast XToon Shader", &xtoonEnable, XTOONPGM, controlCB);
	gradientPGM = new GLUI_Checkbox(glui, "Gradient", &gradientEnable, GRADIENT, controlCB);
	dvrPGM = new GLUI_Checkbox(glui, "DVR", &dvrEnable, DVR, controlCB);
	rin = new GLUI_Checkbox(glui, "Show Ray Start", &rayinToggle, RAYIN, controlCB);
	rout = new GLUI_Checkbox(glui, "Show Ray Stop", &rayoutToggle, RAYOUT, controlCB);

	column_01 = new GLUI_Column( glui );

	GUIRayCastRoll = new GLUI_Rollout( glui, "Ray Cast Parameters", false);

	raycaster_panel = new GLUI_Panel( GUIRayCastRoll, "" );
	jittering = new GLUI_Checkbox( raycaster_panel, "Stippling", &j, JITTER, controlCB );
	jittering->set_alignment( GLUI_ALIGN_RIGHT );

    GUIsamples = new GLUI_Spinner( raycaster_panel, "N Samples", &nSamples );
	GUIsamples->set_int_limits( 0, 255 );
    GUIsamples->set_alignment( GLUI_ALIGN_RIGHT );

    GUInoise = new GLUI_Spinner( raycaster_panel, "Noise Delta", &noiseDelta );
	GUInoise->set_float_limits( 1.0, 10.0 );
    GUInoise->set_alignment( GLUI_ALIGN_RIGHT );

    GUIstep = new GLUI_Spinner( raycaster_panel, "Step Length", &stepLength );
	GUIstep->set_float_limits( 0.01f, 1.0f );
    GUIstep->set_alignment( GLUI_ALIGN_RIGHT );

    GUIt = new GLUI_Spinner( raycaster_panel, "Threshold", &threshold );
	GUIt->set_float_limits( 0.01f, 1.0f );
    GUIt->set_alignment( GLUI_ALIGN_RIGHT );

    GUIgscale = new GLUI_Spinner( raycaster_panel, "Gradient Scale", &gradientScale );
	GUIgscale->set_float_limits( 0.01f, 1.0f );
    GUIgscale->set_alignment( GLUI_ALIGN_RIGHT );

    GUIgdelta = new GLUI_Spinner( raycaster_panel, "Gradient Delta", &gradientDelta );
	GUIgdelta->set_float_limits( 0.01f, 1.0f );
    GUIgdelta->set_alignment( GLUI_ALIGN_RIGHT );

    GUIfmax = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Max", &fMax );
	GUIfmax->set_float_limits( 0.01f, 255.0f );
    GUIfmax->set_alignment( GLUI_ALIGN_RIGHT );

    GUIfmin = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Min", &fMin );
	GUIfmin->set_float_limits( 0.0f, 255.0f );
    GUIfmin->set_alignment( GLUI_ALIGN_RIGHT );

    GUIalpha = new GLUI_Spinner( raycaster_panel, "Alpha Value", &alpha );
	GUIalpha->set_float_limits( 0.01f, 1.0f );
    GUIalpha->set_alignment( GLUI_ALIGN_RIGHT );

    GUItscale = new GLUI_Spinner( raycaster_panel, "Transfer Scale", &transferScale );
	GUItscale->set_float_limits( 0.01f, 1.0f );
    GUItscale->set_alignment( GLUI_ALIGN_RIGHT );

    GUIthick = new GLUI_Spinner( raycaster_panel, "Thickness", &thickness );
	GUIthick->set_float_limits( 0.01f, 1.0f );
    GUIthick->set_alignment( GLUI_ALIGN_RIGHT );

	GUIXToonRoll = new GLUI_Rollout( glui, "XTOON Parameters", false );
	
	xtoon_panel = new GLUI_Panel( GUIXToonRoll, "" );

	toneDetailBox = new GLUI_Checkbox(xtoon_panel, "Tone Detail", &toneDetail, XTOONTYPE, controlCB );

    GUIr = new GLUI_Spinner( xtoon_panel, "Coarse Detail", &R );
	GUIr->set_float_limits( 1.0f, 25.0f );
    GUIr->set_alignment( GLUI_ALIGN_RIGHT );

	backlightBOX = new GLUI_Checkbox(xtoon_panel, "Backlighting", &backlight, XTOONTYPE, controlCB );

    GUIR = new GLUI_Spinner( xtoon_panel, "Backlight Detail", &backlight_detail );
	GUIR->set_float_limits( 0.0f, 25.0f );
    GUIR->set_alignment( GLUI_ALIGN_RIGHT );

	specularBOX = new GLUI_Checkbox(xtoon_panel, "Specular Highlight", &specHighlight, XTOONTYPE, controlCB );

    GUIs = new GLUI_Spinner( xtoon_panel, "Shine Factor", &S );
	GUIs->set_float_limits( 1.0f, 25.0f );
    GUIs->set_alignment( GLUI_ALIGN_RIGHT );

	xtoonBOX = new GLUI_Checkbox(xtoon_panel, "Enable / Disable", &xToonFlag, XTOON, controlCB );

	glui->set_main_gfx_window(windowId);
    
	glutInitWindowSize(300, 300);
	subWindowId = glutCreateWindow("Transfer Function 2D Texture");
	glutPositionWindow(865, 350);

	// Set GLUT callback functions
	glutReshapeFunc(setViewport);
	glutDisplayFunc(renderSub);
	glutKeyboardFunc(keypressSub);
	
	// Setup OpenGL state & scene resources 
	initSub();

	GLUI_Master.set_glutIdleFunc(updateScene); 

    // Show window & start update loop
    glutMainLoop();    

	return 0;
}
Example #8
0
int main (int argc, char **argv)
{

/* **************************************************************************************************************************** */

 	/* Pointeurs vers l'application */
	glutInit(&argc, argv);         

  	/*  Activation des buffers :   
     	Double buffer 
     	RGBA color
     	Depth buffer */               
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); 

  	/* Création de la fenêtre */
	glutInitWindowSize(1024, 768);

	/* Positionnement de la fenêtre */
	glutInitWindowPosition(100, 100);

	/* Ouverture de la fenêtre */  
	glutCreateWindow("TD_Animation_3D");

	/* Spécification de la fontion de dessin */
	glutDisplayFunc(display);

  	/* Spécification de la fontion de redimensionnement */
	glutReshapeFunc(reshape);

  	/* Spécification des fontions de gestion du clavier */
	glutKeyboardFunc(keyboardDown);
	glutKeyboardUpFunc(keyboardUp);
	glutSpecialFunc(keyboardSpecDown);
	glutSpecialUpFunc(keyboardSpecUp);

 	/* Spécification des fontions de gestion de la souris */
	glutMouseFunc(mouse);
	glutMotionFunc(motion);

 	/* Spécification de la fonction de mise-à-jour */
	glutIdleFunc(timeTick);

/* **************************************************************************************************************************** */

	/* Affichage des fonctions clavier */
	HelpMessage();

/* **************************************************************************************************************************** */

	/* Intitialisation des paramètres de l'affichage et de la fenêtre */
	GLInit();

	/* Intitialisation des paramètres du squelette */ 
	SkeletInit();

	/* Intitialisation de la scène cinématique */
	IKInit();

/* **************************************************************************************************************************** */

  	/* Lancement de la boucle OpenGL */  
	glutMainLoop();

/* **************************************************************************************************************************** */

	return 0;

/* **************************************************************************************************************************** */
}
Example #9
0
int main(int argc, char* argv[])
{
  /****************************************/
  /*   Initialize GLUT and create window  */
  /****************************************/

  glutInit(&argc, argv);
  glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  glutInitWindowPosition( 50, 50 );
  glutInitWindowSize( 300, 300 );
 
  main_window = glutCreateWindow( "GLUI Example 2" );
  glutDisplayFunc( myGlutDisplay );
  glutReshapeFunc( myGlutReshape );  
  glutKeyboardFunc( myGlutKeyboard );
  glutMotionFunc( myGlutMotion );
  glutMouseFunc( myGlutMouse );

  /****************************************/
  /*       Set up OpenGL lights           */
  /****************************************/

  GLfloat light0_ambient[] =  {0.1f, 0.1f, 0.3f, 1.0f};
  GLfloat light0_diffuse[] =  {.6f, .6f, 1.0f, 1.0f};
  GLfloat light0_position[] = {1.0f, 1.0f, 1.0f, 0.0f};

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);

  /****************************************/
  /*          Enable z-buferring          */
  /****************************************/

  glEnable(GL_DEPTH_TEST);

  /****************************************/
  /*         Here's the GLUI code         */
  /****************************************/

  GLUI *glui = GLUI_Master.create_glui( "GLUI", 0, 400, 50 ); /* name, flags,
								 x, and y */
  new GLUI_StaticText( glui, "GLUI Example 2" );
  new GLUI_Separator( glui );
  checkbox = new GLUI_Checkbox( glui, "Wireframe", &wireframe, 1, control_cb );
  spinner  = new GLUI_Spinner( glui, "Segments:", &segments, 2, control_cb );
  spinner->set_int_limits( 3, 60 );
  edittext = new GLUI_EditText( glui, "Text:", text, 3, control_cb );
  GLUI_Panel *obj_panel = new GLUI_Panel( glui, "Object Type" );
  radio = new GLUI_RadioGroup( obj_panel,&obj,4,control_cb );
  new GLUI_RadioButton( radio, "Sphere" );
  new GLUI_RadioButton( radio, "Torus" );
  new GLUI_RadioButton( radio, "Teapot" );
  new GLUI_Button( glui, "Quit", 0,(GLUI_Update_CB)exit );
 
  glui->set_main_gfx_window( main_window );

  /* We register the idle callback with GLUI, *not* with GLUT */
  GLUI_Master.set_glutIdleFunc( myGlutIdle );
  GLUI_Master.set_glutIdleFunc( NULL );

  glutMainLoop();

  return EXIT_SUCCESS;
}
/**
 * Method for create a window
 */
void Visualizer::createWindow(const char * title)
{
        xnew=0; ynew=0; znew=0;                   /* actual position */
        xold=0; yold=0; zold=0;                   /* old position */
        xx1=0; yy1=0; zz1=0;                      /* mouse position*/
        mouseState=0;                             /* mouse button state */
        xshift=0; yshift=0;                       /* shifting in space*/

        xnew=0; ynew=0; znew=0;                   /* actual position */
        xold=0; yold=0; zold=0;                   /* old position */
        xx1=0; yy1=0; zz1=0;                      /* mouse position*/
        mouseState=0;                             /* mouse button state */
        xshift=0; yshift=0;                       /* shifting in space*/

	fov=45.0;                                 /* field of view */
	near_plane=1;                             /* trim plain */
	far_plane=1000.0;                         /* farther trim plain */
	line_width=1.0;                           /* width of line */
	WindowWidth=1024;                         /* width and height of window */
	WindowHeight=768;
	ObjectType=0;                             /* type of paint object */
	Solid=1;                                  /* fill or wireframe model */

	char * dummy_argv[1];
	dummy_argv[0] = const_cast<char *>("run");
	int dummy_argc = 1;

	glutInit(&dummy_argc, dummy_argv);

	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE ); /* graphic mod of window */

        glutInitWindowSize(WindowWidth,WindowHeight); /* original window size */
        glutInitWindowPosition(10,10);                /* original window position */
        glutCreateWindow(title);                      /* create window */

        glutDisplayFunc(onDisplay);                   /* set function for redisplay */
        glutReshapeFunc(onReshape);                   /* set function for change of size window */
        glutKeyboardFunc(onKeyboard);                 /* set function for press key */
        glutSpecialFunc(onSpecial);
        glutMouseFunc(onMouseClick);                  /* set function for press mouse button */
        glutMotionFunc(onMouseMotion);                /* set function for mouse move */

        glClearColor(0.0, 0.0, 0.0, 0.0);             /* color for clearing of color-buffer */
        glClearDepth(1.0f);                           /* color for clearing of z-buffer */
        glEnable(GL_DEPTH_TEST);                      /* configure function for testing value in z-buffer */
        glDepthFunc(GL_LESS);                         /* select function */
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); /* improvement display */

        glEnable(GL_CULL_FACE);
        glPolygonMode(GL_FRONT, GL_FILL);             /* configure draw of fill polygons */
        //glCullFace(GL_FRONT);

        glLineWidth(line_width);                      /* line width */
	glPointSize(line_width);

	//glEnable(GL_MULTISAMPLE);
#ifdef FREEGLUT
    #ifdef GLUT_AUX
	int *sampleNumbers = NULL;
	int sampleNumbersSize = 0;
	sampleNumbers = glutGetModeValues(GLUT_MULTISAMPLE, &sampleNumbersSize);
	if(sampleNumbers != NULL)
	{
		glutSetOption(GLUT_MULTISAMPLE, sampleNumbers[sampleNumbersSize - 1]);
		printf("Multisampling with %i samples.\n", sampleNumbers[sampleNumbersSize - 1]);
		free(sampleNumbers);
	}
	else
	{
		printf("Multisampling is not available.\n");
	}
    #endif
#endif

        scene_ = glGenLists(1);                        /* get number of calllist */
        createCallList();                             /* initialization */

	glutMainLoop();
}
Example #11
0
File: main.c Project: damora/ivr
//-----------------------------------------------------------------------------------------------------------------------//
// main
//-----------------------------------------------------------------------------------------------------------------------//
int main(int argc,  char * argv[])
{
    int rc=0;
    int rank=0;
#ifdef MPI
    int comsize;

    // init MPI
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &comsize);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    fprintf(stderr,"rank=%d\n", rank);
#ifdef BGQ
    install_signal_handler();
#endif
#endif

    args = parseargs(argc, argv);

    // init, initcamera, initvolattrs
    if ((rc=init(args, rank) != 0)) {
        fprintf(stderr, "initialization failed: %d\n", rc);
        return 0;
    };

    //---------------------------- Platform Specific Display and Interaction ----------------------------------------//
#if LOCAL

    resettransforms();
    mystate.alpha=0.25f;

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(WINDOWWIDTH, WINDOWHEIGHT);
    glutCreateWindow("iVR");
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mousebutton);
    glutMotionFunc(mousemotion);
//    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glDisable(GL_DEPTH_TEST);
    glutMainLoop();
#elif MPI		// BEGIN MPI CODE
#ifdef REMOTE 	// START OF REMOTE RENDERING HANDSHAKE

    // connect to relay server
    if (rank == 0) {
        sockfd = initconnection(HOSTNAME, PORT);
        if (sockfd == -1) {
            fprintf(stderr,"remote connection failed, sockfd=%d\n",sockfd);
            freeall();
            exit(0);
        }
        fprintf(stderr,"relay connection succeeded\n");
    }
    PRINTDEBUG("%3d: \n", rank);
    boolean_t connected = TRUE;
    int ctr = 0;
    while (connected) {  // main loop when steering
        fprintf(stderr,"%3d: before steering control\n", rank);
        if (rank == 0) {
            rc = recvstate(sockfd, &mystate);
            fprintf(stderr,"bytes recvd=%d\n", rc);
            if (mystate.finish) connected = 0;;
            winwidth = mystate.winwidth;
            winheight=mystate.winheight;
        } // end if rank == 0 for remote visualization
        // wait until we've completed the handshake with steering client before proceeding;
        MPI_Barrier(MPI_COMM_WORLD);
        MPI_Bcast(&connected, 1, MPI_INT, 0, MPI_COMM_WORLD);
        if (!connected) break;
        MPI_Bcast((float *)&winwidth, 1, MPI_FLOAT, 0, MPI_COMM_WORLD);
        MPI_Bcast((float *)&winheight, 1, MPI_FLOAT, 0, MPI_COMM_WORLD);
        MPI_Bcast(&mystate.alpha, 1, MPI_FLOAT, 0, MPI_COMM_WORLD);
        MPI_Bcast(mystate.newconst, 6, MPI_FLOAT, 0, MPI_COMM_WORLD);
        MPI_Bcast(mystate.mvm, 16, MPI_FLOAT, 0, MPI_COMM_WORLD);
        MPI_Bcast(mystate.pm, 16, MPI_FLOAT, 0, MPI_COMM_WORLD);
        MPI_Bcast(mystate.vv, 4, MPI_FLOAT, 0, MPI_COMM_WORLD);
#endif
        float planeconst[6] = {pzero[0], pzero[1], pzero[2], pzero[3], pzero[4], pzero[5]};
        setviewport(&viewport, 0, 0, winwidth, winheight);
        setplaneconst(planeconst, mystate.newconst);
        setmvm(mvm, mystate.mvm);
        setpm(pm, mystate.pm);
        setfrustum(&viewvolume, mystate.vv);
        updatevolbbox();
        initcolbufs(rank);

        // create and display the image
        unsigned long long lstart, lstop;
        for (int i=0; i<1; i++) {
            TIME(RENDER, lstart);
            createlocalimage(rank);
            // can't composite until all ranks have completed local image generation
            MPI_Barrier(MPI_COMM_WORLD);
            compositelocalimage();
            TIME(RENDER, lstop);
            PERFORMANCE(lstart, lstop, framenum, elapsed, avg);
        }
        // wait until all ranks exit composite step before writing image
        MPI_Barrier(MPI_COMM_WORLD);
        writeimage(ctr++);
#ifdef REMOTE
    } // end while remote loop
    if (rank == 0) disconnect(sockfd);
#endif // END OF REMOTE CLIENT  HANDSHAKE


    fprintf(stderr,"%3d: finished\n", rank);
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Finalize();
#endif
    // clean up
    freeall();
    exit(0);
}
Example #12
0
int main(int argc, char** argv) {
	// Standard stuff...
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowSize(1080, 600);
	glutCreateWindow("Lighted Cube");
	glutReshapeFunc(changeViewport);
	glutKeyboardFunc(keyboardFunc);
	glutDisplayFunc(render);
	glewInit();

	initMatrices(); // New <========================================


	// Make a shader
	char* vertexShaderSourceCode = readFile("vertexShader.vsh");
	char* fragmentShaderSourceCode = readFile("fragmentShader.fsh");
	GLuint vertShaderID = makeVertexShader(vertexShaderSourceCode);
	GLuint fragShaderID = makeFragmentShader(fragmentShaderSourceCode);
	shaderProgramID = makeShaderProgram(vertShaderID, fragShaderID);

	// Create the "remember all"
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	// Create the buffer, but don't load anything yet
	//glBufferData(GL_ARRAY_BUFFER, 7*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
	glBufferData(GL_ARRAY_BUFFER, 6 * NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW); // NEW! - we're only loading vertices and normals (6 elements, not 7)

	// Load the vertex points
	glBufferSubData(GL_ARRAY_BUFFER, 0, 3 * NUM_VERTICES*sizeof(GLfloat), vertices);
	// Load the colors right after that
	//glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),4*NUM_VERTICES*sizeof(GLfloat), colors);
	glBufferSubData(GL_ARRAY_BUFFER, 3 * NUM_VERTICES*sizeof(GLfloat), 3 * NUM_VERTICES*sizeof(GLfloat), normals);


#ifdef USING_INDEX_BUFFER
	glGenBuffers(1, &indexBufferID);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, NUM_INDICES*sizeof(GLuint), indices, GL_STATIC_DRAW);
#endif

	// Find the position of the variables in the shader
	positionID = glGetAttribLocation(shaderProgramID, "s_vPosition");
	normalID = glGetAttribLocation(shaderProgramID, "s_vNormal"); // NEW
	lightID1 = glGetUniformLocation(shaderProgramID, "vLight1");    // NEW
	lightID2 = glGetUniformLocation(shaderProgramID, "vLight2");    // NEW

	// ============ New! glUniformLocation is how you pull IDs for uniform variables===============
	perspectiveMatrixID = glGetUniformLocation(shaderProgramID, "mP");
	viewMatrixID = glGetUniformLocation(shaderProgramID, "mV");
	modelMatrixID = glGetUniformLocation(shaderProgramID, "mM");
	allRotsMatrixID = glGetUniformLocation(shaderProgramID, "mRotations"); // NEW
	//=============================================================================================

	glVertexAttribPointer(positionID, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glVertexAttribPointer(normalID, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices)));

	glUseProgram(shaderProgramID);
	glEnableVertexAttribArray(positionID);
	glEnableVertexAttribArray(normalID);    // NEW

	glEnable(GL_CULL_FACE);  // NEW! - we're doing real 3D now
	glCullFace(GL_BACK);     // Other options? GL_FRONT and GL_FRONT_AND_BACK
	glEnable(GL_DEPTH_TEST); // Make sure the depth buffer is on.  As you draw a pixel, update the screen only if it's closer than previous ones

	glutMainLoop();

	return 0;
}
Example #13
0
// ------------------------------------------------------------------- main ---
int main( int argc, char **argv )
{
    FILE* test;
    size_t i, j;
    int arg;

    wchar_t * font_cache = 
        L" !\"#$%&'()*+,-./0123456789:;<=>?"
        L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
        L"`abcdefghijklmnopqrstuvwxyz{|}~";

    float  font_size   = 0.0;
    const char * font_filename   = NULL;
    const char * header_filename = NULL;
    const char * variable_name   = "font";
    int show_help = 0;

    for ( arg = 1; arg < argc; ++arg )
    {
        if ( 0 == strcmp( "--font", argv[arg] ) || 0 == strcmp( "-f", argv[arg] ) )
        {
            ++arg;

            if ( font_filename )
            {
                fprintf( stderr, "Multiple --font parameters.\n" );
                print_help();
                exit( 1 );
            }

            if ( arg >= argc )
            {
                fprintf( stderr, "No font file given.\n" );
                print_help();
                exit( 1 );
            }

            font_filename = argv[arg];
            continue;
        }

        if ( 0 == strcmp( "--header", argv[arg] ) || 0 == strcmp( "-o", argv[arg] )  )
        {
            ++arg;

            if ( header_filename )
            {
                fprintf( stderr, "Multiple --header parameters.\n" );
                print_help();
                exit( 1 );
            }

            if ( arg >= argc )
            {
                fprintf( stderr, "No header file given.\n" );
                print_help();
                exit( 1 );
            }

            header_filename = argv[arg];
            continue;
        }

        if ( 0 == strcmp( "--help", argv[arg] ) || 0 == strcmp( "-h", argv[arg] ) )
        {
            show_help = 1;
            break;
        }

        if ( 0 == strcmp( "--size", argv[arg] ) || 0 == strcmp( "-s", argv[arg] ) )
        {
            ++arg;

            if ( 0.0 != font_size )
            {
                fprintf( stderr, "Multiple --size parameters.\n" );
                print_help();
                exit( 1 );
            }

            if ( arg >= argc )
            {
                fprintf( stderr, "No font size given.\n" );
                print_help();
                exit( 1 );
            }

            errno = 0;

            font_size = atof( argv[arg] );

            if ( errno )
            {
                fprintf( stderr, "No valid font size given.\n" );
                print_help();
                exit( 1 );
            }

            continue;
        }

        if ( 0 == strcmp( "--variable", argv[arg] ) || 0 == strcmp( "-arg", argv[arg] )  )
        {
            ++arg;

            if ( 0 != strcmp( "font", variable_name ) )
            {
                fprintf( stderr, "Multiple --variable parameters.\n" );
                print_help();
                exit( 1 );
            }

            if ( arg >= argc )
            {
                fprintf( stderr, "No variable name given.\n" );
                print_help();
                exit( 1 );
            }

            variable_name = argv[arg];
            continue;
        }

        fprintf( stderr, "Unknown parameter %s\n", argv[arg] );
        print_help();
        exit( 1 );
    }

    if ( show_help )
    {
        print_help();
        exit( 1 );
    }

    if ( !font_filename )
    {
        fprintf( stderr, "No font file given.\n" );
        print_help();
        exit( 1 );
    }

    if ( !( test = fopen( font_filename, "r" ) ) )
    {
        fprintf( stderr, "Font file \"%s\" does not exist.\n", font_filename );
    }

    fclose( test );

    if ( 4.0 > font_size )
    {
        fprintf( stderr, "Font size too small, expected at least 4 pt.\n" );
        print_help();
        exit( 1 );
    }

    if ( !header_filename )
    {
        fprintf( stderr, "No header file given.\n" );
        print_help();
        exit( 1 );
    }

    texture_atlas_t * atlas = texture_atlas_new( 128, 128, 1 );
    texture_font_t  * font  = texture_font_new_from_file( atlas, font_size, font_filename );

    glutInit( &argc, argv );
    glutInitWindowSize( atlas->width, atlas->height );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutCreateWindow( "Freetype OpenGL" );
    glutReshapeFunc( reshape );
    glutDisplayFunc( display );
    glutKeyboardFunc( keyboard );

    size_t missed = texture_font_load_glyphs( font, font_cache );

    wprintf( L"Font filename              : %s\n", font_filename );
    wprintf( L"Font size                  : %.1f\n", font_size );
    wprintf( L"Number of glyphs           : %ld\n", wcslen(font_cache) );
    wprintf( L"Number of missed glyphs    : %ld\n", missed );
    wprintf( L"Texture size               : %ldx%ldx%ld\n",
             atlas->width, atlas->height, atlas->depth );
    wprintf( L"Texture occupancy          : %.2f%%\n", 
            100.0*atlas->used/(float)(atlas->width*atlas->height) );
    wprintf( L"\n" );
    wprintf( L"Header filename            : %s\n", header_filename );
    wprintf( L"Variable name              : %s\n", variable_name );


    size_t texture_size = atlas->width * atlas->height *atlas->depth;
    size_t glyph_count = font->glyphs->size;
    size_t max_kerning_count = 1;
    for( i=0; i < glyph_count; ++i )
    {
        texture_glyph_t *glyph = *(texture_glyph_t **) vector_get( font->glyphs, i );

        if( vector_size(glyph->kerning) > max_kerning_count )
        {
            max_kerning_count = vector_size(glyph->kerning);
        }
    }


    FILE *file = fopen( header_filename, "w" );


    // -------------
    // Header
    // -------------
    fwprintf( file, 
        L"/* ============================================================================\n"
        L" * Freetype GL - A C OpenGL Freetype engine\n"
        L" * Platform:    Any\n"
        L" * WWW:         http://code.google.com/p/freetype-gl/\n"
        L" * ----------------------------------------------------------------------------\n"
        L" * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.\n"
        L" *\n"
        L" * Redistribution and use in source and binary forms, with or without\n"
        L" * modification, are permitted provided that the following conditions are met:\n"
        L" *\n"
        L" *  1. Redistributions of source code must retain the above copyright notice,\n"
        L" *     this list of conditions and the following disclaimer.\n"
        L" *\n"
        L" *  2. Redistributions in binary form must reproduce the above copyright\n"
        L" *     notice, this list of conditions and the following disclaimer in the\n"
        L" *     documentation and/or other materials provided with the distribution.\n"
        L" *\n"
        L" * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR\n"
        L" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
        L" * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n"
        L" * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
        L" * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n"
        L" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n"
        L" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n"
        L" * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
        L" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n"
        L" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
        L" *\n"
        L" * The views and conclusions contained in the software and documentation are\n"
        L" * those of the authors and should not be interpreted as representing official\n"
        L" * policies, either expressed or implied, of Nicolas P. Rougier.\n"
        L" * ===============================================================================\n"
        L" */\n");


    // ----------------------
    // Structure declarations
    // ----------------------
    fwprintf( file,
        L"#include <stddef.h>\n"
        L"#ifdef __cplusplus\n"
        L"extern \"C\" {\n"
        L"#endif\n"
        L"\n"
        L"typedef struct\n"
        L"{\n"
        L"    wchar_t charcode;\n"
        L"    float kerning;\n"
        L"} kerning_t;\n\n" );

    fwprintf( file,
        L"typedef struct\n"
        L"{\n"
        L"    wchar_t charcode;\n"
        L"    int width, height;\n"
        L"    int offset_x, offset_y;\n"
        L"    float advance_x, advance_y;\n"
        L"    float s0, t0, s1, t1;\n"
        L"    size_t kerning_count;\n"
        L"    kerning_t kerning[%d];\n"
        L"} texture_glyph_t;\n\n", max_kerning_count );

    fwprintf( file,
        L"typedef struct\n"
        L"{\n"
        L"    size_t tex_width;\n"
        L"    size_t tex_height;\n"
        L"    size_t tex_depth;\n"
        L"    char tex_data[%d];\n"
        L"    float size;\n"
        L"    float height;\n"
        L"    float linegap;\n"
        L"    float ascender;\n"
        L"    float descender;\n"
        L"    size_t glyphs_count;\n"
        L"    texture_glyph_t glyphs[%d];\n"
        L"} texture_font_t;\n\n", texture_size, glyph_count );


    
    fwprintf( file, L"texture_font_t %s = {\n", variable_name );


    // ------------
    // Texture data
    // ------------
    fwprintf( file, L" %d, %d, %d, \n", atlas->width, atlas->height, atlas->depth );
    fwprintf( file, L" {" );
    for( i=0; i < texture_size; i+= 32 )
    {
        for( j=0; j < 32 && (j+i) < texture_size ; ++ j)
        {
            if( (j+i) < (texture_size-1) )
            {
                fwprintf( file, L"%d,", atlas->data[i+j] );
            }
            else
            {
                fwprintf( file, L"%d", atlas->data[i+j] );
            }
        }
        if( (j+i) < texture_size )
        {
            fwprintf( file, L"\n  " );
        }
    }
    fwprintf( file, L"}, \n" );


    // -------------------
    // Texture information
    // -------------------
    fwprintf( file, L" %ff, %ff, %ff, %ff, %ff, %d, \n", 
             font->size, font->height,
             font->linegap,font->ascender, font->descender,
             glyph_count );

    // --------------
    // Texture glyphs
    // --------------
    fwprintf( file, L" {\n" );
    for( i=0; i < glyph_count; ++i )
    {
        texture_glyph_t * glyph = *(texture_glyph_t **) vector_get( font->glyphs, i );

/*
        // Debugging information
        wprintf( L"glyph : '%lc'\n",
                 glyph->charcode );
        wprintf( L"  size       : %dx%d\n",
                 glyph->width, glyph->height );
        wprintf( L"  offset     : %+d%+d\n",
                 glyph->offset_x, glyph->offset_y );
        wprintf( L"  advance    : %ff, %ff\n",
                 glyph->advance_x, glyph->advance_y );
        wprintf( L"  tex coords.: %ff, %ff, %ff, %ff\n", 
                 glyph->u0, glyph->v0, glyph->u1, glyph->v1 );

        wprintf( L"  kerning    : " );
        if( glyph->kerning_count )
        {
            for( j=0; j < glyph->kerning_count; ++j )
            {
                wprintf( L"('%lc', %ff)", 
                         glyph->kerning[j].charcode, glyph->kerning[j].kerning );
                if( j < (glyph->kerning_count-1) )
                {
                    wprintf( L", " );
                }
            }
        }
        else
        {
            wprintf( L"None" );
        }
        wprintf( L"\n\n" );
*/


        // TextureFont
        if( (glyph->charcode == L'\'' ) || (glyph->charcode == L'\\' ) )
        {
            fwprintf( file, L"  {L'\\%lc', ", glyph->charcode );
            //wprintf( L"  {L'\\%lc', ", glyph->charcode );
        }
        else if( glyph->charcode == (wchar_t)(-1) )
        {
            fwprintf( file, L"  {L'\\0', " );
            //wprintf( L"  {L'\\0', " );
        }
        else
        {
            fwprintf( file, L"  {L'%lc', ", glyph->charcode );
            //wprintf( L"  {L'%lc', ", glyph->charcode );
        }
        fwprintf( file, L"%d, %d, ", glyph->width, glyph->height );
        fwprintf( file, L"%d, %d, ", glyph->offset_x, glyph->offset_y );
        fwprintf( file, L"%ff, %ff, ", glyph->advance_x, glyph->advance_y );
        fwprintf( file, L"%ff, %ff, %ff, %ff, ", glyph->s0, glyph->t0, glyph->s1, glyph->t1 );
        fwprintf( file, L"%d, ", vector_size(glyph->kerning) );
        fwprintf( file, L"{ " );
        for( j=0; j < vector_size(glyph->kerning); ++j )
        {
            kerning_t *kerning = (kerning_t *) vector_get( glyph->kerning, j);
            wchar_t charcode = kerning->charcode;

            if( (charcode == L'\'' ) || (charcode == L'\\') )
            {
                fwprintf( file, L"{L'\\%lc', %ff}", charcode, kerning->kerning );
            }
            else if( (charcode != (wchar_t)(-1) ) )
            {
                fwprintf( file, L"{L'%lc', %ff}", charcode, kerning->kerning );
            }
            if( j < (vector_size(glyph->kerning)-1))
            {
                fwprintf( file, L", " );
            }
        }
        fwprintf( file, L"} },\n" );
    }
    fwprintf( file, L" }\n};\n" );

    fwprintf( file,
        L"#ifdef __cplusplus\n"
        L"}\n"
        L"#endif\n" );

    return 0;
}
Example #14
0
int
main(int argc, char **argv)
{
    int i;
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);

    for (i=1; i<argc; i++) {
        if(!strcmp("-noms", argv[i])) {
            glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
            printf("forcing no multisampling\n");
        } else if(!strcmp("-nomipmaps", argv[i])) {
            useMipmaps = 0;
        } else if(!strcmp("-nearest", argv[i])) {
            linearFiltering = 0;
        }
    }
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(600,300);
    glutCreateWindow("sprite blast");
    glutReshapeFunc(reshape);
    glutDisplayFunc(redraw);
    glutMouseFunc(mouse);
    glutMotionFunc(mouseMotion);
    glutVisibilityFunc(visible);
    glutKeyboardFunc(key);
    glutCreateMenu(menu);
    glutAddMenuEntry("Reset time", 0);
    glutAddMenuEntry("Constant", 1);
    glutAddMenuEntry("Linear", 2);
    glutAddMenuEntry("Quadratic", 3);
    glutAddMenuEntry("Blend on", 4);
    glutAddMenuEntry("Blend off", 5);
    glutAddMenuEntry("Threshold 1", 6);
    glutAddMenuEntry("Threshold 10", 7);
    glutAddMenuEntry("Point smooth on", 8);
    glutAddMenuEntry("Point smooth off", 9);
    glutAddMenuEntry("Point size 4", 10);
    glutAddMenuEntry("Point size 8", 11);
    glutAddMenuEntry("Point size 16", 12);
    glutAddMenuEntry("Toggle spin", 13);
    glutAddMenuEntry("200 points ", 14);
    glutAddMenuEntry("500 points ", 15);
    glutAddMenuEntry("1000 points ", 16);
    glutAddMenuEntry("2000 points ", 17);
    glutAddMenuEntry("Quit", 666);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POINT_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPointSize(16.0);
#ifdef GL_ARB_point_parameters
    glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
#endif

    makePointList();
    makeSprite();

    glutMainLoop();
    return 0;             /* ANSI C requires main to return int. */
}
Example #15
0
main(int argc, char *argv[])
{
    GLuint *tex;
    int texwid, texht, texcomps;

    GLUquadricObj *quadric;

    glutInitWindowSize(winWidth, winHeight);
    glutInit(&argc, argv);
    if(argc > 1)
    {
        char *args = argv[1];
        int done = FALSE;
        while(!done)
        {
            switch(*args)
            {
            case 's': /* single buffer */
                printf("Single Buffered\n");
                dblbuf = FALSE;
                break;
            case '-': /* do nothing */
                break;
            case 0:
                done = TRUE;
                break;
            }
            args++;
        }
    }
    if(dblbuf)
        glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
    else
        glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH);
    (void)glutCreateWindow("example program");
    glutDisplayFunc(redraw_original);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(key);

    /* draw a perspective scene */
    glMatrixMode(GL_PROJECTION);
    glFrustum(-100., 100., -100., 100., 300., 600.);
    glMatrixMode(GL_MODELVIEW);
    /* look at scene from (0, 0, 450) */
    gluLookAt(0., 0., 450., 0., 0., 0., 0., 1., 0.);

    /* turn on features */
    glEnable(GL_DEPTH_TEST);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

    glMateriali(GL_FRONT, GL_SHININESS, 128); /* cosine power */

    /* remove back faces to speed things up */
    glCullFace(GL_BACK);
    glBlendFunc(GL_ONE, GL_ONE);

    lightchanged[UPDATE_TEX] = GL_TRUE;
    lightchanged[UPDATE_OGL] = GL_TRUE;

    /* load pattern for current 2d texture */

    tex = read_texture("../data/wood.rgb", &texwid, &texht, &texcomps);

    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA,
                      GL_UNSIGNED_BYTE, tex);
    free(tex);
    CHECK_ERROR("end of main");

    lighttex = (GLfloat *)malloc(texdim * texdim * sizeof(GL_FLOAT) * 3);



    /* XXX TODO use display list to avoid retesselating */
    glNewList(1, GL_COMPILE);
    glutSolidSphere((GLdouble)texdim/2., 50, 50);
    glEndList();


    glNewList(2, GL_COMPILE);
    glutSolidTeapot(70.);
    glEndList();

    quadric = gluNewQuadric();
    gluQuadricTexture(quadric, GL_TRUE);

    glNewList(3, GL_COMPILE);
    gluSphere(quadric, 70., 20, 20);
    glEndList();

    gluDeleteQuadric(quadric);
    maxobject = 3;

    glutMainLoop();

    return 0;
}
int main(int argc, char *argv[])
{
	// inicjalizacja biblioteki GLUT
	glutInit(&argc, argv);

	// inicjalizacja bufora ramki
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

	// rozmiary głównego okna programu
	glutInitWindowSize(500, 500);

	// utworzenie głównego okna programu
	glutCreateWindow("Zadanie 2");

	// dołączenie funkcji generującej scenę 3D
	glutDisplayFunc(DisplayScene);

	// dołączenie funkcji wywoływanej przy zmianie rozmiaru okna
	glutReshapeFunc(Reshape);

	// dołączenie funkcji obsługi klawiatury
	glutKeyboardFunc(Keyboard);

	// utworzenie podmenu - Filtr pomniejszający
	int MenuMinFilter = glutCreateMenu(Menu);
	glutAddMenuEntry("GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST);
	glutAddMenuEntry("GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR);
	glutAddMenuEntry("GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST);
	glutAddMenuEntry("GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR);

	// utworzenie podmenu - Aspekt obrazu
	int MenuAspect = glutCreateMenu(Menu);
#ifdef WIN32

	glutAddMenuEntry("Aspekt obrazu - całe okno", FULL_WINDOW);
#else

	glutAddMenuEntry("Aspekt obrazu - cale okno", FULL_WINDOW);
#endif

	glutAddMenuEntry("Aspekt obrazu 1:1", ASPECT_1_1);

	// menu główne
	glutCreateMenu(Menu);

#ifdef WIN32

	glutAddSubMenu("Filtr pomniejszający", MenuMinFilter);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);
	glutAddMenuEntry("Wyjście", EXIT);
#else

	glutAddSubMenu("Filtr pomniejszajacy", MenuMinFilter);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);
	glutAddMenuEntry("Wyjscie", EXIT);
#endif

	// określenie przycisku myszki obsługującego menu podręczne
	glutAttachMenu(GLUT_RIGHT_BUTTON);

	// sprawdzenie i przygotowanie obsługi wybranych rozszerzeñ
	ExtensionSetup();

	// utworzenie list wyświetlania
	GenerateDisplayLists();

	// wprowadzenie programu do obsługi pętli komunikatów
	glutMainLoop();
	return 0;
}
Example #17
0
/* Parse arguments, and set up interface between OpenGL and window system */
int
main(int argc, char *argv[])
{
    GLUquadricObj *sphere, *cone, *base;
    GLfloat v0[3], v1[3], v2[3];
    unsigned *floortex;
    int texcomps, texwid, texht;

    glutInit(&argc, argv);
    glutInitWindowSize(512, 512);
    if(argc > 1)
    {
	char *args = argv[1];
	int done = GL_FALSE;
	while(!done)
	{
	    switch(*args)
	    {
	    case 's': /* single buffer */
		printf("Single Buffered\n");
		dblbuf = GL_FALSE;
		break;
	    case '-': /* do nothing */
		break;
	    case 0:
		done = GL_TRUE;
		break;
	    }
	    args++;
	}
    }
    if(dblbuf)
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL|GLUT_DOUBLE);
    else
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);

    (void)glutCreateWindow("projection shadows");
    glutDisplayFunc(redraw);
    glutKeyboardFunc(key);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutReshapeFunc(reshape);

    glutCreateMenu(menu);
    glutAddMenuEntry("No Shadows", NONE);
    glutAddMenuEntry("Black Shadows", SHADOW_BLACK);
    glutAddMenuEntry("Shadows on Texture", SHADOW);
    glutAttachMenu(GLUT_RIGHT_BUTTON);


    /* draw a perspective scene */
    glMatrixMode(GL_PROJECTION);
    glFrustum(-100., 100., -100., 100., 320., 640.); 
    glMatrixMode(GL_MODELVIEW);

    /* turn on features */
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    /* make shadow matricies */

      /* 3 points on floor */
      v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f;
      v1[X] =  100.f; v1[Y] = -100.f; v1[Z] = -320.f;
      v2[X] =  100.f; v2[Y] = -100.f; v2[Z] = -520.f;
      
      findplane(floorplane, v0, v1, v2);
      shadowmatrix(floorshadow, floorplane, lightpos);

      /* 3 points on left wall */
      v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f;
      v1[X] = -100.f; v1[Y] = -100.f; v1[Z] = -520.f;
      v2[X] = -100.f; v2[Y] =  100.f; v2[Z] = -520.f;

      findplane(lwallplane, v0, v1, v2);
      shadowmatrix(leftwallshadow, lwallplane, lightpos);

    /* place light 0 in the right place */
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

    /* remove back faces to speed things up */
    glCullFace(GL_BACK);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    /* make display lists for sphere and cone; for efficiency */

    glNewList(WALLS, GL_COMPILE);
    glColor3f(1.f, 1.f, 1.f);
    glBegin(GL_QUADS);
    /* right wall */
    glNormal3f(-1.f, 0.f, 0.f);
    glVertex3f( 100.f, -100.f, -320.f);
    glVertex3f( 100.f,  100.f, -320.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f( 100.f, -100.f, -520.f);

    /* ceiling */
    glNormal3f(0.f, -1.f, 0.f);
    glVertex3f(-100.f,  100.f, -320.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f( 100.f,  100.f, -320.f);

    /* back wall */
    glNormal3f(0.f, 0.f, 1.f);
    glVertex3f(-100.f, -100.f, -520.f);
    glVertex3f( 100.f, -100.f, -520.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glEnd();
    glEndList();


    glNewList(SPHERE, GL_COMPILE);
    sphere = gluNewQuadric();
    glPushMatrix();
    glTranslatef(60.f, -50.f, -360.f);
    gluSphere(sphere, 20.f, 20, 20);
    gluDeleteQuadric(sphere);
    glPopMatrix();
    glEndList();


    glNewList(LIGHT, GL_COMPILE);
    sphere = gluNewQuadric();
    gluSphere(sphere, 5.f, 20, 20);
    gluDeleteQuadric(sphere);
    glEndList();

    glNewList(CONE, GL_COMPILE);
    cone = gluNewQuadric();
    base = gluNewQuadric();
    glPushMatrix();
    glTranslatef(-40.f, -40.f, -400.f);
    glRotatef(-90.f, 1.f, 0.f, 0.f);
    gluDisk(base, 0., 20., 20, 1);
    gluCylinder(cone, 20., 0., 60., 20, 20);
    gluDeleteQuadric(cone);
    gluDeleteQuadric(base);
    glPopMatrix();
    glEndList();


    glNewList(SHADOWERS, GL_COMPILE);
    glCallList(CONE);
    glCallList(SPHERE);
    glEndList();

    glNewList(FLOOR, GL_COMPILE);
    /* make the floor textured */
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glNormal3f(0.f, 1.f, 0.f);
    glTexCoord2i(0, 0);
    glVertex3f(-100.f, -100.f, -320.f);
    glTexCoord2i(1, 0);
    glVertex3f( 100.f, -100.f, -320.f);
    glTexCoord2i(1, 1);
    glVertex3f( 100.f, -100.f, -520.f);
    glTexCoord2i(0, 1);
    glVertex3f(-100.f, -100.f, -520.f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glEndList();

    glNewList(LEFTWALL, GL_COMPILE);
    glBegin(GL_QUADS);
    /* left wall */
    glNormal3f(1.f, 0.f, 0.f);
    glVertex3f(-100.f, -100.f, -320.f);
    glVertex3f(-100.f, -100.f, -520.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glVertex3f(-100.f,  100.f, -320.f);
    glEnd();
    glEndList();

    floortex = read_texture("../../data/wood0.rgb",
			    &texwid, &texht, &texcomps);

    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA,
		      GL_UNSIGNED_BYTE, floortex);

    free(floortex);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

    glutMainLoop();
    return 0;
}
Example #18
0
void	keyboard(unsigned char ch, int x, int y)
{
	x = ch; y = ch;
	switch (ch)
	{
		case 27:             /* escape */
			running = !running;
			break;
		case 'w':
		case 'W':
			glTranslatef(0,-10, 0);
			glutPostRedisplay();
			break;
		case 's':
		case 'S':
			glTranslatef(0, 10, 0);
			glutPostRedisplay();
			break;
		case 'a':
		case 'A':
			glTranslatef(10, 0,0);
			glutPostRedisplay();
			break;
		case 'd':
		case 'D':
			glTranslatef(-10, 0,0);
			glutPostRedisplay();
			break;
		case 'Q':
		case 'q':
			conf_rotate = (conf_rotate) ? false : true;
			glutPostRedisplay();
			break;
		case 'X':
		case 'x':
			conf_skip_frames = !conf_skip_frames;
			std::cout << "conf_skip_frames = " << conf_skip_frames << std::endl;
			break;
		case '=':
			conf_zoom *= 0.9f;
			std::cout << "conf_zoom = " << conf_zoom << std::endl;
			break ;
		case '-':
			conf_zoom /= 0.9f;
			std::cout << "conf_zoom = " << conf_zoom << std::endl;
			break ;
		case 'r':
		case 'R':
			target_rotate += 45.0f * 2.0f;
			break;
		case 'P':
		case 'p':
			conf_pause = !conf_pause;
			break;
		case ' ':
			pour_water = !pour_water;
			break;
		case '1':
			glutReshapeFunc(reshape_vue_haute);
			glutDisplayFunc(display_vue_haute);
			reshape_vue_haute(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
			glutPostRedisplay();
			break;
		case '2':
			glutReshapeFunc(reshape_iso);
			glutDisplayFunc(display_iso);
			reshape_iso(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
			glutPostRedisplay();
			break;
		case '3':
			glutReshapeFunc(reshape);
			glutDisplayFunc(display);
			reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
			glutPostRedisplay();
			break;
        case 'v':
        case 'V':
            vidange = !vidange;
            break;
		default:
			break;
	}
}
int main(int argc, char** argv)
{
	if (argc != 7) {
        printf("%d", argc);
        for (int i = 0; i < argc; i++) {
            printf("%s\n", argv[i]);
        }
		usage();
    }

	vertexShader   = std::string(argv[1]);
	fragmentShader = std::string(argv[2]);
    meshOBJ        = std::string(argv[3]);
	normalMap      = std::string(argv[4]);
	displacementMap      = std::string(argv[5]);
	colorMap       =std::string(argv[6]);

    //
    // Initialize GLUT.
    //
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowPosition(20, 20);
    glutInitWindowSize(640, 480);
    glutCreateWindow("CS148 Texturing");
    
    //
    // Initialize GLEW.
    //
#ifndef __APPLE__
    glewInit();
    if(!GLEW_VERSION_2_0) {
        printf("Your graphics card or graphics driver does\n"
			   "\tnot support OpenGL 2.0, trying ARB extensions\n");

        if(!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) {
            printf("ARB extensions don't work either.\n");
            printf("\tYou can try updating your graphics drivers.\n"
				   "\tIf that does not work, you will have to find\n");
            printf("\ta machine with a newer graphics card.\n");
            exit(1);
        }
    }
#endif

    // Be sure to initialize GLUT (and GLEW for this assignment) before
    // initializing your application.

    Setup();

    glutDisplayFunc(DisplayCallback);
    glutReshapeFunc(ReshapeCallback);
    glutSpecialFunc(SpecialKeyCallback);
    glutKeyboardFunc(KeyCallback);
    glutMouseFunc(MouseCallback);
    glutMotionFunc(MouseMotionCallback);
    glutIdleFunc(DisplayCallback);

    glutMainLoop();

    // Cleanup code should be called here.
    CleanUp();

    return 0;
}
/* ---------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
	struct aiLogStream stream;

	glutInitWindowSize(900,600);
	glutInitWindowPosition(100,100);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInit(&argc, argv);

	glutCreateWindow("Assimp - Very simple OpenGL sample");
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);

	/* get a handle to the predefined STDOUT log stream and attach
	   it to the logging system. It remains active for all further
	   calls to aiImportFile(Ex) and aiApplyPostProcessing. */
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	aiAttachLogStream(&stream);

	/* ... same procedure, but this stream now writes the
	   log messages to assimp_log.txt */
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	aiAttachLogStream(&stream);

	/* the model name can be specified on the command line. If none
	  is specified, we try to locate one of the more expressive test 
	  models from the repository (/models-nonbsd may be missing in 
	  some distributions so we need a fallback from /models!). */
	if( 0 != loadasset( argc >= 2 ? argv[1] : "../../test/models-nonbsd/X/dwarf.x")) {
		if( argc != 1 || (0 != loadasset( "../../../../test/models-nonbsd/X/dwarf.x") && 0 != loadasset( "../../test/models/X/Testwuson.X"))) { 
			return -1;
		}
	}

	glClearColor(0.1f,0.1f,0.1f,1.f);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);    /* Uses default lighting parameters */

	glEnable(GL_DEPTH_TEST);

	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glEnable(GL_NORMALIZE);

	/* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */
	if(getenv("MODEL_IS_BROKEN"))  
		glFrontFace(GL_CW);

	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

	glutGet(GLUT_ELAPSED_TIME);
	glutMainLoop();

	/* cleanup - calling 'aiReleaseImport' is important, as the library 
	   keeps internal resources until the scene is freed again. Not 
	   doing so can cause severe resource leaking. */
	aiReleaseImport(scene);

	/* We added a log stream to the library, it's our job to disable it
	   again. This will definitely release the last resources allocated
	   by Assimp.*/
	aiDetachAllLogStreams();
	return 0;
}
Example #21
0
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;
}