Example #1
0
// MODIFY THIS FUNCTION
void drawMesh(cgtk::GLSLProgram &program, const MeshVAO &meshVAO)
{

    glm::mat4 model = globals.trackball.getRotationMatrix() * glm::mat4(1.0f);
    glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 1.5f), glm::vec3(0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
    glm::mat4 projection = glm::perspective(90.0f+globals.zoomfactor, (float) globals.width/globals.height, 0.1f, 100.0f);

    glm::mat4 mvp = projection * view * model;
    glm::mat4 mv = view * model;


    program.enable();

    program.setUniformMatrix4f("mvp", mvp);
    program.setUniformMatrix4f("view", view);
    program.setUniformMatrix4f("model", model);
    program.setUniform3f("lightDir", globals.lightDir);
    program.setUniform3f("eye_position", glm::vec3(0.0f, 0.0f, 1.5f));
    program.setUniform1f("material_kd", globals.material_kd);
    program.setUniform1f("outline_intensity", globals.outline_intensity);

    program.setUniform3f("diffuseColor", globals.diffuseColor);
    program.setUniform3f("ambientColor", globals.ambientColor);
    program.setUniform3f("outlineColor", globals.outlineColor);

    program.setUniform1i("colorlvl", globals.colorlvl);


    glBindVertexArray(meshVAO.vao);
    glDrawElements(GL_TRIANGLES, meshVAO.numIndices, GL_UNSIGNED_INT, 0);
    glBindVertexArray(0);

    program.disable();

}
Example #2
0
void drawSkyBox(cgtk::GLSLProgram &program){

	glDepthMask(GL_FALSE);
	
	// Bind Skybox and DrawCa
	program.enable(); // glUseProgram()

	// Pass uniforms ///////////// 
	glm::mat4 model = glm::mat4(1.0f);
	glm::mat4 trackMatrix = globals.trackball.getRotationMatrix();
	model = trackMatrix;
	glm::mat4 view = glm::mat4(1.0f);
	glm::mat4 projection = glm::mat4(1.0f);
	projection = projection = glm::perspective(globals.zoomFactor*45.0f,
		1.0f, 0.1f, 100.0f);

	view = glm::lookAt(glm::vec3(0.0f, 0.01f, 5.0f), glm::vec3(0),
		glm::vec3(0.0f, 1.0f, 0.0f));

	glm::mat4 MVPmatrix = projection * view * model;
	glm::mat4 u_mv = view * model;

	program.setUniformMatrix4f("u_projection", glm::mat4(projection));
	program.setUniformMatrix4f("u_view", glm::mat4(view));
	program.setUniform1i("u_cubemap", globals.cubemap_sky_box);

	program.setUniformMatrix4f("u_mvp", glm::mat4(MVPmatrix));

	//////////////////////////////

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_sky_box);

	glBindVertexArray(globals.skyboxVAO);
	//glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); // not sure about 36
	glDrawArrays(GL_TRIANGLES, 0, 108);
	glBindVertexArray(0);


	program.disable();
	glDepthMask(GL_TRUE);
}