Exemplo n.º 1
0
/*!
 Draw the objects
 */
void GLTable::draw(void)
{
    
    //////////////////////////////////////////////////
    // Renders the sphere
    
    // Enable the shader program
    glUseProgram(_program);
    
    // this changes the camera location
    glm::mat4 rotated_view =  rotatedViewMatrix();
    glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, &rotated_view[0][0]); // send the view matrix to our shader
    glUniformMatrix4fv(_inverseViewMatrixLocation, 1, GL_FALSE, &invRotatedViewMatrix()[0][0]);
    glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, &_modelMatrix[0][0]); //
    
    // Bind the buffer and switch it to an active buffer
    glBindVertexArray(_vaoID[0]);
    
   // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // allows to see the primitives
    // Draw the triangles
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 24, 4);
    // Unbind our Vertex Array Object
    glBindVertexArray(0);
    
    // Unbind the shader program
    glUseProgram(0);
    
}
Exemplo n.º 2
0
void GLBeerPint::draw(void)
{
    
    //////////////////////////////////////////////////
    // Renders the sphere
    
    // Enable the shader program
    glUseProgram(_program);
    
    // this changes the camera location
    glm::mat4 rotated_view =  rotatedViewMatrix();
    glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, &rotated_view[0][0]); // send the view matrix to our shader
    glUniformMatrix4fv(_inverseViewMatrixLocation, 1, GL_FALSE, &invRotatedViewMatrix()[0][0]);
    glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, &_modelMatrix[0][0]); //
    
    // Bind the buffer and switch it to an active buffer
    glBindVertexArray(_vaoID[0]);
    
    //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // allows to see the primitives
    // Draw the triangles
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 42);
    //Top of can
    glDrawArrays(GL_TRIANGLE_FAN, 43, _num_vertices);

    //////////////////////////////////////////////////
    // Renders the normal vectors
    
    if(_render_normal_vectors)
    {
        
        // Enable the shader program
        glUseProgram(_program_normals);
        
        glUniformMatrix4fv(_viewMatrixLocationN, 1, GL_FALSE, &rotated_view[0][0]); // send the view matrix to our shader
        glUniformMatrix4fv(_modelMatrixLocationN, 1, GL_FALSE, &_modelMatrix[0][0]); //
        
        
        // Bind the buffer and switch it to an active buffer
        glBindVertexArray(_vaoIDNormals[0]);
        glDrawArrays(GL_LINES, 0, _num_vertices_normals);
    }
    
    // Unbind our Vertex Array Object
    glBindVertexArray(0);
    
    // Unbind the shader program
    glUseProgram(0);
    
    
}
Exemplo n.º 3
0
/*
 Inits the shader program for this object
 */
