*XNA [#hd6ed4ec] このページの情報は古いです。 2008年頃の情報です。 [[Wikipedia:XNA:http://ja.wikipedia.org/wiki/Microsoft_XNA]] ---- #contents ** 初期設定 [#hfdb116f] XNAのバージョン2.0くらい。 - インストールするもの - Visual C# 2005 Express Edition(Visual studio2005が無い人) XNA Game Studio - Visual C# 2005 Express Edition http://www.microsoft.com/japan/msdn/vstudio/express/past/2005/ - XNA Game Studio 2.0 http://www.microsoft.com/downloads/details.aspx?FamilyId=DF80D533-BA87-40B4-ABE2-1EF12EA506B7&displaylang=en - プロジェクトの作成 Visual C# を起動。 [ファイル]タブ -> [新しいプロジェクト] -> 左側の[プロジェクトの種類]をXNA Game Studio 2.0に -> 右側の[Windows Game(2.0)]を選択 -> OK あとは普通にビルドすれば青い画面が表示されるはずです。 ** Vsync同期をOFFにする [#ld52e0ab] GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false; ** パフォーマンス計測 [#m195c67b] System.Diagnostics.Stopwatch Stopwatch = new System.Diagnostics.Stopwatch(); Stopwatch.Start(); /// コード Stopwatch.End(); float time = Stopwatch.ElapsedTicks / (float)(System.Diagnostics.Stopwatch.Frequency * (1.0f / 60.0f)) * 100.0f; ** カリング面の変更 [#n73b748b] GraphicsDevice.RenderState.CullMode = ; // モードの種類 CullMode.CullCounterClockwiseFace; CullMode.CullClockwiseFace; CullMode.None; ** 深度バッファ(Zバッファ)をONにする [#cc1b5428] GraphicsDevice.RenderState.DepthBufferEnable = true; ** ポリゴンの描画 [#y59313f3] XNAのバージョン2.0くらい。 - 変数 VertexDeclaration m_VertexDeclaration = null; // 頂点データ定義 VertexPositionColor[] m_Vertices = null; // 頂点データ BasicEffect m_BasicEffect = null; // シェーダ - コンストラクタ // 頂点データ定義 m_VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements); // 頂点データ m_Vertices = new VertexPositionColor[3]; m_Vertices[0] = new VertexPositionColor(new Vector3(0.0f, 3.0f, 0.0f), Color.Red); m_Vertices[1] = new VertexPositionColor(new Vector3(3.0f, -2.0f, 0.0f), Color.Blue); m_Vertices[2] = new VertexPositionColor(new Vector3(-3.0f, -2.0f, 0.0f), Color.Green); // 基本シェーダ m_BasicEffect = new BasicEffect(GraphicsDevice, null); m_BasicEffect.VertexColorEnabled = true; - 描画 // 頂点データの定義 GraphicsDevice.VertexDeclaration = m_VertexDeclaration; // ViewMatrix m_BasicEffect.View = Matrix.CreateLookAt( new Vector3(0.0f, 0.0f, 10.0f), // pos Vector3.Zero, // view Vector3.Up // upper ); // Projection m_BasicEffect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), // pers (float)GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height, // aspect 1.0f, // near 100.0f // far ); // begin effect m_BasicEffect.Begin(); // パスの数だけ描画 foreach (EffectPass pass in m_BasicEffect.CurrentTechnique.Passes) { pass.Begin(); // ポリゴンを描画する GraphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleList, // 描画モード m_Vertices, // 頂点データ 0, // 1 // ポリゴン枚数 ); pass.End(); } m_BasicEffect.End(); ** Tips [#af351901] |