コード例 #1
0
ファイル: part1.cpp プロジェクト: krewie/toonshading
// 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();

}
コード例 #2
0
ファイル: part1.cpp プロジェクト: klutt/datorgrafikass1
// MODIFY THIS FUNCTION
void drawMesh(cgtk::GLSLProgram &program, const MeshVAO &meshVAO)
{
    program.enable();
    // al=1;
globals.program.setUniform1f("u_al",al);
globals.program.setUniform1f("u_dl",dl);
globals.program.setUniform1f("u_sl",sl);
globals.program.setUniform1f("u_gamma",gam);
globals.program.setUniform1f("u_invert",inv);
// globals.program.setUniform1f("u_zoom",zoom);


    // Define the model, view, and projection matrices here
    glm::mat4 model = glm::mat4(1.0f);
glm::mat4 view = glm::lookAt(glm::vec3(0.0f,0.0f,6.0f),
    				 glm::vec3(0.0f,1.0f,0.0f),
    				 glm::vec3(0.0f,0.0f,1.0f));
    glm::mat4 projection = glm::perspective(zoom*10.5f,1.0f,3.0f,8.0f);
    // Construct the ModelViewProjection, ModelView, and normal
    // matrices here and pass them as uniform variables to the shader
    // program
	glm::mat4 MV = view*model;
	globals.program.setUniformMatrix4f("u_MV",MV);

	glm::mat4 MVP = projection*view*model;
	globals.program.setUniformMatrix4f("u_MVP",MVP);

    glm::mat4 NM = glm::transpose(glm::inverse(MV));
    globals.program.setUniformMatrix4f("u_NM", NM);
   

    // Set up the light source and material properties and pass them
    // as uniform variables to the shader program, along with the
    // flags (uniform int variables) used for toggling on/off
    // different parts of the rendering
    glm::vec3 LP(0.0,0.0,8.0);
    globals.program.setUniform3f("u_LP", LP);
    glm::vec3 LC(1.0,1.0,1.0);
    globals.program.setUniform3f("u_LC", LC);
    glm::vec3 DC(1.0,1.0,0);
    glm::vec3 AC=glm::vec3(1.0,0,1.0);
    glm::vec3 SC(0,1.0,1.0);
    globals.program.setUniform3f("u_DC", DC);
    globals.program.setUniform3f("u_AC", AC);
    globals.program.setUniform3f("u_SC", SC);
    float SP = 1.0;
//    globals.program.setUniform1f("u_SP", SP);

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

    program.disable();
}
コード例 #3
0
ファイル: part2.cpp プロジェクト: isqb/graphics
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);
}
コード例 #4
0
ファイル: part2.cpp プロジェクト: isqb/graphics
// MODIFY THIS FUNCTION
void drawMesh(cgtk::GLSLProgram &program, const MeshVAO &meshVAO)
{
    program.enable();
    
    // Define the model, view, and projection matrices here
    glm::mat4 model = glm::mat4(1.0f);
    glm::mat4 view = glm::mat4(1.0f);
    glm::mat4 projection = glm::mat4(1.0f);

    // Construct the ModelViewProjection, ModelView, and normal
    // matrices here and pass them (along with the model matrix) as
    // uniform variables to the shader program

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

	if(!globals.ortho_switch) {
		projection = glm::perspective(globals.zoomFactor*45.0f, 1.0f, 0.1f, 100.0f);
	}
	else {
		projection = glm::ortho(globals.zoomFactor*-5.0, globals.zoomFactor*5.0, globals.zoomFactor*-5.0, globals.zoomFactor*5.0, 0.1, 100.0); 
	}

	glm::mat4 trackMatrix = globals.trackball.getRotationMatrix();

	model = trackMatrix;

	glm::mat4 MVPmatrix = projection * view * model;
	glm::mat4 u_mv = view * model;
	globals.program.setUniformMatrix4f("MVPmatrix", glm::mat4(MVPmatrix));
	globals.program.setUniformMatrix4f("u_mv", u_mv);

	globals.program.setUniform3f("light_position",globals.light_position);
	globals.program.setUniform3f("light_color",globals.light_color);
	globals.program.setUniform3f("ambient_color",globals.ambient_color);
	globals.program.setUniform3f("diffuse_color",globals.diffuse_color);
	globals.program.setUniform3f("specular_color",globals.specular_color);
	globals.program.setUniform1f("specular_power",420.0);

	globals.program.setUniform1i("ambient_switch",globals.ambient_switch);
	globals.program.setUniform1i("diffuse_switch",globals.diffuse_switch);
	globals.program.setUniform1i("specular_switch",globals.specular_switch);
	globals.program.setUniform1i("gamma_swtich",globals.gamma_swtich);
	globals.program.setUniform1i("invert_switch",globals.invert_switch);
	globals.program.setUniform1i("normals_switch",globals.normals_switch);
    
	

    // Select the active texture unit and bind the cubemap texture
	
    // Pass the number of the active texture unit as a uniform int
    // variable to the shader program

	// bind mesh and draw
	if (globals.newText != globals.oldText){
		switch (globals.newText){
			
		case 8:
			glActiveTexture(GL_TEXTURE8);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_7);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_7);
			break;

		case 7:
			glActiveTexture(GL_TEXTURE7);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_6);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_6);
			break;

		case 6:
			glActiveTexture(GL_TEXTURE6);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_5);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_5);
			break;

		case 5:
			glActiveTexture(GL_TEXTURE5);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_4);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_4);
			break;

		case 4:
			glActiveTexture(GL_TEXTURE4);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_3);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_3);
			break;

		case 3:
			glActiveTexture(GL_TEXTURE3);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_2);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_2);
			break;
		case 2:
			glActiveTexture(GL_TEXTURE2);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_1);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_1);
			break;
			/* Using TEXTURE1 for sky box
		case 1:
			glActiveTexture(GL_TEXTURE1);
			glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_0);
			globals.program.setUniform1i("u_cubemap", globals.cubemap_0);
			break;*/

		default:
			break;
		}
		globals.oldText = globals.newText;
	}
	glBindVertexArray(meshVAO.vao);
	glDrawElements(GL_TRIANGLES, meshVAO.numIndices, GL_UNSIGNED_INT, 0);
	glBindVertexArray(0);

    
	// Background Colour
	//glClearColor(globals.bg_color[0],globals.bg_color[1],globals.bg_color[2], 1.0);
	

    
	program.disable();
	/**/
#pragma region Draw sky box in DrawMesh
	globals.program_sky_box.enable();
	/**/
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_CUBE_MAP, globals.cubemap_sky_box);

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

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

	globals.program_sky_box.disable();
#pragma endregion
}