void GLSphereRed::initShader(void)
{
    
#ifdef _WIN32
    // This loads the shader program from a file
    _program = LoadAndCreateShaderProgram("../data/shaders/redsphere1.vs", "../data/shaders/redsphere1.fs");
#else
    // This loads the shader program from a file
    _program = LoadAndCreateShaderProgram("/Users/geethanjalijeevanatham/Desktop/Helloworld/myopenGL/model/testing/assignment2/Problem2/Problem2/data/shaders/redsphere1.vs", "/Users/geethanjalijeevanatham/Desktop/Helloworld/myopenGL/model/testing/assignment2/Problem2/Problem2/data/shaders/redsphere1.fs");
#endif
    glUseProgram(_program);
    
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Vertex information / names
    
    glBindAttribLocation(_program, 0, "in_Position");
    glBindAttribLocation(_program, 1, "in_Normal");
    glBindAttribLocation(_program, 2, "in_Color");
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Define the model view matrix.
    
    
    _modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f)); // Create our model matrix which will halve the size of our model
    
    
    _projectionMatrixLocation = glGetUniformLocation(_program, "projectionMatrixBox"); // Get the location of our projection matrix in the shader
    _viewMatrixLocation = glGetUniformLocation(_program, "viewMatrixBox"); // Get the location of our view matrix in the shader
    _modelMatrixLocation = glGetUniformLocation(_program, "modelMatrixBox"); // Get the location of our model matrix in the shader
    _inverseViewMatrixLocation = glGetUniformLocation(_program, "inverseViewMatrix");
    
    
    glUniformMatrix4fv(_projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix()[0][0] ); // Send our projection matrix to the shader
    glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, &viewMatrix()[0][0]); // Send our view matrix to the shader
    glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, &_modelMatrix[0][0]); // Send our model matrix to the shader
    glUniformMatrix4fv(_inverseViewMatrixLocation, 1, GL_FALSE, &invRotatedViewMatrix()[0][0]);
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Material
    _material._diffuse_material = glm::vec3(1.0, 0.0, 0.0);
    _material._ambient_material = glm::vec3(1.0, 0.0, 0.0);
    _material._specular_material = glm::vec3(1.0, 1.0, 1.0);
    _material._shininess = 150.0;
    
    
    _material._ambientColorPos = glGetUniformLocation(_program, "ambient_color");
    _material._diffuseColorPos = glGetUniformLocation(_program, "diffuse_color");
    _material._specularColorPos = glGetUniformLocation(_program, "specular_color");
    _material._shininessIdx = glGetUniformLocation(_program, "shininess");
    
    
    // Send the material to your shader program
    glUniform3fv(_material._ambientColorPos, 1, &_material._ambient_material[0] );
    glUniform3fv(_material._diffuseColorPos, 1, &_material._diffuse_material[0]);
    glUniform3fv(_material._specularColorPos, 1, &_material._specular_material[0]);
    glUniform1f(_material._shininessIdx, _material._shininess);
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Light
    
    // define the position of the light and send the light position to your shader program
    _light_source1._lightPos = glm::vec4(2.0,0.0,2.0,0.0);
    _light_source1._ambient_intensity = 0.0;
    _light_source1._specular_intensity = 1.0;
    _light_source1._diffuse_intensity = 1.0;
    _light_source1._attenuation_coeff = 0.02;
    
    
    
    // Read all the index values from the shader program
    _light_source1._ambientIdx = glGetUniformLocation(_program, "ambient_intensity");
    _light_source1._diffuseIdx = glGetUniformLocation(_program, "diffuse_intensity");
    _light_source1._specularIdx = glGetUniformLocation(_program, "specular_intensity");
    _light_source1._attenuation_coeffIdx = glGetUniformLocation(_program, "attenuationCoefficient");
    _light_source1._lightPosIdx = glGetUniformLocation(_program, "light_position");
    
    
    // Send the light information to your shader program
    glUniform1f(_light_source1._ambientIdx, _light_source1._ambient_intensity );
    glUniform1f(_light_source1._diffuseIdx, _light_source1._diffuse_intensity);
    glUniform1f(_light_source1._specularIdx, _light_source1._specular_intensity);
    glUniform1f(_light_source1._attenuation_coeffIdx, _light_source1._attenuation_coeff);
    glUniform4fv(_light_source1._lightPosIdx, 1, &_light_source1._lightPos[0]);
    
    
    
    
    glUseProgram(0);
    
    
}
Exemplo n.º 4
0
/*
 Inits the shader program for this object
 */
