[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
public class MyGame : Game
{
GraphicsDeviceManager graphics;
ContentManager content;
Effect effect;
VertexPositionColor[] vertices = {
new VertexPositionColor(new Vector3(0, 1, 0), Color.White),
new VertexPositionColor(new Vector3(1, 0, 0), Color.Blue),
new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red)
};
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
effect = content.Load<Effect>("MyEffect");
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionColor.VertexElements
);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent) { content.Unload(); }
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length / 3
);
pass.End();
}
effect.End();
}
}
struct VertexPositionColor
{
float4 Position : POSITION;
float4 Color : COLOR;
};
VertexPositionColor MyVertexShader(VertexPositionColor input)
{
return input;
}
float4 MyPixelShader(float4 color : COLOR) : COLOR
{
if(color.r % 0.1f < 0.05f)
return float4(1,1,1,1);
else
return color;
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}