[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class Triangle
{
VertexPositionColor[] vertices = new VertexPositionColor[3];
public Triangle(Vector3 p1, Vector3 p2, Vector3 p3, Color color)
{
vertices[0].Position = p1;
vertices[1].Position = p2;
vertices[2].Position = p3;
vertices[0].Color = color;
vertices[1].Color = color;
vertices[2].Color = color;
}
public void Draw(BasicEffect effect)
{
effect.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
effect.GraphicsDevice,
VertexPositionColor.VertexElements);
effect.VertexColorEnabled = true;
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
effect.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleList,
vertices,
0,
1
);
pass.End();
}
effect.End();
}
}
class MyGame : Game
{
GraphicsDeviceManager graphics;
BasicEffect basicEffect;
Triangle whiteTriangle = new Triangle(
new Vector3(0, 1, 1),
new Vector3(1, 0, 1),
new Vector3(-1, 0, 1),
Color.White
);
Triangle blueTriangle = new Triangle(
new Vector3(1, 1, 0),
new Vector3(0, 0, 0),
new Vector3(-1, 1, 0),
Color.Blue
);
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
basicEffect = new BasicEffect(graphics.GraphicsDevice, null);
basicEffect.View = Matrix.CreateLookAt(
new Vector3(0, 0, 3),
new Vector3(0, 0, 0),
new Vector3(0, 1, 0)
);
basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
(float)Window.ClientBounds.Width / Window.ClientBounds.Height,
1, 100
);
}
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.RenderState.StencilEnable = true;
graphics.GraphicsDevice.RenderState.StencilFunction = CompareFunction.Always;
graphics.GraphicsDevice.RenderState.StencilPass = StencilOperation.Replace;
graphics.GraphicsDevice.RenderState.ReferenceStencil = 1;
graphics.GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.None;
graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = false;
whiteTriangle.Draw(basicEffect);
graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
graphics.GraphicsDevice.RenderState.ReferenceStencil = 0;
graphics.GraphicsDevice.RenderState.StencilFunction = CompareFunction.Less;
graphics.GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.All;
blueTriangle.Draw(basicEffect);
}
}
| メンバ名 | 説明 |
| Depth15Stencil1 | 深度バッファは15bitで、ステンシルバッファは1bitです。あわせて16bitです。 |
| Depth16 | 深度バッファは16bitです。 |
| Depth24 | 深度バッファは24bitです。ただし、実際には32bit確保されます。そのうち使える分が24bitということです。 |
| Depth24Stencil4 | 深度バッファは24bitで、ステンシルバッファは4bitです。32bit確保されます。 |
| Depth24Stencil8 | 深度バッファは24bitで、ステンシルバッファは8bitです。Depth24Stensil8Singleとの違いは・・・なんなんでしょう・・・? |
| Depth24Stencil8Single | 深度バッファは24bitで、ステンシルバッファは8bit、あわせて32bitです。 |
| Depth32 | 深度バッファは32bitです。 |
| Unknown | 不明なフォーマットを意味します。 |
| メンバ名 | 説明 |
| Decrement | ステンシル・バッファの値をデクリメントします。0より小さくなったらMaxの値になります。 |
| DecrementSaturation | ステンシル・バッファの値をデクリメントします。ただし、0になるまでです。 |
| Increment | ステンシル・バッファの値をインクリメントします。Maxの値を超えたら0に戻ります。 |
| IncrementSaturation | ステンシル・バッファの値をインクリメントします。ただし、Maxの値になるまでです。 |
| Invert | ステンシル・バッファのビットを反転します。 |
| Keep | ステンシル・バッファの値を書き換えません。デフォルトの値です。 |
| Replace | ステンシル・バッファをRenderState.ReferenceStencilプロパティの値に書き換えます。 |
| Zero | ステンシル・バッファの値を0にセットします。 |