本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.SamplerState类的典型用法代码示例。如果您正苦于以下问题:C# SamplerState类的具体用法?C# SamplerState怎么用?C# SamplerState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SamplerState类属于Microsoft.Xna.Framework.Graphics命名空间,在下文中一共展示了SamplerState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvalidOperationException
/// <summary>
/// Begins a new sprite and text batch with the specified render state.
/// </summary>
/// <param name="sortMode">The drawing order for sprite and text drawing. <see cref="SpriteSortMode.Deferred"/> by default.</param>
/// <param name="blendState">State of the blending. Uses <see cref="BlendState.AlphaBlend"/> if null.</param>
/// <param name="samplerState">State of the sampler. Uses <see cref="SamplerState.LinearClamp"/> if null.</param>
/// <param name="depthStencilState">State of the depth-stencil buffer. Uses <see cref="DepthStencilState.None"/> if null.</param>
/// <param name="rasterizerState">State of the rasterization. Uses <see cref="RasterizerState.CullCounterClockwise"/> if null.</param>
/// <param name="effect">A custom <see cref="Effect"/> to override the default sprite effect. Uses default sprite effect if null.</param>
/// <param name="transformMatrix">An optional matrix used to transform the sprite geometry. Uses <see cref="Matrix.Identity"/> if null.</param>
/// <exception cref="InvalidOperationException">Thrown if <see cref="Begin"/> is called next time without previous <see cref="End"/>.</exception>
/// <remarks>This method uses optional parameters.</remarks>
/// <remarks>The <see cref="Begin"/> Begin should be called before drawing commands, and you cannot call it again before subsequent <see cref="End"/>.</remarks>
public void Begin
(
SpriteSortMode sortMode = SpriteSortMode.Deferred,
BlendState blendState = null,
SamplerState samplerState = null,
DepthStencilState depthStencilState = null,
RasterizerState rasterizerState = null,
Effect effect = null,
Matrix? transformMatrix = null
)
{
if (_beginCalled)
throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
// defaults
_sortMode = sortMode;
_blendState = blendState ?? BlendState.AlphaBlend;
_samplerState = samplerState ?? SamplerState.LinearClamp;
_depthStencilState = depthStencilState ?? DepthStencilState.None;
_rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
_effect = effect;
_matrix = transformMatrix ?? Matrix.Identity;
// Setup things now so a user can change them.
if (sortMode == SpriteSortMode.Immediate)
{
Setup();
}
_beginCalled = true;
}
示例2: DrawSkybox
private void DrawSkybox()
{
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Clamp;
ss.AddressV = TextureAddressMode.Clamp;
Engine.Video.GraphicsDevice.SamplerStates[0] = ss;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
Engine.Video.GraphicsDevice.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
int i = 0;
foreach(ModelMesh mesh in skyboxModel.Meshes) {
foreach(Effect currentEffect in mesh.Effects) {
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index];
currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
currentEffect.Parameters["xView"].SetValue(camera.ViewMatrix);
currentEffect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]);
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
Engine.Video.GraphicsDevice.DepthStencilState = dss;
}
示例3: DrawTerrainAsset
public void DrawTerrainAsset(TerrainBlock asset)
{
SamplerState s = new SamplerState();
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
s.AddressU = TextureAddressMode.Wrap; s.AddressV = TextureAddressMode.Wrap;
Game.GraphicsDevice.SamplerStates[0] = s;
Game.GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None };
//effect.FogEnabled = true;
//effect.FogStart = 120f;
//effect.FogEnd = 150f;
//effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.TextureEnabled = true;
effect.Texture = asset.GetTexture();
effect.EnableDefaultLighting();
effect.AmbientLightColor = new Vector3(0.5f, 0.5f, 0.5f);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
game.GraphicsDevice.SetVertexBuffer(asset.GetVertexBuffer());
game.GraphicsDevice.Indices = asset.GetIndexBuffer();
game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, asset.GetVerticesLength(), 0, asset.GetIndicesLength() / 3);
}
//base.Draw(gameTime);
}
示例4: ImperativeRenderer
public ImperativeRenderer(
IBatchContainer container,
DefaultMaterialSet materials,
int layer = 0,
RasterizerState rasterizerState = null,
DepthStencilState depthStencilState = null,
BlendState blendState = null,
SamplerState samplerState = null,
bool worldSpace = true,
bool useZBuffer = false,
bool autoIncrementSortKey = false,
bool autoIncrementLayer = false
)
{
if (container == null)
throw new ArgumentNullException("container");
if (materials == null)
throw new ArgumentNullException("materials");
Container = container;
Materials = materials;
Layer = layer;
RasterizerState = rasterizerState;
DepthStencilState = depthStencilState;
BlendState = blendState;
SamplerState = samplerState;
UseZBuffer = useZBuffer;
WorldSpace = worldSpace;
AutoIncrementSortKey = autoIncrementSortKey;
AutoIncrementLayer = autoIncrementLayer;
NextSortKey = 0;
PreviousBatch = null;
}
示例5: draw
public void draw(Matrix view, Matrix projection, Vector3 playerPosition)
{
SamplerState samplerState = new SamplerState();
samplerState.AddressU = TextureAddressMode.Clamp;
samplerState.AddressV = TextureAddressMode.Clamp;
Game1.getGraphics().GraphicsDevice.SamplerStates[0] = samplerState;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
Game1.getGraphics().GraphicsDevice.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
foreach (ModelMesh mesh in skyboxModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(playerPosition);
//effect.CurrentTechnique = effect.Techniques["Textured"];
effect.LightingEnabled = true;
effect.AmbientLightColor = new Vector3(1f, 1f, 1f);
effect.EmissiveColor = new Vector3(0.4f, 0.4f, 0.4f);
effect.TextureEnabled = true;
effect.Texture = skyboxTextures;
effect.World = worldMatrix;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
Game1.getGraphics().GraphicsDevice.DepthStencilState = dss;
}
示例6: draw
public override void draw(Matrix projection, Matrix camera)
{
SamplerState samplerState = new SamplerState();
samplerState.AddressU = TextureAddressMode.Clamp;
samplerState.AddressV = TextureAddressMode.Clamp;
Game1.getGraphics().GraphicsDevice.SamplerStates[0] = samplerState;
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.LightingEnabled = true;
effect.AmbientLightColor = new Vector3(1f, 1f, 1f);
effect.EmissiveColor = new Vector3(1, 1, 1);
//effect.DirectionalLight0.Enabled = true;
effect.DirectionalLight0.Direction = new Vector3(0, 1, 0);
effect.DirectionalLight0.DiffuseColor = new Vector3(1, 0, 0);
//effect.DirectionalLight1.Direction = new Vector3(1, 1, 0);
//effect.DirectionalLight1.DiffuseColor = new Vector3(0, 1, 0);
effect.TextureEnabled = true;
effect.Texture = textur;
effect.View = camera;
effect.Projection = projection;
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY((float)rotation) * Matrix.CreateScale((float)0.5) * Matrix.CreateTranslation(position);
}
mesh.Draw();
}
}
示例7: TagRenderer
public TagRenderer(int tag)
{
Tag = tag;
BlendState = BlendState.AlphaBlend;
SamplerState = SamplerState.LinearClamp;
Camera = new Camera();
}
示例8: EffectState
public EffectState(Effect effect, SamplerState sampler, RasterizerState raster, DepthStencilState stencil, bool texture)
{
Effect = effect;
Sampler = sampler;
Raster = raster;
TextureOverride = texture;
}
示例9: DrawSkybox
public void DrawSkybox(Camera camera, Vector3 shipPosition)
{
//A TextureAddressMode.Clamp state removes the seams between the cube.
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Clamp;
ss.AddressV = TextureAddressMode.Clamp;
_device.SamplerStates[0] = ss;
//Removes the ZBuffer so no size can be set for the skybox.
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
_device.DepthStencilState = dss;
Matrix[] transforms = new Matrix[_skyboxModel.Bones.Count]; //Represents the position of each model bone.
_skyboxModel.CopyAbsoluteBoneTransformsTo(transforms); //Models have a method that populates an array.
foreach (ModelMesh mesh in _skyboxModel.Meshes)
{
//BasicEffect is a simplified version of it's parent class Effect. Effects allow objects to be placed on screen.
foreach (BasicEffect basicEffect in mesh.Effects)
{
basicEffect.Projection = camera.Projection;
basicEffect.View = camera.View;
basicEffect.World = Matrix.CreateScale(80) * mesh.ParentBone.Transform * Matrix.CreateTranslation(shipPosition); //Positions the mesh in the correct place relavent to the world.
}
mesh.Draw();
}
//Reenabling the ZBuffer.
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
_device.DepthStencilState = dss;
}
示例10: TagExcludeRenderer
public TagExcludeRenderer(int excludeTag)
{
ExcludeTag = excludeTag;
BlendState = BlendState.AlphaBlend;
SamplerState = SamplerState.LinearClamp;
Camera = new Camera();
}
示例11: DrawPolygons
public void DrawPolygons(Vector2 position, float angle, float scale,
Texture2D texture, VertexPositionTexture[] vertices, BlendState blendMode)
{
effect.World = Matrix.CreateRotationZ(angle) *
Matrix.CreateScale(scale) *
Matrix.CreateTranslation(new Vector3(position, 0));
effect.Texture = texture;
GraphicsDevice device = GameEngine.Instance.GraphicsDevice;
if (blendMode == BlendState.AlphaBlend)
{
device.BlendState = BlendState.AlphaBlend;
}
else if (blendMode == BlendState.Additive)
{
device.BlendState = BlendState.Additive;
}
SamplerState s = new SamplerState();
s.AddressU = TextureAddressMode.Wrap;
s.AddressV = TextureAddressMode.Wrap;
device.SamplerStates[0] = s;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
//pass.Apply();
}
}
示例12: Draw
/// <summary>
/// Does the actual drawing of the skybox with our skybox effect.
/// There is no world matrix, because we're assuming the skybox won't
/// be moved around. The size of the skybox can be changed with the size
/// variable.
/// </summary>
/// <param name="view">The view matrix for the effect</param>
/// <param name="projection">The projection matrix for the effect</param>
/// <param name="cameraPosition">The position of the camera</param>
public override void Draw(GameTime gameTime)
{
GraphicsDevice device = game.GraphicsDevice;
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Clamp;
ss.AddressV = TextureAddressMode.Clamp;
device.SamplerStates[0] = ss;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
device.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
int i = 0;
foreach (ModelMesh mesh in skyboxModel.Meshes)
{
foreach (BasicEffect currentEffect in mesh.Effects)
{
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(camera.position);
currentEffect.World = worldMatrix;
currentEffect.View = camera.view;
currentEffect.Projection = camera.projection;
currentEffect.TextureEnabled=true;
currentEffect.Texture = skyboxTextures[i++];
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
device.DepthStencilState = dss;
}
示例13: Start
/// <summary>
/// Starts the specified batch.
/// </summary>
/// <param name="batch">The batch.</param>
/// <param name="useCamera">if set to <c>true</c> camera matrix will be applied.</param>
/// <param name="sortMode">The sort mode.</param>
/// <param name="blendState">State of the blend.</param>
/// <param name="samplerState">State of the sampler.</param>
/// <param name="depthStencilState">State of the depth stencil.</param>
/// <param name="rasterizerState">State of the rasterizer.</param>
/// <param name="effect">The effect.</param>
/// <param name="transform">The transformation matrix.</param>
public static void Start(this SpriteBatch batch,
bool useCamera = false,
SpriteSortMode sortMode = SpriteSortMode.Deferred,
BlendState blendState = null,
SamplerState samplerState = null,
DepthStencilState depthStencilState = null,
RasterizerState rasterizerState = null,
Effect effect = null,
Matrix? transform = null)
{
Matrix matrix = AlmiranteEngine.IsWinForms ? Matrix.Identity : AlmiranteEngine.Settings.Resolution.Matrix;
if (useCamera)
{
matrix = AlmiranteEngine.Camera.Matrix * matrix;
}
if (transform.HasValue)
{
matrix = transform.Value * matrix;
}
BatchExtensions._sortMode = sortMode;
BatchExtensions._blendState = blendState;
BatchExtensions._samplerState = samplerState;
BatchExtensions._depthStencilState = depthStencilState;
BatchExtensions._rasterizerState = rasterizerState;
BatchExtensions._effect = effect;
BatchExtensions._matrix = matrix;
batch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix);
}
示例14: DownColorTexture
/// <summary>
/// DownSample a Color Texture (using hardware Linear filtering, cant be used on Single/float Textures)
/// </summary>
/// <param name="render">The render.</param>
/// <param name="Texture2D">The texture2 D.</param>
/// <param name="SamplerState">State of the sampler.</param>
/// <returns></returns>
public Texture2D DownColorTexture(RenderHelper render, Texture2D Texture2D, SamplerState SamplerState)
{
render.PushRenderTarget(RenderTarget2D);
render.RenderTextureComplete(Texture2D, Color.White,
Rectangle, Matrix.Identity, Texture2D.Bounds,
true, SpriteSortMode.Deferred, SamplerState);
return render.PopRenderTargetAsSingleRenderTarget2D();
}
示例15: Draw
public override void Draw(GraphicsDevice device, Camera camera)
{
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Wrap;
ss.AddressV = TextureAddressMode.Wrap;
device.SamplerStates[0] = ss;
base.Draw(device, camera);
}