Ejemplo n.º 1
0
	//functia de afisare (lucram cu banda grafica)
	void notifyDisplayFrame() {
		// Deseneaza doar daca s-a modificat pozitia camerei sau perspectiva (a fost apasata o tasta).
		if (modified) {
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			// Foloseste shaderul.
			glUseProgram(gl_program_shader);

			// Trimite variabile uniforme la shader.
			glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "projection_matrix"), 1, false, glm::value_ptr(projection_matrix));
			glUniform1i(glGetUniformLocation(gl_program_shader, "tps_color"), 0);
			glUniform3f(glGetUniformLocation(gl_program_shader, "light_position"),
				view1->getPosition().x, view1->getPosition().y, view1->getPosition().z);
			glUniform3f(glGetUniformLocation(gl_program_shader, "eye_position"),
				view1->getPosition().x, view1->getPosition().y, view1->getPosition().z);
			glUniform3f(glGetUniformLocation(gl_program_shader, "light_direction"),
				view1->getForward().x, view1->getForward().y, view1->getForward().z);
			glUniform1i(glGetUniformLocation(gl_program_shader, "material_shininess"), material_shininess);

			if (is_fps)
				vehicle->drawGeometry(gl_program_shader, textures.size());

			view_matrix = is_fps ? view1->getViewMatrix() : view2->getViewMatrix();
			glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "view_matrix"), 1, false, glm::value_ptr(view_matrix));
			glUniform1f(glGetUniformLocation(gl_program_shader, "material_kd"), is_fps ? material_kd : 0);
			glUniform1f(glGetUniformLocation(gl_program_shader, "material_ks"), is_fps ? material_ks : 0);

			std::vector<glm::vec4> plane_coefs;
			glm::mat4 pv = projection_matrix * view1->getViewMatrix();

			// Calculeaza coeficientii ecuatiilor pentru planurile frustumului.
			plane_coefs.push_back(glm::vec4(pv[0][3] + pv[0][0], pv[1][3] + pv[1][0], pv[2][3] + pv[2][0], pv[3][3] + pv[3][0])); // left
			plane_coefs.push_back(glm::vec4(pv[0][3] - pv[0][0], pv[1][3] - pv[1][0], pv[2][3] - pv[2][0], pv[3][3] - pv[3][0])); // right
			plane_coefs.push_back(glm::vec4(pv[0][3] + pv[0][1], pv[1][3] + pv[1][1], pv[2][3] + pv[2][1], pv[3][3] + pv[3][1])); // bottom
			plane_coefs.push_back(glm::vec4(pv[0][3] - pv[0][1], pv[1][3] - pv[1][1], pv[2][3] - pv[2][1], pv[3][3] - pv[3][1])); // top
			plane_coefs.push_back(glm::vec4(pv[0][3] + pv[0][2], pv[1][3] + pv[1][2], pv[2][3] + pv[2][2], pv[3][3] + pv[3][2])); // near
			plane_coefs.push_back(glm::vec4(pv[0][3] - pv[0][2], pv[1][3] - pv[1][2], pv[2][3] - pv[2][2], pv[3][3] - pv[3][2])); // far

			quad->drawGeometry(gl_program_shader, is_fps, plane_coefs);
			city->draw(gl_program_shader, is_fps, plane_coefs);
			modified = false;
		}
	}
Ejemplo n.º 2
0
	//functia de afisare (lucram cu banda grafica)
	void notifyDisplayFrame(){
		//bufferele din framebuffer sunt aduse la valorile initiale (setate de clear color si cleardepth)
		//adica se sterge ecranul si se pune culoare (si alte propietati) initiala
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//foloseste shaderul
		glUseProgram(gl_program_shader_gouraud);
				
		//trimite variabile uniforme la shader
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(model_matrix));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "view_matrix"),1,false,glm::value_ptr(view_matrix));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "projection_matrix"),1,false,glm::value_ptr(projection_matrix));
		glUniform3f(glGetUniformLocation(gl_program_shader_gouraud, "light_position"),light_position.x, light_position.y, light_position.z);
		glUniform3f(glGetUniformLocation(gl_program_shader_gouraud, "eye_position"),eye_position.x, eye_position.y, eye_position.z);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "material_shininess"),material_shininess);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "material_kd"),material_kd);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "material_ks"),material_ks);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "timp"), timp);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "amplitudine"), amplitudine);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "faza"), faza);
		glUniform1f(glGetUniformLocation(gl_program_shader_gouraud, "frecventa"), frecventa);
		glUniform2f(glGetUniformLocation(gl_program_shader_gouraud, "directie"), directie.x,directie.z);
		glUniform2f(glGetUniformLocation(gl_program_shader_gouraud, "centru"), centru.x, centru.z);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "directional"), directional);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "circular"), circular);
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "toDraw"), drawable);
		//pune si un sol
		//matrice_translatie = glm::translate(model_matrix, glm::vec3(0,0,0));
		//glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(matrice_translatie));

		glBindVertexArray(mesh_vao_ground);
		glDrawElements(GL_TRIANGLES, indecsi, GL_UNSIGNED_INT, 0);
		drawable = 1;
		glUniform1i(glGetUniformLocation(gl_program_shader_gouraud, "toDraw"), drawable);
		//pune o sfera la pozitia luminii
		glm::mat4 matrice_translatie = glm::translate(model_matrix, glm::vec3(light_position.x,light_position.y,light_position.z));
		glm::mat4 matrice_scalare = glm::scale(model_matrix, glm::vec3(0.1,0.1,0.1));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(matrice_translatie * matrice_scalare));
		
		glBindVertexArray(mesh_vao_sphere);
		glDrawElements(GL_TRIANGLES, mesh_num_indices_sphere, GL_UNSIGNED_INT, 0);
		drawable = 0;
		// camera
		view_matrix = FPS.getViewMatrix();

		
	}