void GLSphere::initShader(void)
{
    
    // Vertex shader source code. This draws the vertices in our window. We have 3 vertices since we're drawing an triangle.
    // Each vertex is represented by a vector of size 4 (x, y, z, w) coordinates.
    // static const string vertex_code = vs_string_CoordSystem;
    static const char * vs_source = vs_string_GLSphere_410.c_str();
    
    // Fragment shader source code. This determines the colors in the fragment generated in the shader pipeline. In this case, it colors the inside of our triangle specified by our vertex shader.
    // static const string fragment_code = fs_string_CoordSystem;
    static const char * fs_source = fs_string_GLSphere_410.c_str();
    
    // This next section we'll generate the OpenGL program and attach the shaders to it so that we can render our triangle.
    _program = glCreateProgram();
    
    // We create a shader with our fragment shader source code and compile it.
    GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fs, 1, &fs_source, NULL);
    glCompileShader(fs);
    CheckShader(fs, GL_FRAGMENT_SHADER);
    
    // We create a shader with our vertex shader source code and compile it.
    GLuint vs = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vs, 1, &vs_source, NULL);
    glCompileShader(vs);
    CheckShader(vs, GL_VERTEX_SHADER);
    
    // We'll attach our two compiled shaders to the OpenGL program.
    glAttachShader(_program, vs);
    glAttachShader(_program, fs);
    
    glLinkProgram(_program);
    
    glUseProgram(_program);
    
    
    _modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f)); // Create our model matrix which will halve the size of our model
    
    
    int projectionMatrixLocation = glGetUniformLocation(_program, "projectionMatrixBox"); // Get the location of our projection matrix in the shader
    _viewMatrixLocation = glGetUniformLocation(_program, "viewMatrixBox"); // Get the location of our view matrix in the shader
    _modelMatrixLocation = glGetUniformLocation(_program, "modelMatrixBox"); // Get the location of our model matrix in the shader
    _inverseViewMatrixLocation = glGetUniformLocation(_program, "inverseViewMatrix");
    
    _light_source0._lightPosIdx = glGetUniformLocation(_program, "light_position");
    
    
    glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix()[0][0] ); // Send our projection matrix to the shader
    glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, &viewMatrix()[0][0]); // Send our view matrix to the shader
    glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, &_modelMatrix[0][0]); // Send our model matrix to the shader
     glUniformMatrix4fv(_inverseViewMatrixLocation, 1, GL_FALSE, &invRotatedViewMatrix()[0][0]);
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Material
    _material._diffuse_material = glm::vec3(1.0, 0.5, 0.0);
    _material._ambient_material = glm::vec3(1.0, 0.5, 0.0);
    _material._specular_material = glm::vec3(1.0, 1.0, 1.0);
    _material._shininess = 12.0;
    
    
    _material._ambientColorPos = glGetUniformLocation(_program, "ambient_color");
    _material._diffuseColorPos = glGetUniformLocation(_program, "diffuse_color");
    _material._specularColorPos = glGetUniformLocation(_program, "specular_color");
    _material._shininessIdx = glGetUniformLocation(_program, "shininess");
    
    
    // Send the material to your shader program
    glUniform3fv(_material._ambientColorPos, 1, &_material._ambient_material[0] );
    glUniform3fv(_material._diffuseColorPos, 1, &_material._diffuse_material[0]);
    glUniform3fv(_material._specularColorPos, 1, &_material._specular_material[0]);
    glUniform1f(_material._shininessIdx, _material._shininess);
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Light
    
    // define the position of the light and send the light position to your shader program
    _light_source0._lightPos = glm::vec4(50.0,50.0,0.0,1.0);
    _light_source0._ambient_intensity = 0.5;
    _light_source0._specular_intensity = 1.0;
    _light_source0._diffuse_intensity = 1.0;
 
    

    _light_source0._ambientIdx = glGetUniformLocation(_program, "ambient_intensity");
    _light_source0._diffuseIdx = glGetUniformLocation(_program, "diffuse_intensity");
    _light_source0._specularIdx = glGetUniformLocation(_program, "specular_intensity");
   
    

    // Send the light information to your shader program
    glUniform1f(_light_source0._ambientIdx, _light_source0._ambient_intensity );
    glUniform1f(_light_source0._diffuseIdx, _light_source0._diffuse_intensity);
    glUniform1f(_light_source0._specularIdx, _light_source0._specular_intensity);
    
    glUniform4fv(_light_source0._lightPosIdx, 1, &_light_source0._lightPos[0]);
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // Vertex information / names
    // bind the to the shader program
    glBindAttribLocation(_program, 0, "in_Position");
    glBindAttribLocation(_program, 1, "in_Normal");
    glBindAttribLocation(_program, 2, "in_Color");
    
    
    
     glUseProgram(0);
    
}
Exemplo n.º 5
0
/*
Inits the shader program for this object
*/
void GLSphereDiffHigh::initShader(void)
{
#ifdef _WIN32
	// This loads the shader program from a file
	_program = LoadAndCreateShaderProgram("../data/shaders/HW3_p2.vs", "../data/shaders/HW3_p2.fs");
#else
	// This loads the shader program from a file
	_program = LoadAndCreateShaderProgram("../data/shaders/HW3_p2.vs", "../data/shaders/HW3_p2.fs");
#endif

	glUseProgram(_program);


	///////////////////////////////////////////////////////////////////////////////////////////////
	// Vertex information / names

	glBindAttribLocation(_program, 0, "in_Position");
	glBindAttribLocation(_program, 1, "in_Normal");
	glBindAttribLocation(_program, 2, "in_Color");


	///////////////////////////////////////////////////////////////////////////////////////////////
	// Define the model view matrix. 


	_modelMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f)); // Create our model matrix which will halve the size of our model


	_projectionMatrixLocation = glGetUniformLocation(_program, "projectionMatrixBox"); // Get the location of our projection matrix in the shader
	_viewMatrixLocation = glGetUniformLocation(_program, "viewMatrixBox"); // Get the location of our view matrix in the shader
	_modelMatrixLocation = glGetUniformLocation(_program, "modelMatrixBox"); // Get the location of our model matrix in the shader
	_inverseViewMatrixLocation = glGetUniformLocation(_program, "inverseViewMatrix");


	glUniformMatrix4fv(_projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix()[0][0]); // Send our projection matrix to the shader
	glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, &viewMatrix()[0][0]); // Send our view matrix to the shader
	glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, &_modelMatrix[0][0]); // Send our model matrix to the shader
	glUniformMatrix4fv(_inverseViewMatrixLocation, 1, GL_FALSE, &invRotatedViewMatrix()[0][0]);

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Material
	_material1._diffuse_material = glm::vec3(1.0, 0.0, 0.0);
	_material1._ambient_material = glm::vec3(1.0, 0.0, 0.0);
	_material1._specular_material = glm::vec3(1.0, 1.0, 1.0);
	_material1._shininess = 12.0;


	_material1._ambientColorPos = glGetUniformLocation(_program, "ambient_color");
	_material1._diffuseColorPos = glGetUniformLocation(_program, "diffuse_color");
	_material1._specularColorPos = glGetUniformLocation(_program, "specular_color");
	_material1._shininessIdx = glGetUniformLocation(_program, "shininess");


	// Send the material to your shader program
	glUniform3fv(_material1._ambientColorPos, 1, &_material1._ambient_material[0]);
	glUniform3fv(_material1._diffuseColorPos, 1, &_material1._diffuse_material[0]);
	glUniform3fv(_material1._specularColorPos, 1, &_material1._specular_material[0]);
	glUniform1f(_material1._shininessIdx, _material1._shininess);

	// material 2
	
	_material2._diffuse_material = glm::vec3(1.0, 1.0, 1.0);
	_material2._ambient_material = glm::vec3(1.0, 1.0, 1.0);
	_material2._specular_material = glm::vec3(1.0, 1.0, 1.0);
	_material2._shininess = 12.0;


	_material2._ambientColorPos = glGetUniformLocation(_program, "ambient_color1");
	_material2._diffuseColorPos = glGetUniformLocation(_program, "diffuse_color1");
	_material2._specularColorPos = glGetUniformLocation(_program, "specular_color1");
	_material2._shininessIdx = glGetUniformLocation(_program, "shininess1");


	// Send the material to your shader program
	glUniform3fv(_material2._ambientColorPos, 1, &_material2._ambient_material[0]);
	glUniform3fv(_material2._diffuseColorPos, 1, &_material2._diffuse_material[0]);
	glUniform3fv(_material2._specularColorPos, 1, &_material2._specular_material[0]);
	glUniform1f(_material2._shininessIdx, _material2._shininess);
	

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Light

	// define the position of the light and send the light position to your shader program
	_light_source1._lightPos = glm::vec4(0.0, 0.0, 30.0, 0.0);
	_light_source1._ambient_intensity = 0.0;
	_light_source1._specular_intensity = 0.0;
	_light_source1._diffuse_intensity = 20.0;
	_light_source1._attenuation_coeff = 0.01;

	_light_source1._cone_angle = 90.0; // in degree
	_light_source1._cone_direction = glm::vec3(0.0, -1.0, -1.0); // this must be aligned with the object and light position.


																 // Read all the index values from the shader program
	_light_source1._ambientIdx = glGetUniformLocation(_program, "ambient_intensity");
	_light_source1._diffuseIdx = glGetUniformLocation(_program, "diffuse_intensity");
	_light_source1._specularIdx = glGetUniformLocation(_program, "specular_intensity");
	_light_source1._attenuation_coeffIdx = glGetUniformLocation(_program, "attenuationCoefficient");
	_light_source1._lightPosIdx = glGetUniformLocation(_program, "light_position");
	_light_source1._cone_angleIdx = glGetUniformLocation(_program, "cone_angle");
	_light_source1._cone_directionIdx = glGetUniformLocation(_program, "cone_direction");

	// Send the light information to your shader program
	glUniform1f(_light_source1._ambientIdx, _light_source1._ambient_intensity);
	glUniform1f(_light_source1._diffuseIdx, _light_source1._diffuse_intensity);
	glUniform1f(_light_source1._specularIdx, _light_source1._specular_intensity);
	glUniform1f(_light_source1._attenuation_coeffIdx, _light_source1._attenuation_coeff);
	glUniform4fv(_light_source1._lightPosIdx, 1, &_light_source1._lightPos[0]);

	glUniform1f(_light_source1._cone_angleIdx, _light_source1._cone_angle);
	glUniform3fv(_light_source1._cone_directionIdx, 1, &_light_source1._cone_direction[0]);
	
	
	// light2
	
	_light_source2._lightPos = glm::vec4(0.0,0.0, 11.1, 0.0);
	_light_source2._ambient_intensity = 0.0;
	_light_source2._specular_intensity = 100.0;
	_light_source2._diffuse_intensity = 20.0;
	_light_source2._attenuation_coeff = 0.2;

	_light_source2._cone_angle = 90.0; // in degree
	_light_source2._cone_direction = glm::vec3(0.0, -1.0, -1.0); // this must be aligned with the object and light position.

																 //     Read all the index values from the shader program
	_light_source2._ambientIdx = glGetUniformLocation(_program, "ambient_intensity1");
	_light_source2._diffuseIdx = glGetUniformLocation(_program, "diffuse_intensity1");
	_light_source2._specularIdx = glGetUniformLocation(_program, "specular_intensity1");
	_light_source2._attenuation_coeffIdx = glGetUniformLocation(_program, "attenuationCoefficient1");
	_light_source2._lightPosIdx = glGetUniformLocation(_program, "light_position1");
	_light_source2._cone_angleIdx = glGetUniformLocation(_program, "cone_angle1");
	_light_source2._cone_directionIdx = glGetUniformLocation(_program, "cone_direction1");

	// Send the light information to your shader program
	glUniform1f(_light_source2._ambientIdx, _light_source2._ambient_intensity);
	glUniform1f(_light_source2._diffuseIdx, _light_source2._diffuse_intensity);
	glUniform1f(_light_source2._specularIdx, _light_source2._specular_intensity);
	glUniform1f(_light_source2._attenuation_coeffIdx, _light_source2._attenuation_coeff);
	glUniform4fv(_light_source2._lightPosIdx, 1, &_light_source2._lightPos[0]);

	glUniform1f(_light_source2._cone_angleIdx, _light_source2._cone_angle);
	glUniform3fv(_light_source2._cone_directionIdx, 1, &_light_source2._cone_direction[0]);
	

	glUseProgram(0);

}