当前位置: 首页>>代码示例>>C++>>正文


C++ Texture::BeginDrawing方法代码示例

本文整理汇总了C++中Texture::BeginDrawing方法的典型用法代码示例。如果您正苦于以下问题:C++ Texture::BeginDrawing方法的具体用法?C++ Texture::BeginDrawing怎么用?C++ Texture::BeginDrawing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Texture的用法示例。


在下文中一共展示了Texture::BeginDrawing方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawScene

	void DrawScene(Texture& renderTarget)
	{
		// Begin drawing to render target and clear it

		renderTarget.BeginDrawing(&Color::Black);

		// Background with moving moon

		background.Draw();
		moon.Draw(moonPosition, sinf(moonPosition.x * 0.1f) * 0.3f);

		// Particle effects

		spinningEffect.Draw();
		cursorEffect.Draw();

		// Draw content of the render texture

		renderTexture.Draw(Vec2(100, 100), -moonPosition.x * 0.01f);

		// Walking character
		{
			Sprite::DrawParams params;
			params.position = characterPosition;
			params.flipX = characterDir == Dir_Left;
			params.scale = 1.4f;

			character.Draw(&params);
		}

		// End drawing to render target

		renderTarget.EndDrawing();
	}
开发者ID:EpsilonAquilae,项目名称:Tiny2D,代码行数:34,代码来源:Tiny2D_Sample.cpp

示例2: DrawToRenderTexture

	void DrawToRenderTexture(Texture& renderTarget)
	{
		renderTarget.BeginDrawing(&Color::Black);

		// Draw the moon
		{
			const Rect rect(0.0f, 0.0f, 256.0f, 256.0f);

			Sprite::DrawParams params;
			params.rect = ▭
			moon.Draw(&params);
		}

		// Draw some debug shapes

		Shape::DrawCircle(Vec2(50, 50), 50, 5, moonPosition.x * 0.1f, Color(1, 0, 0, 0.7f));
		Shape::DrawCircle(Vec2(130, 130), 70, 15, -moonPosition.x * 0.1f, Color(0, 1, 0, 0.7f));
		Shape::DrawRectangle(150, 150, 240, 220, moonPosition.x * 0.05f, Color(0, 0, 1, 0.7f));
		Shape::DrawLine(Vec2(10, 10), Vec2(200, 200), Color::White);

		// Draw debug text

		font.Draw("This is\nrender\ntexture", Vec2(20, 70), Color::Yellow);

		renderTarget.EndDrawing();
	}
开发者ID:EpsilonAquilae,项目名称:Tiny2D,代码行数:26,代码来源:Tiny2D_Sample.cpp

示例3: Postprocessing_DrawQuake

void Postprocessing_DrawQuake(Texture& output, Texture& scene)
{
	output.BeginDrawing(&Color::Black);
	quake->material.SetTechnique("quake");
	quake->material.SetTextureParameter("ColorMap", scene);
	quake->material.SetFloatParameter("Offset", (const float*) &quake->targetOffset, 2);
	quake->material.DrawFullscreenQuad();
	output.EndDrawing();
}
开发者ID:hrasdt,项目名称:Tiny2D,代码行数:9,代码来源:Tiny2D_Postprocessing.cpp

示例4: Postprocessing_DrawOldTV

void Postprocessing_DrawOldTV(Texture& renderTarget, Texture& scene)
{
	renderTarget.BeginDrawing();

	oldtv->material.SetTechnique("oldtv");

	oldtv->material.SetTextureParameter("ColorMap", scene, Sampler::DefaultPostprocess);
	oldtv->material.SetFloatParameter("Time", oldtv->time);

	oldtv->material.SetFloatParameter("OverExposureAmount", 0.1f);
	oldtv->material.SetFloatParameter("DustAmount", 4.0f);
	oldtv->material.SetFloatParameter("FrameJitterFrequency", 3.0f);
	oldtv->material.SetFloatParameter("MaxFrameJitter", 1.4f);
	const Color filmColor(1.0f, 0.7559052f, 0.58474624f, 1.0f);
	oldtv->material.SetFloatParameter("FilmColor", (const float*) &filmColor, 4);
	oldtv->material.SetFloatParameter("GrainThicknes", 1.0f);
	oldtv->material.SetFloatParameter("GrainAmount", 0.8f);
	oldtv->material.SetFloatParameter("ScratchesAmount", 3.0f);
	oldtv->material.SetFloatParameter("ScratchesLevel", 0.7f);

	Sampler dustSampler;
	dustSampler.SetFiltering(true, true);
	dustSampler.SetWrapMode(Sampler::WrapMode_ClampToBorder, Sampler::WrapMode_ClampToBorder, Color::White);
	oldtv->material.SetTextureParameter("DustMap", oldtv->dustMap, dustSampler);

	Sampler lineSampler;
	lineSampler.SetFiltering(false, false);
	lineSampler.SetWrapMode(Sampler::WrapMode_ClampToBorder, Sampler::WrapMode_Clamp, Color::White);
	oldtv->material.SetTextureParameter("LineMap", oldtv->lineMap, lineSampler);

	Sampler tvSampler;
	tvSampler.SetFiltering(true, true);
	tvSampler.SetWrapMode(Sampler::WrapMode_Clamp, Sampler::WrapMode_Clamp);
	oldtv->material.SetTextureParameter("TvMap", oldtv->tvAndNoiseMap, tvSampler);

	Sampler noiseSampler;
	noiseSampler.SetFiltering(true, true);
	noiseSampler.SetWrapMode(Sampler::WrapMode_Repeat, Sampler::WrapMode_Repeat);
	oldtv->material.SetTextureParameter("NoiseMap", oldtv->tvAndNoiseMap, noiseSampler);

	oldtv->material.DrawFullscreenQuad();

	renderTarget.EndDrawing();
}
开发者ID:hrasdt,项目名称:Tiny2D,代码行数:44,代码来源:Tiny2D_Postprocessing.cpp

