public class GameMain : Microsoft.Xna.Framework.Game
{
private GraphicsDeviceManager graphics;
private VertexDeclaration dec;
private BasicEffect effect;
private Graphics2D graph;
public GameMain()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
graph = new Graphics2D(Content, "test");
effect = new BasicEffect(GraphicsDevice, null);
effect.TextureEnabled = true;
dec = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.VertexElements);
base.Initialize();
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.VertexDeclaration = dec;
GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
texture.Draw(GraphicDevice, effect);
pass.End();
}
effect.End();
base.Draw(gameTime);
}
static void Main(string[] args)
{
using (Game game = new GameMain()) game.Run();
}
}
public class Graphics2D
{
private Texture2D texture;
private VertexPosition[] texture;
public Graphics2D(ContentManager content, string name)
{
texture = content.Load(name);
vertex = new VertexPositionTexture[] {
new VertexPositionTexture(new Vector3(-0.5F, 0.5F, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3( 0.5F, 0.5F, 0), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3( 0.5F, -0.5F, 0), new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(-0.5F, 0.5F, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3( 0.5F, 0.5F, 0), new Vector2(1, 0))
new VertexPositionTexture(new Vector3(-0.5F, -0.5F, 0), new Vector2(0, 1))
};
}
public void Draw(GraphicsDevice graphics, BasicEffect effect)
{
effect.Texture = texture;
graphics.DrawUserPrimitives(PrimitiveType.TriangleList, vertex, 0, 2);
}
}
public class GameMain : Microsoft.Xna.Framework.Game
{
private GraphicsDeviceManager graphics;
private VertexDeclaration dec;
private BasicEffect effect;
private VertexBuffer squareVertex;
private IndexBuffer indexBuffer;
private short[] indices;
private Graphics2D graph;
public GameMain()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
var vertex = new VertexPositionTexture[] {
new VertexPositionTexture(new Vector3(-0.5F, 0.5F, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3( 0.5F, 0.5F, 0), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3( 0.5F, -0.5F, 0), new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(-0.5F, -0.5F, 0), new Vector2(0, 1))
};
indices = new short[] {0, 1, 2, 0, 2, 3};
squareVertex = new VertexBuffer(GraphicsDevice, VertexPositionTexture.SizeInBytes * vertex.Length, BufferUsage.None);
squareVertex.SetData(vertex);
indexBuffer = new IndexBuffer(GraphicsDevice, sizeof(short) * indices.Length, BufferUsage.None, IndexElementSize.SixteenBits);
indexBuffer.SetData(indices);
graph = new Graphics2D(Content, "test");
effect = new BasicEffect(GraphicsDevice, null);
effect.TextureEnabled = true;
dec = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.VertexElements);
base.Initialize();
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.VertexDeclaration = dec;
GraphicsDevice.Vertices[0].SetSource(squareVertex, 0, VertexPositionTexture.SizeInBytes);
GraphicsDevice.Indices = indexBuffer;
GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
effect.Texture = graph.Texture;
effect.CommitChanges();
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
pass.End();
}
effect.End();
base.Draw(gameTime);
}
static void Main(string[] args)
{
using (Game game = new GameMain()) game.Run();
}
}
public class Graphics2D
{
private Texture2D texture;
public Graphics2D(ContentManager content, string name)
{
texture = content.Load(name);
}
public Texture2D Texture
{
get { return texture; }
}
}


Author:銀之助
画像はTWにおける自キャラ
とりあえずメッセ
glow_of_the_sky@hotmail.com