Ejemplo n.º 3
0
	//functia de afisare (lucram cu banda grafica)
	void notifyDisplayFrame(){

		//bufferele din framebuffer sunt aduse la valorile initiale (setate de clear color si cleardepth)
		//adica se sterge ecranul si se pune culoare (si alte propietati) initiala
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		//foloseste shaderul
		glUseProgram(lab::gl_program_shader_gouraud);
				
		//trimite variabile uniforme la shader
		view_matrix = camera.getViewMatrix();

		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "model_matrix"),1,false,glm::value_ptr(model_matrix));
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "view_matrix"), 1, false, glm::value_ptr(view_matrix));
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "projection_matrix"), 1, false, glm::value_ptr(projection_matrix));
		glUniform3f(glGetUniformLocation(lab::gl_program_shader_gouraud, "light_position"), light_position.x, light_position.y, light_position.z);
		glUniform3f(glGetUniformLocation(lab::gl_program_shader_gouraud, "eye_position"), eye_position.x, eye_position.y, eye_position.z);
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "material_shininess"), material_shininess);
		glUniform1f(glGetUniformLocation(lab::gl_program_shader_gouraud, "material_kd"), material_kd);
		glUniform1f(glGetUniformLocation(lab::gl_program_shader_gouraud, "material_ks"), material_ks);
		glUniform1fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "amplitudine"), 3, &amplitudine[0]);
		glUniform1fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "frecventa"), 3,  &frecv[0]);
		glUniform1fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "faza"), 3,  &faza[0]);
		glUniform2fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "centru"), 2, &centru[0]);
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "timp"), timp/10);
		timp++;
	
		//pune o sfera la pozitia luminii
		flag = 0;
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "flag"), flag);
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "model_matrix"), 1, false, glm::value_ptr(matrice_translatie_1));
		lab::setColorObject(1, 1, 0, 0);
		glBindVertexArray(mesh_vao_sphere);
		glDrawElements(GL_TRIANGLES, mesh_num_indices_sphere, GL_UNSIGNED_INT, 0);

		//pune si un sol
		flag = 1;
		glUniform1i(glGetUniformLocation(lab::gl_program_shader_gouraud, "flag"), flag);
		matrice_translatie_2 = glm::translate(model_matrix, glm::vec3(-500, -200, -800));
		glUniformMatrix4fv(glGetUniformLocation(lab::gl_program_shader_gouraud, "model_matrix"), 1, false, glm::value_ptr(matrice_translatie_2));
		
		ground->setColor(0, 0.2, 1);
		lab::drawMesh(ground, 0);
	}
Ejemplo n.º 4
0
	void camera_1(Object* obj){
		glViewport(0, 0, screen_width, screen_height);



		//foloseste shaderul
		glUseProgram(gl_program_shader);

		//trimite variabile uniforme la shader
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "model_matrix"), 1, false, glm::value_ptr(obj->model_matrix));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "view_matrix"), 1, false, glm::value_ptr(cam1.getViewMatrix()));
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "projection_matrix"), 1, false, glm::value_ptr(projection_matrix));

		//bind obiect
		glBindVertexArray(obj->mesh_vao);
		glDrawElements(GL_TRIANGLES, obj->mesh_num_indices, GL_UNSIGNED_INT, 0);

		//deseneaza axe camera
		glUniformMatrix4fv(glGetUniformLocation(gl_program_shader, "model_matrix"), 1, false, glm::value_ptr(glm::mat4()));	//identity
		cam1.drawGeometry();
	}