示例5: DrawLoadingScreen

	void DrawLoadingScreen(Texture& renderTarget)
	{
		// Begin drawing to render target

		renderTarget.BeginDrawing();

		// Draw background

		loadingScreen.Draw();

		// Draw rotating cog wheels

		DrawCogWheel(640, 930 - 750, 110, cogWheelRotation, Color(0.7f, 0.4f, 0.1f, 1));
		DrawCogWheel(820, 880 - 750, 70, -cogWheelRotation * 1.3f, Color(0.6f, 0.3f, 0.1f, 1));
		DrawCogWheel(900, 970 - 750, 42, cogWheelRotation * 1.8f, Color(0.6f, 0.4f, 0.1f, 1));
		DrawCogWheel(952, 914 - 750, 30, -cogWheelRotation * 2.8f, Color(0.7f, 0.4f, 0.1f, 1));
		DrawCogWheel(990, 957 - 750, 22, cogWheelRotation * 3.4f, Color(0.5f, 0.3f, 0.1f, 1));

		// End drawing to render target
		
		renderTarget.EndDrawing();
	}
开发者ID:EpsilonAquilae,项目名称:Tiny2D,代码行数:22,代码来源:Tiny2D_Sample.cpp

示例6: Postprocessing_DrawRainyGlass

void Postprocessing_DrawRainyGlass(Texture& renderTarget, Texture& scene)
{
	Texture dropletTarget = RenderTexturePool::Get(256, 256);

	// Clear droplet render target to default front-facing direction

	const Color frontClearColor(0.5f /* x == 0 */, 0.5f /* y = 0 */, 1.0f /* z = 1 */, 0.0f);
	dropletTarget.BeginDrawing(&frontClearColor);

	// Evaporation

	if (rain->dropletBuffer.IsValid())
	{
		if (rain->rainEvaporation > 0.02f) // Apply rain evaporation
		{
			rain->material.SetTechnique("rain_evaporation");
			rain->rainEvaporation = 0;
		}
		else // Just copy previous buffer (skip evaporation step this time)
		{
			rain->material.SetTechnique("copy_texture");
		}

		rain->material.SetTextureParameter("ColorMap", rain->dropletBuffer, Sampler::DefaultPostprocess);
		rain->material.DrawFullscreenQuad();
	}

	// Droplets

	const Vec2 sizeScale( (float) dropletTarget.GetWidth(), (float) dropletTarget.GetHeight() );

	while (rain->deltaTime > 0.0f)
	{
		const float stepDeltaTime = min(rain->deltaTime, 1 / 60.0f);
		rain->deltaTime -= stepDeltaTime;
		Postprocessing_UpdateRainyGlassStep(stepDeltaTime);

		const unsigned int numDroplets = rain->droplets.size();
		if (!numDroplets)
			continue;

		std::vector<Vec2> verts(numDroplets * 4);
		std::vector<Vec2> tex(numDroplets * 4);
		std::vector<unsigned short> indices(numDroplets * 6);

		int currVertexIndex = 0;
		unsigned short* currIndex = &indices[0];

		std::vector<RainyGlass::Droplet>::iterator dropletsEnd = rain->droplets.end();
		for (std::vector<RainyGlass::Droplet>::iterator it = rain->droplets.begin(); it != dropletsEnd; ++it)
		{
			Vec2 size = Vec2(it->size, it->size);
			Vec2 pos = it->pos - size * 0.5f;

			size *= sizeScale;
			pos *= sizeScale;

			Vec2* currVertex = &verts[currVertexIndex];
			*(currVertex++) = pos;
			*(currVertex++) = pos + Vec2(size.x, 0.0f);
			*(currVertex++) = pos + size;
			*(currVertex++) = pos + Vec2(0.0f, size.y);

			Vec2* currTex = &tex[currVertexIndex];
			(currTex++)->Set(0.0f, 0.0f);
			(currTex++)->Set(1.0f, 0.0f);
			(currTex++)->Set(1.0f, 1.0f);
			(currTex++)->Set(0.0f, 1.0f);

			*(currIndex++) = currVertexIndex;
			*(currIndex++) = currVertexIndex + 1;
			*(currIndex++) = currVertexIndex + 2;
			*(currIndex++) = currVertexIndex;
			*(currIndex++) = currVertexIndex + 2;
			*(currIndex++) = currVertexIndex + 3;

			currVertexIndex += 4;
		}

		Shape::DrawParams drawParams;
		drawParams.SetGeometryType(Shape::Geometry::Type_Triangles);
		drawParams.SetNumVerts(verts.size());
		drawParams.SetPosition(&verts[0], sizeof(Vec2));
		drawParams.SetTexCoord(&tex[0], 0, sizeof(Vec2));
		drawParams.SetIndices(indices.size(), &indices[0]);

		Material& defaultMaterial = App::GetDefaultMaterial();

		defaultMaterial.SetTechnique("tex_col");
		defaultMaterial.SetFloatParameter("Color", (const float*) &Color::White, 4);
		defaultMaterial.SetTextureParameter("ColorMap", rain->dropletTexture);
		defaultMaterial.Draw(&drawParams);
	}

	dropletTarget.EndDrawing();

	// Swap droplet buffer

	if (rain->dropletBuffer.IsValid())
		RenderTexturePool::Release(rain->dropletBuffer);
//.........这里部分代码省略.........
开发者ID:hrasdt,项目名称:Tiny2D,代码行数:101,代码来源:Tiny2D_Postprocessing.cpp

示例7: Postprocessing_DrawBloom

void Postprocessing_DrawBloom(Texture& output, Texture& scene)
{
	Assert(bloom);

	const int width = App::GetWidth();
	const int height = App::GetHeight();

	// Downsample to half size

	Texture halfSizeRenderTexture = RenderTexturePool::Get(width / 2, height / 2);
	halfSizeRenderTexture.BeginDrawing();
	bloom->material.SetTechnique("downsample2x2");
	bloom->material.SetTextureParameter("ColorMap", scene);
	bloom->material.DrawFullscreenQuad();
	halfSizeRenderTexture.EndDrawing();

	// Downsample to quarter size

	Texture quarterSizeRenderTextures[2];

	quarterSizeRenderTextures[0] = RenderTexturePool::Get(width / 4, height / 4);
	quarterSizeRenderTextures[0].BeginDrawing();
	bloom->material.SetTextureParameter("ColorMap", halfSizeRenderTexture);
	bloom->material.DrawFullscreenQuad();
	quarterSizeRenderTextures[0].EndDrawing();
	RenderTexturePool::Release(halfSizeRenderTexture);

	// Blur downsampled scene vertically and horizontally

	if (bloom->numBlurSteps)
	{
		bloom->material.SetFloatParameter("BlurKernel", &bloom->blurKernel);
		quarterSizeRenderTextures[1] = RenderTexturePool::Get(width / 4, height / 4);
	}

	for (int i = 0; i < bloom->numBlurSteps; i++)
	{
		quarterSizeRenderTextures[1].BeginDrawing();
		bloom->material.SetTechnique("vertical_blur");
		bloom->material.SetTextureParameter("ColorMap", quarterSizeRenderTextures[0], Sampler::DefaultPostprocess);
		bloom->material.DrawFullscreenQuad();
		quarterSizeRenderTextures[1].EndDrawing();

		quarterSizeRenderTextures[0].BeginDrawing();
		bloom->material.SetTechnique("horizontal_blur");
		bloom->material.SetTextureParameter("ColorMap", quarterSizeRenderTextures[1], Sampler::DefaultPostprocess);
		bloom->material.DrawFullscreenQuad();
		quarterSizeRenderTextures[0].EndDrawing();
	}

	if (bloom->numBlurSteps)
		RenderTexturePool::Release(quarterSizeRenderTextures[1]);

	// Blend result with the scene

	output.BeginDrawing();
	bloom->material.SetTechnique("blend");
	bloom->material.SetTextureParameter("ColorMap0", quarterSizeRenderTextures[0]);
	bloom->material.SetTextureParameter("ColorMap1", scene, Sampler::DefaultPostprocess);
	bloom->material.SetFloatParameter("BlendFactor", &bloom->blendFactor);
	bloom->material.DrawFullscreenQuad();
	output.EndDrawing();

	RenderTexturePool::Release(quarterSizeRenderTextures[0]);
}
开发者ID:hrasdt,项目名称:Tiny2D,代码行数:65,代码来源:Tiny2D_Postprocessing.cpp


注:本文中的Texture::BeginDrawing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。