本文整理汇总了C#中IRenderContext.EnableTextures方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderContext.EnableTextures方法的具体用法?C# IRenderContext.EnableTextures怎么用?C# IRenderContext.EnableTextures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRenderContext
的用法示例。
在下文中一共展示了IRenderContext.EnableTextures方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public override void Render(IGameContext gameContext, IRenderContext renderContext)
{
if (!renderContext.Is3DContext)
return;
if (this.m_GrassAsset == null)
return;
var vertexes = new[]
{
new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(0, 0, 1), new Vector2(0, 1)),
new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3(0, 1, 1), new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(0, 1)),
new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(1, 1))
};
var indicies = new short[]
{
0, 2, 1, 1, 2, 3,
4, 5, 6, 5, 7, 6,
0, 4, 6, 0, 6, 2,
1, 7, 5, 1, 3, 7,
0, 1, 4, 5, 4, 1,
6, 3, 2, 7, 3, 6
};
var oldWorld = renderContext.World;
renderContext.EnableTextures();
renderContext.SetActiveTexture(this.m_GrassAsset.Texture);
renderContext.World =
Matrix.CreateRotationY(MathHelper.ToRadians(this.m_Rotation)) *
Matrix.CreateTranslation(new Vector3(this.X, this.Y, this.Z));
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
vertexes,
0, // vertex buffer offset to add to each element of the index buffer
8, // number of vertices to draw
indicies,
0, // first index element to read
indicies.Length / 3);
}
renderContext.World = oldWorld;
}
示例2: Render
/// <summary>
/// Renders the specified chunk with the specified rendering context.
/// </summary>
/// <param name="renderContext">The rendering context.</param>
/// <param name="runtimeChunk">The runtime chunk to render.</param>
public void Render(IRenderContext renderContext, IChunk runtimeChunk)
{
if (!renderContext.Is3DContext)
{
return;
}
if (runtimeChunk.GraphicsEmpty)
{
return;
}
if (runtimeChunk.Generated && runtimeChunk.VertexBuffer == null && runtimeChunk.IndexBuffer == null)
{
this.CalculateBuffers(renderContext, runtimeChunk);
}
if (runtimeChunk.VertexBuffer != null && runtimeChunk.IndexBuffer != null)
{
renderContext.PushEffect(this.m_TerrainEffectAsset.Effect);
renderContext.EnableTextures();
renderContext.SetActiveTexture(this.m_TextureAtlasAsset.TextureAtlas.Texture);
renderContext.GraphicsDevice.Indices = runtimeChunk.IndexBuffer;
renderContext.GraphicsDevice.SetVertexBuffer(runtimeChunk.VertexBuffer);
renderContext.World = Matrix.CreateScale(32);
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
runtimeChunk.VertexBuffer.VertexCount,
0,
runtimeChunk.IndexBuffer.IndexCount / 3);
}
renderContext.PopEffect();
}
}
示例3: Render
public void Render(IGameContext gameContext, IRenderContext renderContext, bool renderFull = false)
{
if (!renderContext.Is3DContext)
{
return;
}
if (this.m_BuffersNeedRecalculation)
{
this.RecalculateBuffers(renderContext);
}
if (renderFull)
{
if (this.m_FullVertexBuffer != null && this.m_FullIndexBuffer != null)
{
renderContext.World = Matrix.Identity;
renderContext.EnableTextures();
renderContext.SetActiveTexture(this.m_TextureAsset.Texture);
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.Indices = this.m_FullIndexBuffer;
renderContext.GraphicsDevice.SetVertexBuffer(this.m_FullVertexBuffer);
renderContext.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
this.m_FullVertexBuffer.VertexCount,
0,
this.m_FullIndexBuffer.IndexCount / 3);
}
}
}
else
{
if (this.m_CulledVertexBuffer != null && this.m_CulledIndexBuffer != null)
{
renderContext.World = Matrix.Identity;
renderContext.EnableTextures();
renderContext.SetActiveTexture(this.m_TextureAsset.Texture);
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.Indices = this.m_CulledIndexBuffer;
renderContext.GraphicsDevice.SetVertexBuffer(this.m_CulledVertexBuffer);
renderContext.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
this.m_CulledVertexBuffer.VertexCount,
0,
this.m_CulledIndexBuffer.IndexCount / 3);
}
}
}
foreach (var room in this.Rooms)
{
var matrix = Matrix.CreateScale(0.1f) * Matrix.CreateTranslation(room.X / 10, room.Y / 10, room.Z / 10);
room.Render(gameContext, renderContext, null, false, matrix);
}
}
示例4: RenderTexture
/// <summary>
/// The render texture.
/// </summary>
/// <param name="context">
/// The context.
/// </param>
/// <param name="matrix">
/// The matrix.
/// </param>
/// <param name="texture">
/// The texture.
/// </param>
/// <param name="color">
/// The color.
/// </param>
/// <param name="flipHorizontally">
/// The flip horizontally.
/// </param>
/// <param name="flipVertically">
/// The flip vertically.
/// </param>
/// <param name="sourceArea">
/// The source area.
/// </param>
/// <exception cref="NotSupportedException">
/// </exception>
private void RenderTexture(
IRenderContext context,
Matrix matrix,
Texture2D texture,
Color? color = null,
bool flipHorizontally = false,
bool flipVertically = false,
Rectangle? sourceArea = null)
{
if (color != null)
{
throw new NotSupportedException();
}
if (flipHorizontally)
{
throw new NotSupportedException();
}
if (flipVertically)
{
throw new NotSupportedException();
}
if (sourceArea != null)
{
throw new NotSupportedException();
}
context.EnableTextures();
context.SetActiveTexture(texture);
var vertexes = new[]
{
new VertexPositionTexture(Vector3.Transform(new Vector3(0, 0, 0), matrix), new Vector2(0, 1)),
new VertexPositionTexture(Vector3.Transform(new Vector3(0, 1, 0), matrix), new Vector2(0, 0)),
new VertexPositionTexture(Vector3.Transform(new Vector3(1, 0, 0), matrix), new Vector2(1, 1)),
new VertexPositionTexture(Vector3.Transform(new Vector3(1, 1, 0), matrix), new Vector2(1, 0))
};
var indicies = new short[] { 1, 3, 0, 2 };
context.GraphicsDevice.BlendState = BlendState.NonPremultiplied;
foreach (var pass in context.Effect.CurrentTechnique.Passes)
{
pass.Apply();
context.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleStrip,
vertexes,
0,
vertexes.Length,
indicies,
0,
vertexes.Length - 2);
}
context.GraphicsDevice.BlendState = BlendState.Opaque;
}
示例5: RenderPlane
public void RenderPlane(IRenderContext context, Matrix transform, TextureAsset texture, Vector2 topLeftUV,
Vector2 bottomRightUV)
{
if (!context.Is3DContext)
{
throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
}
var vertexes = new[]
{
new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
};
var indicies = new short[]
{
0, 2, 1,
3, 1, 2,
};
context.EnableTextures();
context.SetActiveTexture(texture.Texture);
var world = context.World;
context.World = transform;
foreach (var pass in context.Effect.CurrentTechnique.Passes)
{
pass.Apply();
context.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
vertexes,
0,
vertexes.Length,
indicies,
0,
indicies.Length / 3);
}
context.World = world;
}
示例6: RenderLine
/// <summary>
/// Renders a 3D line using texture UVs.
/// </summary>
/// <param name="context">
/// The rendering context.
/// </param>
/// <param name="start">
/// The start of the line.
/// </param>
/// <param name="end">
/// The end of the line.
/// </param>
/// <param name="texture">
/// The texture to use.
/// </param>
/// <param name="startUV">
/// The UV for the start of the line.
/// </param>
/// <param name="endUV">
/// The UV for the end of the line.
/// </param>
public void RenderLine(
IRenderContext context,
Vector3 start,
Vector3 end,
TextureAsset texture,
Vector2 startUV,
Vector2 endUV)
{
if (!context.Is3DContext)
{
throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
}
context.EnableTextures();
context.SetActiveTexture(texture.Texture);
var vertexes = new[] { new VertexPositionTexture(start, startUV), new VertexPositionTexture(end, endUV) };
var indicies = new short[] { 0, 1 };
foreach (var pass in context.Effect.CurrentTechnique.Passes)
{
pass.Apply();
context.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertexes, 0, 2, indicies, 0, 1);
}
}
示例7: RenderCube
public void RenderCube(IRenderContext renderContext, Matrix transform, TextureAsset texture, Vector2 topLeftUV, Vector2 bottomRightUV)
{
var vertexes = new[]
{
new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(-1, 0, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(-1, 0, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(-1, 0, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 1, 1), new Vector3(-1, 0, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(1, 0, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 1, 1), new Vector3(1, 0, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 1, 1), new Vector3(0, 1, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 1, 1), new Vector3(0, 1, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector2(topLeftUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(0, 0, -1), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(0, 1, 1), new Vector3(0, 0, 1), new Vector2(topLeftUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, 0, 1), new Vector2(bottomRightUV.X, topLeftUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(0, 0, -1), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
new VertexPositionNormalTexture(new Vector3(1, 1, 1), new Vector3(0, 0, 1), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
};
var indicies = new short[]
{
0, 2, 1,
3, 1, 2,
4, 5, 6,
7, 6, 5,
0 + 8, 1 + 8, 4 + 8,
5 + 8, 4 + 8, 1 + 8,
2 + 8, 6 + 8, 3 + 8,
7 + 8, 3 + 8, 6 + 8,
0 + 16, 4 + 16, 2 + 16,
6 + 16, 2 + 16, 4 + 16,
1 + 16, 3 + 16, 5 + 16,
7 + 16, 5 + 16, 3 + 16
};
renderContext.EnableTextures();
renderContext.SetActiveTexture(texture.Texture);
var world = renderContext.World;
renderContext.World = transform;
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
vertexes,
0,
vertexes.Length,
indicies,
0,
indicies.Length / 3);
}
renderContext.World = world;
}
示例8: Render
public void Render(
IGameContext gameContext,
IRenderContext renderContext,
RoomObject focused,
bool renderFocusedTransparently,
Matrix? matrix = null)
{
if (this.m_RefreshBuffers)
{
this.RefreshBuffers(renderContext);
this.m_RefreshBuffers = false;
}
var oldWorld = renderContext.World;
renderContext.World = matrix ?? Matrix.Identity;
renderContext.EnableTextures();
renderContext.SetActiveTexture(this.m_TextureAsset.Texture);
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
this.RenderRoom(renderContext);
foreach (var obj in this.m_RoomObjects)
{
if (renderFocusedTransparently && obj == focused)
{
continue;
}
obj.Render(gameContext, renderContext);
}
}
if (renderFocusedTransparently && focused != null && this.m_RoomObjects.Contains(focused))
{
renderContext.GraphicsDevice.BlendState = BlendState.AlphaBlend;
renderContext.Effect.Parameters["Alpha"].SetValue(0.5f);
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
focused.Render(gameContext, renderContext);
}
renderContext.Effect.Parameters["Alpha"].SetValue(1f);
}
renderContext.GraphicsDevice.BlendState = BlendState.Opaque;
renderContext.World = oldWorld;
}
示例9: Blit
public void Blit(IRenderContext renderContext, RenderTarget2D source, RenderTarget2D destination = null, Effect shader = null)
{
float destWidth, destHeight;
if (destination != null)
{
renderContext.PushRenderTarget(destination);
destWidth = destination.Width;
destHeight = destination.Height;
}
else
{
// TODO: renderContext.GraphicsDevice.GetRenderTargets();
destWidth = renderContext.GraphicsDevice.PresentationParameters.BackBufferWidth;
destHeight = renderContext.GraphicsDevice.PresentationParameters.BackBufferHeight;
}
if (shader == null)
{
shader = _blitEffect;
}
if (_vertexBuffer == null)
{
_vertexBuffer = new VertexBuffer(renderContext.GraphicsDevice, typeof (VertexPositionTexture),
_vertexes.Length, BufferUsage.WriteOnly);
_vertexBuffer.SetData(_vertexes);
}
if (_indexBuffer == null)
{
_indexBuffer = new IndexBuffer(renderContext.GraphicsDevice, typeof (short), _indicies.Length,
BufferUsage.WriteOnly);
_indexBuffer.SetData(_indicies);
}
var oldWorld = renderContext.World;
var oldProjection = renderContext.Projection;
var oldView = renderContext.View;
renderContext.GraphicsDevice.BlendState = BlendState.Opaque;
renderContext.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
renderContext.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
renderContext.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
renderContext.World = Matrix.CreateScale(destWidth, destHeight, 1);
#if PLATFORM_WINDOWS
renderContext.Projection = Matrix.CreateOrthographicOffCenter(0, destWidth, destHeight, 0, 0, 1);
#else
renderContext.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
Matrix.CreateOrthographicOffCenter(0, destWidth, destHeight, 0, 0, 1);
#endif
renderContext.View = Matrix.Identity;
renderContext.PushEffect(shader);
renderContext.EnableTextures();
renderContext.SetActiveTexture(source);
renderContext.GraphicsDevice.SetVertexBuffer(_vertexBuffer);
renderContext.GraphicsDevice.Indices = _indexBuffer;
foreach (var pass in shader.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleStrip,
0,
0,
4,
0,
2);
}
renderContext.PopEffect();
renderContext.World = oldWorld;
renderContext.Projection = oldProjection;
renderContext.View = oldView;
if (destination != null)
{
renderContext.PopRenderTarget();
}
}