예제 #1
0
파일: main.c 프로젝트: ExMix/OpenGL_ES
GLUSboolean update(GLUSfloat time)
{
	// Bias needed to convert the from [-1;1] to [0;1]
	GLfloat biasMatrix[16] = {0.5f, 0.0f, 0.0f, 0.0f,
								0.0f, 0.5f, 0.0f, 0.0f,
								0.0f, 0.0f, 0.5f, 0.0f,
								0.5f, 0.5f, 0.5f, 1.0f};
	// Frame buffer has another view port and so perspective projection. Needed for projected texturing of the mirror texture.
	GLfloat viewProjectionBiasTextureMatrix[16];

	// This matrix is used to flip the rendered object upside down.
	GLfloat scaleMatrix[16];

	// Store current width and height for later reseting.
	GLuint width = g_width;
	GLuint height = g_height;

	//
    // Upside down rendering to frame buffer.
	//
    glBindFramebuffer(GL_FRAMEBUFFER, g_fboMirrorTexture);

	reshape(TEXTURE_WIDTH, TEXTURE_HEIGHT);

    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glusMatrix4x4Identityf(scaleMatrix);
    glusMatrix4x4Scalef(scaleMatrix, 1.0f, -1.0f, 1.0f);

    glFrontFace(GL_CW);

    if (!updateWavefront(time, scaleMatrix))
    {
    	return GLUS_FALSE;
    }

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // Save the current projection matrix for later usage.

    glusMatrix4x4Copyf(viewProjectionBiasTextureMatrix, g_viewProjectionMatrix, GLUS_FALSE);

    glusMatrix4x4Multiplyf(viewProjectionBiasTextureMatrix, biasMatrix, viewProjectionBiasTextureMatrix);

    //
    // Scene rendering
    //

    reshape(width, height);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Normal rendering
    glusMatrix4x4Identityf(scaleMatrix);

    glFrontFace(GL_CCW);

    if (!updateWavefront(time, scaleMatrix))
    {
    	return GLUS_FALSE;
    }

    glUseProgram(g_program.program);

    // This matrix is needed to calculate the vertices into the frame buffer render pass.
    glUniformMatrix4fv(g_viewProjectionBiasTextureMatrixLocation, 1, GL_FALSE, viewProjectionBiasTextureMatrix);

    glBindVertexArray(g_vao);

    glDrawElements(GL_TRIANGLES, g_numberIndicesSphere, GL_UNSIGNED_INT, 0);

    return GLUS_TRUE;
}
예제 #2
0
파일: main.c 프로젝트: Adon-m/OpenGL
GLUSboolean update(GLUSfloat time)
{
	GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };

	GLfloat modelMatrix[16];

	GLint i;

	//
	// Rendering scene to frame buffer.
	//

	glBindFramebuffer(GL_FRAMEBUFFER, g_ssaoFBO);
	glDrawBuffers(2, drawBuffers);

	reshape(TEXTURE_WIDTH, TEXTURE_HEIGHT);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	for (i = 0; i < 3; i++)
	{
		glusMatrix4x4Identityf(modelMatrix);
		glusMatrix4x4Translatef(modelMatrix, (GLfloat)(i - 1) * 4.1f, 0.0f, 0.0f);
		glusMatrix4x4RotateRyf(modelMatrix, 45.0f);

		if (!updateWavefront(time, modelMatrix))
		{
			return GLUS_FALSE;
		}
	}

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, g_texture);

	glUseProgram(g_program.program);

	glBindVertexArray(g_vao);

	glDrawElements(GL_TRIANGLES, g_numberIndicesPlane, GL_UNSIGNED_INT, 0);

	//
	// SSAO rendering step.
	//

	glBindFramebuffer(GL_FRAMEBUFFER, g_blurFBO);

	glDrawBuffer(GL_COLOR_ATTACHMENT0);

	glClear(GL_COLOR_BUFFER_BIT);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, g_ssaoTexture);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, g_ssaoNormalTexture);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, g_ssaoDepthTexture);
	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, g_ssaoRotationNoiseTexture);
	glActiveTexture(GL_TEXTURE0);

	glUseProgram(g_ssaoProgram.program);

	glBindVertexArray(g_ssaoVAO);

	glDrawElements(GL_TRIANGLES, g_numberIndicesPostprocessPlane, GL_UNSIGNED_INT, 0);

	glBindTexture(GL_TEXTURE_2D, 0);

	//
	// Blur rendering step.
	//

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	glDrawBuffer(GL_COLOR_ATTACHMENT0);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, g_ssaoTexture);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, g_blurTexture);
	glActiveTexture(GL_TEXTURE0);

	glUseProgram(g_blurProgram.program);

	glBindVertexArray(g_blurVAO);

	glDrawElements(GL_TRIANGLES, g_numberIndicesPostprocessPlane, GL_UNSIGNED_INT, 0);

	glBindTexture(GL_TEXTURE_2D, 0);

	return GLUS_TRUE;
}