Пример #1
0
void displayTexFilerInfo()
{
	char buff[255];
	std::string tinfoMinification[] =
	{
		"Nearest",
		"Bilinear"
	};

	std::string tinfoMagnification[] =
	{
		"Nearest",
		"Bilinear",
		"Nearest on closest mipmap",
		"Bilinear on closest mipmap",
		"Trilinear"
	};

	sprintf_s(buff, "Mag Filter: %s Min Filter: %s", tinfoMinification[tSnow.GetMagnificationFilter()].c_str(),
		tinfoMagnification[tSnow.GetMinificationFilter() - 2].c_str());

	SetWindowText(appMain.hWnd, buff);
}
Пример #2
0
void RenderScene(LPVOID lpParam)
{
	// typecast lpParam to Render pointer
	Render* glRender = (Render*)lpParam;


	////Rendering happens here////

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	int iModelViewLoc = glGetUniformLocation(spShader.GetShaderProgramID(), "modelViewMatrix");
	int iProjectionLoc = glGetUniformLocation(spShader.GetShaderProgramID(), "projectionMatrix");
	glUniformMatrix4fv(iProjectionLoc, 1, GL_FALSE, glm::value_ptr(*glRender->GetProjectionMatrix()));

	glm::mat4 mModelView = glm::lookAt(glm::vec3(0, 12, 27), glm::vec3(0, 0, 0), glm::vec3(0.0f, 1.0f, 0.0f));
	glm::mat4 mCurrent;

	glBindVertexArray(uVAO);

	// texture binding set GL_ACTIVE_TEXTURE0, then tellfragment shader
	// that Sampler variable will get data from GL_ACTIVE_TEXTURE0

	int iSimplerLoc = glGetUniformLocation(spShader.GetShaderProgramID(), "gSampler");
	glUniform1i(iSimplerLoc, 0);

	tGold.BindTexture(0);

	// render cube

	mCurrent = glm::translate(mModelView, glm::vec3(-8.0f, 0.0f, 0.0f));
	mCurrent = glm::scale(mCurrent, glm::vec3(10.0f, 10.0f, 10.0f));
	mCurrent = glm::rotate(mCurrent, fRotationAngleCube, glm::vec3(1.0f, 0.0f, 0.0f));
	glUniformMatrix4fv(iModelViewLoc, 1, GL_FALSE, glm::value_ptr(mCurrent));

	glDrawArrays(GL_TRIANGLES, 0, 36);

	// Rendering of pyramid

	mCurrent = glm::translate(mModelView, glm::vec3(8.0f, 0.0f, 0.0f));
	mCurrent = glm::scale(mCurrent, glm::vec3(10.0f, 10.0f, 10.0f));
	mCurrent = glm::rotate(mCurrent, fRotationAnglePyramid, glm::vec3(0.0f, 1.0f, 0.0f));
	glUniformMatrix4fv(iModelViewLoc, 1, GL_FALSE, glm::value_ptr(mCurrent));

	glDrawArrays(GL_TRIANGLES, 36, 12);

	// render ground
	tSnow.BindTexture();

	glUniformMatrix4fv(iModelViewLoc, 1, GL_FALSE, glm::value_ptr(mModelView));
	glDrawArrays(GL_TRIANGLES, 48, 6);

	// user control

	if (Keys::Key(VK_UP))fCubeRotationSpeed -= appMain.sof(60.0f);
	if (Keys::Key(VK_DOWN))fCubeRotationSpeed += appMain.sof(60.0f);
	if (Keys::Key(VK_RIGHT))fPyramidRotationSpeed += appMain.sof(60.0f);
	if (Keys::Key(VK_LEFT))fPyramidRotationSpeed -= appMain.sof(60.0f);

	fRotationAngleCube += appMain.sof(fCubeRotationSpeed);
	fRotationAnglePyramid += appMain.sof(fPyramidRotationSpeed);
	
	// toggle FPS and V-Sync
	if (Keys::OneKey(VK_F1))
	{
		bShowFPS = !bShowFPS;
		if (!bShowFPS)
		{
			SetWindowText(appMain.hWnd, "Test Open GL Window");
		}
	}

	if (Keys::OneKey(VK_F2))
	{
		bVSync = !bVSync;
		glRender->SetVerticalSynchronization(bVSync);
	}
	else if (Keys::OneKey(VK_F3))
	{
		tGold.SetFiltering((tGold.GetMagnificationFilter() + 1) % 2, tGold.GetMinificationFilter());
		tSnow.SetFiltering((tSnow.GetMagnificationFilter() + 1) % 2, tSnow.GetMinificationFilter());
		displayTexFilerInfo();
	}
	else if (Keys::OneKey(VK_F4))
	{
		int newMinFilter = tSnow.GetMinificationFilter() == TEXTURE_FILTER_MIN_TRILINEAR ? TEXTURE_FILTER_MIN_NEAREST : tSnow.GetMinificationFilter() + 1;
		tSnow.SetFiltering(tSnow.GetMagnificationFilter(), newMinFilter);
		tGold.SetFiltering(tGold.GetMagnificationFilter(), newMinFilter);
		displayTexFilerInfo();
	}

	if (bShowFPS)
	{
		char buff[55];

		sprintf_s(buff, "FPS: %d, VSync: %s", glRender->GetFPS(), bVSync ? "On" : "Off");

		SetWindowText(appMain.hWnd, buff);
	}

	if (Keys::OneKey(VK_ESCAPE))
		PostQuitMessage(0);


	// call SwapBuffers
	glRender->SwapBuffersM();
}