Example #1
0
//##############################################################################################
//Load the shader programs, vertex data from model files, create the solids, set initial view
void init(void) {

    //Local Variables
    float modelBoundingRadius[NUM_MODELS];  //Model's bounding radius
    glm::vec3 scale[NUM_MODELS];  //Temporarily holds scales of models

    // load the shader programs
    shaderProgram = loadShaders(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
    glUseProgram(shaderProgram);


    // generate VAOs and VBOs
    glGenVertexArrays(NUM_MODELS, VAO);
    glGenBuffers(NUM_MODELS, buffer);


    /*Note: The for loop below is what binds our models to be used with the GL library.
    The function loadModelBuffer is provided by Prof. Barnes and is located in the iclude465.hpp .
    This call needs to be done after the generation of VAOs and VBOs*/

    /*Load Buffer and get the models scale values*/
    for (int i = 0; i < NUM_MODELS; i++) {
        //Load the buffers from the model files
        modelBoundingRadius[i] = loadModelBuffer(modelPointer[i]->getFileName(),
                                                 modelPointer[i]->getVertexCount(),
                                                 VAO[i], buffer[i], shaderProgram,
                                                 vPosition[i], vColor[i], vNormal[i],
                                                 "vPosition", "vColor", "vNormal");

        //Set scale for models given bounding radius
        /*Notes: AC3D's sizeTo function sets the diameters, not the radius.  The function
        above, provided by the professor, returns a value equal to the models radius
        according to as it is drawn.*/
        scale[i] = glm::vec3(modelPointer[i]->getModelSize() * 1.0f / modelBoundingRadius[i]);

        //Now that we have the scale, update the scale matrix in each of the objects
        modelPointer[i]->setScaleMatrix(glm::scale(glm::mat4(), glm::vec3(scale[i])));
    }


    MVP = glGetUniformLocation(shaderProgram, "ModelViewProjection");


    // set render state values
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.7f, 0.7f, 0.7f, 1.0f);

    //Get initial time reading for statistical reporting
    lastTime = glutGet(GLUT_ELAPSED_TIME);
}
void init (void) 
{
	shaderProgram = loadShaders(vertexShaderFile,fragmentShaderFile);
	glUseProgram(shaderProgram);
  
	// generate VAOs and VBOs
	glGenVertexArrays( nShapes, vao );
	glGenBuffers( nShapes, buffer );



	// load the buffers from the model files
	for (int i = 0; i < nShapes; i++) 
	{
		boundingRadius[i] = loadModelBuffer(modelFile[i], nVertices[i], vao[i], buffer[i], 
							shaderProgram, Position[i], Color[i], Normal[i], "vPosition", "vColor", "vNormal"); 
		scale[i] = glm::vec3( modelSize[i] * 1.0f  /boundingRadius[i]);		// set scale for models given bounding radius  
	}
    
	MVP = glGetUniformLocation(shaderProgram, "ModelViewProjection");

	// inital view
	eye = glm::vec3(0.0f, 30000.0f, 20000.0f);
	at = glm::vec3(0);
	up = glm::vec3(0.0f, 1.0f, 0.0f);
	
	viewMatrix = glm::lookAt(eye, at, up);
  
	// set render state values
	glEnable(GL_DEPTH_TEST);
	glClearColor(0.02f, 0.02f, 0.025f, 1.0f); //RGBA

	// create shape
	for(int i = 0; i < nShapes; i++)
	{
		shape[i] = new Shape3D(i);
		shape[i]->setScale(scale[i]);
	}

	printf("%d Shapes created \n", nShapes);

	lastTime = glutGet(GLUT_ELAPSED_TIME); /////////////////////////////////////
}
Example #3
0
//	INITIALIZE GL FUNCTIONS
void init(void) {
	
	shaderProgram = loadShaders(vertexShaderFile, fragmentShaderFile);
	glUseProgram(shaderProgram);

	glGenVertexArrays(nModels, vao);
	glGenBuffers(nModels, buffer);

	// Load Models
	int mIndex = 0;
	ruber->boundingRadius = loadModelBuffer(ruber->modelFile, ruber->nVertices,
		vao[mIndex], buffer[mIndex], shaderProgram, vPosition[mIndex], vColor[mIndex], vNormal[mIndex],
		"vPosition", "vColor", "vNormal");
	printf("Loaded Model: %s with %7.2f bounding radius \n", ruber->modelFile, ruber->boundingRadius);

	mIndex++;
	unum->boundingRadius = loadModelBuffer(unum->modelFile, unum->nVertices,
		vao[mIndex], buffer[mIndex], shaderProgram, vPosition[mIndex], vColor[mIndex], vNormal[mIndex],
		"vPosition", "vColor", "vNormal");
	printf("Loaded Model: %s with %7.2f bounding radius \n", unum->modelFile, unum->boundingRadius);

	mIndex++;
	duo->boundingRadius = loadModelBuffer(duo->modelFile, duo->nVertices,
		vao[mIndex], buffer[mIndex], shaderProgram, vPosition[mIndex], vColor[mIndex], vNormal[mIndex],
		"vPosition", "vColor", "vNormal");
	printf("Loaded Model: %s with %7.2f bounding radius \n", duo->modelFile, duo->boundingRadius);

	mIndex++;
	primus->boundingRadius = loadModelBuffer(primus->modelFile, primus->nVertices,
		vao[mIndex], buffer[mIndex], shaderProgram, vPosition[mIndex], vColor[mIndex], vNormal[mIndex],
		"vPosition", "vColor", "vNormal");
	printf("Loaded Model: %s with %7.2f bounding radius \n", primus->modelFile, primus->boundingRadius);

	mIndex++;
	secundus->boundingRadius = loadModelBuffer(secundus->modelFile, secundus->nVertices,
		vao[mIndex], buffer[mIndex], shaderProgram, vPosition[mIndex], vColor[mIndex], vNormal[mIndex],
		"vPosition", "vColor", "vNormal");
	printf("Loaded Model: %s with %7.2f bounding radius \n", secundus->modelFile, secundus->boundingRadius);

	mIndex++;
	warbird->boundingRadius = loadModelBuffer(warbird->modelFile, warbird->nVertices,
		vao[mIndex], buffer[mIndex], shaderProgram, vPosition[mIndex], vColor[mIndex], vNormal[mIndex],
		"vPosition", "vColor", "vNormal");
	printf("Loaded Model: %s with %7.2f bounding radius \n", warbird->modelFile, warbird->boundingRadius);

	MVP = glGetUniformLocation(shaderProgram, "ModelViewProjection");

	warbird->setLocation(5000.0f, 1000.0f, 5000.0f);

	printf("eyeDistance = %3.3f\n", eyeDistance);
	
	eye = glm::vec3(0.0f, eyeDistance, eyeDistance);
	at	= glm::vec3(0.0f, 0.0f, 0.0f);
	up	= glm::vec3(0.0f, 1.0f, 0.0f);
	
	glEnable(GL_DEPTH_TEST);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	
	lastTime = glutGet(GLUT_ELAPSED_TIME);
	
}