PlayStation Mobile Studio
 PlayStation(R)Mobile SDK 1.21.01

■Playstation Mobile 事始め Prev Top Next
関連ページ:なし


今回から、Playstation Mobileをやります。まずは開発環境構築のため Playstation Mobile SDK をダウンロードします。 以下のサイトでサインインしてからダウンロードしてインストールしてください。

PlayStationMobile Developer Portal

開発言語は C# または VBNet となります。
VBNet使う人はいないと思うので、当サイトでは C# 使うことにします。
Microsoft の Visual Studio とは無関係なようで、PlayStation Mobile Studio だけで開発できます。

インストールが終わったら PlayStation Mobile Studio を起動して、「PlayStation Mobile アプリケーション」で新しいソリューションを作成します。

最低限必要なコードが自動的に作成されているので、そのまま F5 で実行できます。
まあそのままではつまらないので、色つき三角ポリゴンを表示するところまでやります( それでも簡単なんだが... )。

あとシェーダーソースは HLSL ではなく CG になります。


Simple.vcg バーテックスシェーダーのcgファイル
Simple.fcg フラグメントシェーダーのcgファイル
AppMain.cs main関数があるソースファイル


---Simple.vcg---  ↑

// バーテックスシェーダー

void main( float3 in a_Position  : POSITION,
           float4 in a_Color     : COLOR0,
           float4 out v_Position : POSITION,
           float4 out v_Color    : COLOR0,
           uniform float4x4 WorldViewProj
                  )
{
   v_Position = mul( float4( a_Position, 1 ), WorldViewProj );
   v_Color = a_Color;
}

---Simple.fcg---  ↑

// フラグメントシェーダー( Direct3Dでいうところのピクセルシェーダー )

void main( float4 in v_Color  : COLOR0,
           float4 out Color   : COLOR )
{
   Color = v_Color;
}

---AppMain.cs---  ↑

using System;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;

namespace PSM_Samples
{
   public class AppMain : IDisposable
   {
      const int Width = 800;
      const int Height = 480;

      private static GraphicsContext graphics;
      private static ShaderProgram shader;
      private static VertexBuffer triangles;

      private static float rotationY;
      private static Matrix4 matWVP;

      public static void Main (string[] args)
      {
         Initialize ();

         while (true) 
         {
            SystemEvents.CheckEvents ();
            Update ();
            Render ();
         }
      }

      // 初期化
      public static void Initialize ()
      {
         // フレームバッファの解像度はウィンドウの解像度と同じサイズにする
         graphics = new GraphicsContext( Width, Height, PixelFormat.Rgba, PixelFormat.Depth16, MultiSampleMode.None );

         // シェーダーの作成
         // cgxはvcgとfcgをコンパイル後、結合したcgファイルらしい
         // パスは固定でないとだめ?
         shader = new ShaderProgram("/Application/shaders/Simple.cgx" );

         // アトリビュート変数( 頂点バッファから渡される変数 )の変数名とインデックスの関連付け
         shader.SetAttributeBinding( 0, "a_Position" );
         shader.SetAttributeBinding( 1, "a_Color" );
         // ユニフォーム変数( Direct3Dでいうところの定数バッファ )の変数名とインデック値の関連付け
         shader.SetUniformBinding( 0, "WorldViewProj" );

         // 頂点バッファ作成
         triangles = new VertexBuffer( 3, VertexFormat.Float3, VertexFormat.Float4 );
         // 頂点座標を設定
         triangles.SetVertices( 0,                     // エレメント0
                           new float[]{  0f,  20f, 0f,
                                       -20f, -20f, 0f,
                                        20f, -20f, 0f } );
         // 頂点カラーを設定
         triangles.SetVertices( 1,                     // エレメント1
                            new float[]{ 1f, 0f, 0f, 1f,
                                         0f, 1f, 0f, 1f,
                                         0f, 0f, 1f, 1f } );

         rotationY = 0;
      }

      public void Dispose()
      {
         triangles.Dispose();
         shader.Dispose();
         graphics.Dispose();
      }

      // フレーム更新処理
      public static void Update ()
      {
         rotationY += 0.01f;
         if( rotationY > (float)FMath.PI * 2.0f )
            rotationY -= (float)FMath.PI * 2.0f;

         // ワールド行列
         Matrix4 matRotationY = Matrix4.RotationY( rotationY );
         Matrix4 matTranslation = Matrix4.Translation( 0.0f, 0.0f, -100.0f );  // OpenGL は右手座標系のためZ値が負の数となる )
         Matrix4 matWorld = matTranslation * matRotationY;  // 積算方向が右から左へ

         // 射影行列
         Matrix4 matProj = Matrix4.Perspective( (float)FMath.PI / 5.0f, (float)Width / (float)Height, 10.0f, 1000.0f );

         matWVP = matProj * matWorld;
      }

      // レンダリング
      public static void Render ()
      {
         graphics.SetClearColor (0.2f, 0.2f, 1, 1 );
         // 描画用フレームバッファ( Direct3Dでいうところのバックバッファ )をクリア
         graphics.Clear ();

         // カリングモードを有効にする
         graphics.Enable( EnableMode.CullFace, true );
         // 反時計回りで裏面となるポリゴンを描画しない
         graphics.SetCullFace( CullFaceMode.Back, CullFaceDirection.Ccw );

         // ブレンドモードを無効にする
         graphics.Enable( EnableMode.Blend, false );

         // 深度テストを無効にする
         graphics.Enable( EnableMode.DepthTest, false );

         // ユニフォーム変数をシェーダーに設定
         shader.SetUniformValue( 0, ref matWVP );

         // シェーダーを設定
         graphics.SetShaderProgram( shader );

         // 頂点バッファを設定
         graphics.SetVertexBuffer( 0, triangles );

         // レンダリング
         graphics.DrawArrays( DrawMode.Triangles, 0, triangles.VertexCount );

         // スワップ
         graphics.SwapBuffers ();
      }
   }
}

OpenGL ベースとなるため、いろいろ変更があります。

たいしたことやってないのですが、最初はこんなもんでしょうね。


Prev Top Next
inserted by FC2 system