本文整理汇总了C#中Texture2D类的典型用法代码示例。如果您正苦于以下问题:C# Texture2D类的具体用法?C# Texture2D怎么用?C# Texture2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Texture2D类属于命名空间,在下文中一共展示了Texture2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadResources
public void LoadResources()
{
if (m_Disposed == true)
{
Buffer = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
{
Format = m_Format,
Width = m_Width,
Height = m_Height,
OptionFlags = ResourceOptionFlags.None,
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default
});
View = new RenderTargetView(GameEnvironment.Device, Buffer);
ResourceView = new ShaderResourceView(GameEnvironment.Device, Buffer);
Viewport = new Viewport(0, 0, Buffer.Description.Width, Buffer.Description.Height);
m_Disposed = false;
}
}
示例2: AddTextureAsset
public void AddTextureAsset(String path, Object user, Int32 u, Int32 v)
{
if (String.IsNullOrWhiteSpace(path))
throw new ArgumentException();
if (user == null)
throw new ArgumentNullException();
Vector2i tiles = new Vector2i(u, v);
if (TextureAssetsByUsers.ContainsKey(path))
{
if (TextureAssetsByUsers[path].TextureInfo.NumTiles != tiles)
throw new ArgumentException("Duplicate texture asset with different tiles: " + path);
TextureAssetsByUsers[path].AddUser(user);
}
else
{
Texture2D t = new Texture2D(path, false);
TextureInfo ti = new TextureInfo(t, tiles);
TextureAssetsByUsers[path] = new TextureUsers(ti, user);
}
}
示例3: TitleScene
public TitleScene()
{
this.Camera.SetViewFromViewport();
_texture = new Texture2D("Application/images/title.png",false);
_ti = new TextureInfo(_texture);
SpriteUV titleScreen = new SpriteUV(_ti);
titleScreen.Scale = _ti.TextureSizef;
titleScreen.Pivot = new Vector2(0.5f,0.5f);
titleScreen.Position = new Vector2(Director.Instance.GL.Context.GetViewport().Width/2,
Director.Instance.GL.Context.GetViewport().Height/2);
this.AddChild(titleScreen);
Vector4 origColor = titleScreen.Color;
titleScreen.Color = new Vector4(0,0,0,0);
var tintAction = new TintTo(origColor,10.0f);
ActionManager.Instance.AddAction(tintAction,titleScreen);
tintAction.Run();
_titleSong = new Bgm("/Application/audio/titlesong.mp3");
if(_songPlayer != null)
_songPlayer.Dispose();
_songPlayer = _titleSong.CreatePlayer();
Scheduler.Instance.ScheduleUpdateForTarget(this,0,false);
// Clear any queued clicks so we dont immediately exit if coming in from the menu
Touch.GetData(0).Clear();
}
示例4: MakePixel
public static Texture2D MakePixel(Color color)
{
Texture2D tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
tex.SetPixel(0, 0, color);
tex.Apply();
return tex;
}
示例5: Sprite
public Sprite(GraphicsContext graphics, Texture2D texture)
{
if(shaderProgram == null)
{
shaderProgram = new ShaderProgram("/Application/shaders/Sprite.cgx");
shaderProgram.SetUniformBinding(0, "u_WorldMatrix");
}
if (texture == null)
{
throw new Exception("ERROR: texture is null.");
}
this.graphics = graphics;
this.texture = texture;
this.width = texture.Width;
this.height = texture.Height;
indices = new ushort[indexSize];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 3;
vertexBuffer = new VertexBuffer(4, indexSize, VertexFormat.Float3,
VertexFormat.Float2, VertexFormat.Float4);
}
示例6: TextureAtlas
public TextureAtlas(string filename)
{
sprites = new Dictionary<string, Bounds2>();
sizes = new Dictionary<string, Vector2i>();
XDocument doc = XDocument.Load(filename + ".xml");
var lines = from sprite in doc.Root.Elements("sprite")
select new
{
Name = sprite.Attribute("n").Value,
X1 = (float)sprite.Attribute("x"),
Y1 = (float)sprite.Attribute("y"),
Height = (float)sprite.Attribute("h"),
Width = (float)sprite.Attribute("w")
};
texAtlas = new Texture2D(filename + ".png", false);
texAtlasInfo = new TextureInfo(texAtlas);
foreach (var curLine in lines)
{
sprites.Add(curLine.Name, new Bounds2(new Vector2(curLine.X1 / texAtlas.Width, 1 - (curLine.Y1 / texAtlas.Height)), new Vector2((curLine.X1 + curLine.Width) / texAtlas.Width, 1 -((curLine.Y1 + curLine.Height) / texAtlas.Height))));
sizes.Add(curLine.Name, new Vector2i((int)curLine.Width, (int)curLine.Height));
}
}
示例7: LoadContent
protected override void LoadContent()
{
tex = Content.Load<Texture2D>("Logo.jpg");
mouse = Content.Load<Texture2D>("Mouse.png");
BasicFont = this.Content.Load<SpriteFont>("wryh");
base.LoadContent();
}
示例8: FighterCarrier
public FighterCarrier(Texture2D texture, Vector2 location, SpriteBatch spriteBatch, Texture2D droneTexture, bool isAlly)
: base(texture, location, spriteBatch, isAlly)
{
//UseCenterAsOrigin = true;
//Init drones
if (!StateManager.NetworkData.IsMultiplayer)
{
Drones.Add(new Drone(droneTexture, location, spriteBatch, this) { DroneState = CoreTypes.DroneState.Stowed });
Drones[0].Rotation.Radians = MathHelper.Pi;
Drones.Add(new Drone(droneTexture, location, spriteBatch, this) { DroneState = CoreTypes.DroneState.Stowed });
Drones[1].Rotation.Radians = MathHelper.TwoPi;
StateManager.InputManager.DebugControlManager.DroneSuicide += new EventHandler<DroneEventArgs>(DebugControlManager_DroneSuicide);
}
//BulletTexture = GameContent.Assets.Images.Ships.Bullets[ShipType.FighterCarrier, ShipTier.Tier1];
DelayBetweenShots = TimeSpan.FromMilliseconds(100);
DamagePerShot = 2;
_initHealth = 100;
MovementSpeed = Vector2.One * 2f;
this.TierChanged += new EventHandler(FighterCarrier_TierChanged);
DamagePerShot = 2;
this.PlayerType = PlayerType.Ally;
ShootSound = GameContent.Assets.Sound[SoundEffectType.FighterCarrierFire];
}
示例9: UserTexture
/// <summary>
/// Creates texture from file in memory
/// </summary>
/// <param name="rs"></param>
/// <param name="texture"></param>
public UserTexture ( RenderSystem rs, byte[] data, bool forceSRgb )
{
this.texture = new Texture2D( rs.Device, data, forceSRgb );
this.Width = texture.Width;
this.Height = texture.Height;
this.Srv = texture;
}
示例10: OnInit
protected override void OnInit(object sender, EventArgs e)
{
//OdysseyUI.RemoveHooks(Global.FormOwner);
ImageLoadInformation imageLoadInfo = new ImageLoadInformation()
{
BindFlags = BindFlags.None,
CpuAccessFlags = CpuAccessFlags.Read,
FilterFlags = FilterFlags.None,
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
MipFilterFlags = FilterFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Staging,
MipLevels = 1
};
// Make texture 3D
Texture2D sourceTexture = Texture2D.FromFile(Game.Context.Device, "medusa.jpg", imageLoadInfo);
stereoTexture = Stereo.Make3D(sourceTexture);
backBuffer = Game.Context.GetBackBuffer();
stereoSourceBox = new ResourceRegion
{
Front = 0,
Back = 1,
Top = 0,
Bottom = Game.Context.Settings.ScreenHeight,
Left = 0,
Right = Game.Context.Settings.ScreenWidth
};
}
示例11: SimpleSprite
/// <summary>コンストラクタ。</summary>
public SimpleSprite(GraphicsContext graphics, Texture2D texture)
{
if(shaderProgram == null)
{
shaderProgram=CreateSimpleSpriteShader();
}
if (texture == null)
{
throw new Exception("ERROR: texture is null.");
}
this.graphics = graphics;
this.texture = texture;
this.width = texture.Width;
this.height = texture.Height;
indices = new ushort[indexSize];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 3;
//@e Vertex coordinate, Texture coordinate, Vertex color
//@j 頂点座標, テクスチャ座標, 頂点色
vertexBuffer = new VertexBuffer(4, indexSize, VertexFormat.Float3, VertexFormat.Float2, VertexFormat.Float4);
}
示例12: DiscTexture
/// <summary>
///
/// </summary>
/// <param name="rs"></param>
/// <param name="texture"></param>
private DiscTexture ( RenderSystem rs, Texture2D texture )
{
this.texture = texture;
this.Width = texture.Width;
this.Height = texture.Height;
this.Srv = texture;
}
示例13: Skybox
public Skybox(GraphicsDevice device)
{
float x = 0.525731f;
float z = 0.850651f;
var vertices = new SkyboxVertex[12]
{
new SkyboxVertex(-x, 0f, z), new SkyboxVertex(x, 0f, z),
new SkyboxVertex(-x, 0f, -z), new SkyboxVertex(x, 0f, -z),
new SkyboxVertex(0f, z, x), new SkyboxVertex(0f, z, -x),
new SkyboxVertex(0f, -z, x), new SkyboxVertex(0f, -z, -x),
new SkyboxVertex(z, x, 0f), new SkyboxVertex(-z, x, 0f),
new SkyboxVertex(z, -x, 0f), new SkyboxVertex(-z, -x, 0f),
};
var indices = new int[60]
{
1,4,0, 4,9,0, 4,5,9, 8,5,4, 1,8,4,
1,10,8, 10,3,8, 8,3,5, 3,2,5, 3,7,2,
3,10,7, 10,6,7, 6,11,7, 6,0,11, 6,1,0,
10,1,6, 11,0,9, 2,11,9, 5,2,9, 11,2,7
};
vertexBuffer = Buffer<SkyboxVertex>.New(device, vertices, BufferFlags.VertexBuffer);
indexBuffer = Buffer<int>.New(device, indices, BufferFlags.IndexBuffer);
skyboxEffect = EffectLoader.Load(@"Graphics/Shaders/Skybox.fx");
skyboxTex = Texture2D.Load(device, @"G:\Users\Athrun\Documents\Stratum\trunk\src\Stratum\WorldEngine\Earth\milkyWay.tif");
}
示例14: TextureFactory
public TextureFactory(Engine engine)
{
_missingTexture = engine.Content.Load<Texture2D>("Textures\\missing-texture");
_landCache = new Cache<int, Texture2D>(TimeSpan.FromMinutes(5), 0x1000);
_lastCacheClean = DateTime.MinValue;
_textures = new Textures(engine);
}
示例15: LoadContent
protected override void LoadContent()
{
texture = game.Content.Load<Texture2D>(textureFilename);
origin.X = texture.Width / 2;
origin.Y = texture.Height / 2;
base.LoadContent();
}