Exemple #1
0
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			break;
		case 2:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
			break;
		case 3:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
			break;
		case 4:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
			break;
		case 5:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			break;
		case 6:
			{
				GLfloat fLargest = 0;
				glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);	// 获取各向异性支持的数量
				glTexParameteri(GL_TEXTURE_2D, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
			}
			break;
		case 7:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
		}
	}

	// Trigger redraw
	glutPostRedisplay();
}
Exemple #2
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld()
{
	modelViewMatrix.moveTo(0.0f, 0.8f, 0.0f);
	modelViewMatrix.push();
	modelViewMatrix.moveTo(-0.3f, 0.f, 0.0f);
	modelViewMatrix.scaleTo(0.40, 0.8, 0.40);
	modelViewMatrix.rotateTo(50.0, 0.0, 10.0, 0.0);
	glSampleMaski(0, 0x02);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtYellow);
	glass1Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.4f, 0.0f, 0.0f);
	modelViewMatrix.scaleTo(0.5, 0.8, 1.0);
	modelViewMatrix.rotateTo(-20.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x04);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtGreen);
	glass2Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(1.0f, 0.0f, -0.6f);
	modelViewMatrix.scaleTo(0.3, 0.9, 1.0);
	modelViewMatrix.rotateTo(-40.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x08);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtMagenta);
	glass3Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(-0.8f, 0.0f, -0.60f);
	modelViewMatrix.scaleTo(0.6, 0.9, 0.40);
	modelViewMatrix.rotateTo(60.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x10);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtBlue);
	glass4Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.1f, 0.0f, 0.50f);
	modelViewMatrix.scaleTo(0.4, 0.9, 0.4);
	modelViewMatrix.rotateTo(205.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x20);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtPink);
	glass4Batch.draw();
	modelViewMatrix.pop();
}
/**
 * Called to draw scene
 */
void RenderScene(void)
{
	static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f };
	static CStopWatch rotTimer;
	float yRot = rotTimer.delta() * 60.0f;

	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	modelViewMatrix.push();

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

	// draw the world upside down
	modelViewMatrix.push();
	modelViewMatrix.scaleTo(1.0f, -1.0f, 1.0f); // flips the Y axis
	modelViewMatrix.moveTo(0.0f, 0.8f, 0.0f); // scootch the world down a bit...

	glFrontFace(GL_CW);
	DrawSongAndDance(yRot);
	glFrontFace(GL_CCW); // restore it

	modelViewMatrix.pop();

	// draw the solid ground
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	shaderManager.useStockShader(GLT_SHADER_TEXTURE_MODULATE, 
		transformPipeline.GetMVPMatrix(), 
		vFloorColor, 
		0);
	floorBatch.draw();
	glDisable(GL_BLEND);

	DrawSongAndDance(yRot);

	modelViewMatrix.pop();

	// Render the overlay

	// Creating this matrix really doesn't need to be done every frame. I'll leave it here
	// so all the pertenant code is together
	M3DMatrix44f mScreenSpace;
	m3dMakeOrthographicMatrix(mScreenSpace, 0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 1.0f);

	// turn blending on, and dephth testing off
	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);

	glUseProgram(rectReplaceShader);
	glUniform1i(locRectTexture, 0);
	glUniformMatrix4fv(locRectMVP, 1, GL_FALSE, mScreenSpace);
	glBindTexture(GL_TEXTURE_RECTANGLE, uiTextures[3]);
	logoBatch.draw();

	// restore no blending and depth test
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	// Perform the buffer swap to display back buffer
	glutSwapBuffers();
	glutPostRedisplay();
}
// 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();
}
Exemple #5
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();
}