// called to draw dancing objects
static void DrawSongAndDance(GLfloat yRot)
{
	static GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	static GLfloat vLightPos[] = { 0.0f, 3.0f, 0.0f, 1.0f };

	// get the light position in eye space
	M3DMatrix44f mCamera;
	modelViewMatrix.GetMatrix(mCamera);
	M3DVector4f vLightTransformed;
	m3dTransformVector4(vLightTransformed, vLightPos, mCamera);

	// draw the light source
	modelViewMatrix.push();
	modelViewMatrix.moveTo(vLightPos);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(),
								vWhite);
	sphereBatch.draw();

	modelViewMatrix.pop();

	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	for (int i = 0; i < NUM_SPHERES; ++i) {
		modelViewMatrix.push();

		modelViewMatrix.MultMatrix(spheres[i]);
		shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
									modelViewMatrix.GetMatrix(),
									transformPipeline.GetProjectionMatrix(),
									vLightTransformed,
									vWhite,
									0);
		sphereBatch.draw();

		modelViewMatrix.pop();
	}

	// song and dance
	modelViewMatrix.moveTo(0.0f, 0.2f, -2.5f);
	modelViewMatrix.push();	// save the translated origin
	modelViewMatrix.rotateTo(yRot, 0.0f, 1.0f, 0.0f);

	// draw stuff relative to the camera
	glBindTexture(GL_TEXTURE_2D, uiTextures[1]);
	shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
								modelViewMatrix.GetMatrix(),
								transformPipeline.GetProjectionMatrix(),
								vLightTransformed,
								vWhite,
								0);
	torusBatch.draw();
	modelViewMatrix.pop();	// erased the rotate

	modelViewMatrix.rotateTo(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.moveTo(0.8f, 0.0f, 0.0f);

	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
								modelViewMatrix.GetMatrix(),
								transformPipeline.GetProjectionMatrix(),
								vLightTransformed,
								vWhite,
								0);
	sphereBatch.draw();
}
Example #2
0
/**
 * Called to draw scene
 */
void RenderScene(void)
{
	// Bind the FBO with multisample buffers
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, msFBO);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// User selected order independant transparency
	if (mode == USER_OIT)
	{
		// Use OIT, setup sample masks
		glSampleMaski(0, 0x01);
		glEnable(GL_SAMPLE_MASK);

		// Prevent depth test from culling covered surfaces
		glDepthFunc(GL_ALWAYS);
	}

	modelViewMatrix.push();
	M3DMatrix44f mCamera;
	cameraFrame.GetCameraMatrix(mCamera);
	modelViewMatrix.MultMatrix(mCamera);

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.0f, -0.4f, -4.0f);
	modelViewMatrix.rotateTo(worldAngle, 0.0, 1.0, 0.0);

	// Draw the background and disk to the first sample
	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.0f, 3.0f, 0.0f);
	modelViewMatrix.rotateTo(90.0, 1.0, 0.0, 0.0);
	modelViewMatrix.rotateTo(90.0, 0.0, 0.0, 1.0);
	glBindTexture(GL_TEXTURE_2D, textures[1]);
	shaderManager.useStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetMVPMatrix(), 0);
	bckgrndCylBatch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.moveTo(0.0f, -0.3f, 0.0f);
	modelViewMatrix.push();
	modelViewMatrix.rotateTo(90.0, 1.0, 0.0, 0.0);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vGrey);
	diskBatch.draw();
	modelViewMatrix.pop();
	modelViewMatrix.moveTo(0.0f, 0.1f, 0.0f);

	// User selected blending
	if (mode == USER_BLEND)
	{
		// Setup blend state
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		switch (blendMode)
		{
		case 1:
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			break;
		case 2:
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
			break;
		case 3:
			glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
			break;
		case 4:
			glBlendFunc(GL_SRC_ALPHA, GL_ONE);
			break;
		case 5:
			glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
			break;
		case 6:
			glBlendFuncSeparate(GL_SRC_ALPHA, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			break;
		case 7:
			glBlendFuncSeparate(GL_SRC_COLOR, GL_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			break;
		default:
			glDisable(GL_BLEND);
		}
	}

	// Now draw the glass pieces
	DrawWorld();

	modelViewMatrix.pop();
	modelViewMatrix.pop();

	// Clean up all state 
	glDepthFunc(GL_LEQUAL);
	glDisable(GL_BLEND);
	glDisable(GL_SAMPLE_MASK);
	glSampleMaski(0, 0xffffffff);

	// Resolve multisample buffer
	projectionMatrix.push();
	projectionMatrix.setMatrix(orthoMatrix);
	modelViewMatrix.push();
	modelViewMatrix.identity();
	// Setup and Clear the default framebuffer
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
	glViewport(0, 0, screenWidth, screenHeight);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (mode == USER_OIT)
		SetupOITResolveProg();
	else if (mode == USER_BLEND)
		SetupResolveProg();

	// Draw a full-size quad to resolve the multisample surfaces
	screenQuad.draw();
	modelViewMatrix.pop();
	projectionMatrix.pop();

	// Reset texture state
	glEnable(GL_DEPTH_TEST);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);

	// Perform the buffer swap to display back buffer
	glutSwapBuffers();
	glutPostRedisplay();
}