void SetupBlurProg(void)
{
	// Set the blur program as the current one
	glUseProgram(blurProg);

	// Set MVP matrix
	glUniformMatrix4fv(glGetUniformLocation(blurProg, "mvpMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());

	// Setup the textue units for the blur targets, these rotate every frame
	glUniform1i(glGetUniformLocation(blurProg, "textureUnit0"), GetBlurTarget0());
	glUniform1i(glGetUniformLocation(blurProg, "textureUnit1"), GetBlurTarget1());
	glUniform1i(glGetUniformLocation(blurProg, "textureUnit2"), GetBlurTarget2());
	glUniform1i(glGetUniformLocation(blurProg, "textureUnit3"), GetBlurTarget3());
	glUniform1i(glGetUniformLocation(blurProg, "textureUnit4"), GetBlurTarget4());
	glUniform1i(glGetUniformLocation(blurProg, "textureUnit5"), GetBlurTarget5());
}
Example #2
0
void render(GLFWwindow* window, double time) {
	static float tx = 0.0f;
	static float dx = 2500.0f;
	if (tx + dx*time > 3.5)
	{
		dx = -2500;
		tx = 3.5 - (tx + dx*time - 3.5);
	}
	if (tx + dx*time < -3.5)
	{
		dx = 2500;
		tx = -3.5 + (tx + dx*time + 3.5);
	}
	tx += time * dx;
	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	glVertexAttribPointer(
		0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
		3,                  // size
		GL_FLOAT,           // type
		GL_FALSE,           // normalized?
		0,                  // stride
		(void*)0            // array buffer offset
		);

	glEnableVertexAttribArray(1);
	glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
	glVertexAttribPointer(
		1,                  // attribute 1. No particular reason for 1, but must match the layout in the shader.
		3,                  // size
		GL_FLOAT,           // type
		GL_FALSE,           // normalized?
		0,                  // stride
		(void*)0            // array buffer offset
		);

	// Draw the triangle !

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(programID);

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	// Camera matrix
	glm::mat4 View = glm::lookAt(
		glm::vec3(4, 3, 3), // Camera is at (4,3,3), in World Space
		glm::vec3(0, 0, 0), // and looks at the origin
		glm::vec3(0, 1, 0)  // Head is up (set to 0,-1,0 to look upside-down)
		);
	// Model matrix : an identity matrix (model will be at the origin)
	glm::mat4 Model = glm::translate(tx, 0.0f, 0.0f);  // Changes for each model !
	// Our ModelViewProjection : multiplication of our 3 matrices
	glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around

	// Get a handle for our "MVP" uniform.
	// Only at initialisation time.
	GLuint MatrixID = glGetUniformLocation(programID, "MVP");

	// Send our transformation to the currently bound shader,
	// in the "MVP" uniform
	// For each model you render, since the MVP will be different (at least the M part)
	glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

	glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // Starting from vertex 0; 3 vertices total -> 1 triangle


	
	int width, height;
	glfwGetWindowSize(window, &width, &height); 


	glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelbuffer);
	glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, NULL);
	glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbuffer);
	glActiveTexture(GL_TEXTURE0 + GetBlurTarget0());
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
	


	glDisable(GL_DEPTH_TEST);

	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, texvertexbuffer);
	glVertexAttribPointer(
		0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
		3,                  // size
		GL_FLOAT,           // type
		GL_FALSE,           // normalized?
		0,                  // stride
		(void*)0            // array buffer offset
		);

	glEnableVertexAttribArray(1);
	glBindBuffer(GL_ARRAY_BUFFER, texcoordbuffer);
	glVertexAttribPointer(
		1,                  // attribute 1. No particular reason for 1, but must match the layout in the shader.
		2,                  // size
		GL_FLOAT,           // type
		GL_FALSE,           // normalized?
		0,                  // stride
		(void*)0            // array buffer offset
		);

	glUseProgram(blurprogramID);
	MVP = glm::mat4();
	glUniformMatrix4fv(glGetUniformLocation(blurprogramID, "MVP"), 1, GL_FALSE, &MVP[0][0]);

	// Setup the textue units for the blur targets, these rotate every frame
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit0"), GetBlurTarget0());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit1"), GetBlurTarget1());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit2"), GetBlurTarget2());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit3"), GetBlurTarget3());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit4"), GetBlurTarget4());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit5"), GetBlurTarget5());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit6"), GetBlurTarget6());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit7"), GetBlurTarget7());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit8"), GetBlurTarget8());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit9"), GetBlurTarget9());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit10"), GetBlurTarget10());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit11"), GetBlurTarget11());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit12"), GetBlurTarget12());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit13"), GetBlurTarget13());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit14"), GetBlurTarget14());
	glUniform1i(glGetUniformLocation(blurprogramID, "textureUnit15"), GetBlurTarget15());

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	AdvanceBlurTaget();

	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
}