コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
最近の更新
未作成ページ
おまかせ表示
ヘルプ
MonoBook
検索
検索
ログイン
個人用ツール
ログイン
ログアウトした編集者のページ
もっと詳しく
投稿記録
トーク
「
MonoGameでピクセルシェーダーを使ってテクスチャを貼る
」を編集中 (節単位)
ページ
議論
日本語
閲覧
編集
ソースを編集
履歴表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
編集
ソースを編集
履歴表示
全般
リンク元
関連ページの更新状況
特別ページ
ページ情報
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。
スパム攻撃防止用のチェックです。 けっして、ここには、値の入力は
しない
でください!
== C#で呼び出してみる == 即席[[コード]]なので[[バーテックスバッファー]]と[[インデックスバッファー]]は使用せずにDrawUserPrimitivesメソッドで描画を行っている。 また、「[[MonoGameのカメラを作る]]」で作ったカメラを使っている。Cameraクラスは[[MonoGame]]標準物ではないので注意。<syntaxhighlight lang="csharp"> using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Camera camera; Effect effect; Texture texture; VertexPositionTexture[] vertices = { new VertexPositionTexture(new Vector3( 0, 1, 0), new Vector2(0.5f, 0.0f)), new VertexPositionTexture(new Vector3( 1, 0, 0), new Vector2(1.0f, 1.0f)), new VertexPositionTexture(new Vector3(-1, 0, 0), new Vector2(0.0f, 1.0f)) }; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { IsMouseVisible = true; base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // 即席カメラ camera = new Camera(this); camera.Position = new Vector3(0, -2, 2); camera.Target = new Vector3(0, 0, 0); // テクスチャ読み込み texture = Content.Load<Texture2D>("texture1"); // エフェクト読み込み effect = Content.Load<Effect>("effect1"); } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); // カメラを回転させる camera.Angle += 1f; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // シェーダーのグローバル変数に値をセットする effect.Parameters["myView"].SetValue(camera.View); effect.Parameters["myProjection"].SetValue(camera.Projection); effect.Parameters["myTexture"].SetValue(texture); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { // パス適用開始(シェーダー有効化) pass.Apply(); // 描画 graphics.GraphicsDevice.DrawUserPrimitives( primitiveType: PrimitiveType.TriangleList, vertexData: vertices, vertexOffset: 0, primitiveCount: vertices.Length / 3); } base.Draw(gameTime); } } </syntaxhighlight>
編集内容の要約:
MonoBookへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
MonoBook:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
このページを編集するには、下記の確認用の質問に回答してください (
詳細
):
1たす1は?(全角で入力してください)
キャンセル
編集の仕方
(新しいウィンドウで開きます)
本文の横幅制限を有効化/無効化