2011-07-02 14 views
0

を描かれている頂点にテクスチャや色を見ることができません。は、私がOpenTKに次のコードを持っている

 unsafe 
     { 
      Vector3* data = (Vector3*)Marshal.AllocHGlobal(
            Marshal.SizeOf(typeof(Vector3)) * simpleVertices.Count); 
      Vector2* uv = (Vector2*)Marshal.AllocHGlobal(
            Marshal.SizeOf(typeof(Vector2)) * simpleVertices.Count); 
      for(int i = 0; i < simpleVertices.Count; i++) 
      { 
       ((Vector3*)data)[i] = simpleVertices[i]; 
       Vector2 thisuv = uvData[i]; 
       ((Vector2*)uv)[i] = uvData[i]; 

      } 

      GL.BindTexture(All.Texture2D, texture.GLTexture.OpenGLName); 
      GL.TexParameter(All.Texture2D, All.TextureWrapS, (int)TextureWrapMode.Repeat); 
      GL.TexParameter(All.Texture2D, All.TextureWrapT, (int)TextureWrapMode.Repeat); 

      byte []squareColors = new byte[simpleVertices.Count]; 
      Random.NextBytes(squareColors); 

      GL.ColorPointer (vertices.Count, All.UnsignedByte, 0, squareColors); 

      GL.VertexPointer(3, All.Float, sizeof(Vector3), new IntPtr(data)); 
      GL.DrawArrays(All.Triangles, 0, simpleVertices.Count); 


      Marshal.FreeHGlobal((IntPtr)data); 
      Marshal.FreeHGlobal((IntPtr)uv); 
     } 

私は(少なくとも彼らは私のXNAレンダラで正常に動作正しいanduv頂点のために与えられているデータを知っています)私が見ているのは、画面上に正しく描画された白いポリゴンです。

上記のコードから、squareColoursにランダムなバイト数が設定されているので色の組み合わせが表示されるはずです(私はsquareColorsがランダムなバイトでいっぱいになっていることを確認しました)が、頂点はすべて白として描画されます。

また、(GL.BindTextureを介して)テクスチャをバインドしようとしましたが、これも失敗しました。

これはなぜ機能しないのでしょうか?

編集:私は色を有効にするために追加した(この記事の最初のコメントを参照)アプリは、以下の出力で出墜落:

スタックトレース:

(ラッパー管理ツーネイティブ)で OpenTK.Graphics.ES11.GL/Core.DrawArrays(OpenTK.Graphics.ES11.All、INT、INT) OpenTK.Graphics.ES11.GL.DrawArrays(OpenTK.Graphics.ES11.All、INT、INTで) [0x00000] /Users/plasma/Source/iphone/monotouch/OpenGLES/OpenTK/Graphics/ES1 1.iPhone/GL.cs:Jabber.J3D.Shape.Draw_IOS(AT 1326 ) [0x00171]で/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/Shape_iOS.cs:136 でJabber.J3D.Shape.Draw Jabber.J3D.PhysicShape.Drawで()[0x00000] で/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/Shape.cs:255() [ 0x00000] Jabber.Scene.GameScene.Draw()で/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/PhysicShape.cs:46 における[0x0001d]で /ユーザ/ ahmedhakeem /ドキュメント/プロジェクト/ JabberEngine2/MyCode/Engine/Scene/GameScene.cs:299 at Ja bber.GameScreenManager.Screen.Draw ()[0x0001f] ChicksnVixens.Screens.GameplayScreen.Draw で/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/GameScreenManager/Screen.cs:150 で() [0x00000] /ユーザ/ ahmedhakeem/IN [0x00054])Jabber.GameScreenManager.ScreenManager.Draw ( で /Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/ChicksnVixens/Screens/GameplayScreen.cs:481でドキュメント/プロジェクト/ JabberEngine2/MyCode/Engine/GameScreenManager/ScreenManager.cs:92 at Jabber.BaseGame.Draw (Microsoft.Xna.Framework.GameTime) の[0x0002c] /Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/BaseGame.cs:95 ChicksnVixens.ChicksnVixensGame.Draw(Microsoft.Xna.Framework.GameTime) [0x00000]で /ユーザ/ ahmedhakeem /ドキュメントで/Projects/JabberEngine2/MyCode/ChicksnVixens/ChicksnVixensGame.cs:414 (Microsoft.Xna.Framework.Game.DoDraw) (Microsoft.Xna.Framework。GameTime) [0x0001e]で /Users/ahmedhakeem/Documents/Projects/JabberEngine2/ExEn/ExEnCommon/Game/GameCommon.cs:205 Microsoft.Xna.Framework.ExEnEmTouchGameView.OnRenderFrame(OpenTK.FrameEventArgs)0x0002eで]で /Users/ahmedhakeem/Documents/Projects/JabberEngine2/ExEn/ExEnEmTouch/ExEnEmTouchGameView.cs:329 OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration()における[0x000af] /ユーザ/プラズマ/出典/ iphone/monotouch/OpenGLES/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs:592 at MonoTouch.Foundation.NSActionDispatcher.Apply ()[0x00000] in /Users/pl ASMA /ソース/ iphone/MonoTouchで/共有/財団/ NSAction.cs:(ラッパーランタイム呼び出し) object.runtime_invoke_void_ この _ (オブジェクト、のIntPtr、のIntPtr、のIntPtr)ラッパー (で管理さ-への45 -native) MonoTouch.UIKit.UIApplication.UIApplicationMain(整数、文字列[]、のIntPtr、のIntPtr) MonoTouch.UIKit.UIApplication.Main(文字列[]、文字列、文字列)で[0x00038]で /ユーザ/プラズマ/ソース/ iphone/MonoTouchで/のUIKit/UIApplication.cs:ChicksnVixens.Program.Main で26 (文字列[])[0x00000] /ユーザ/ ahmedhakeem中/ドキュメント/プロジェクト/ JabberEngine2/MyCode/ChicksnVixens/MonoTouchで のProgram.cs:(ラッパー ランタイム呼び出し) .runtime_invoke_void_object(オブジェクトのIntPtr、のIntPtr、のIntPtr)

ネイティブスタックトレースで24:

0 aChicks
0x000c5d00 mono_handle_native_sigsegv + 343 1 aChicks 0x0000fce0 mono_sigsegv_signal_handler + 322 2 libSystem.B.dylib 0x95fee48b _sigtramp + 43 3 ???
0xFFFFFFFFのは0x0 + 4294967295 4
GLEngine
0x08645753 gleLLVMArrayFunc + 67 5
GLEngine
0x0863cba2 gleDrawArraysOrElements_ExecCore + 856 6 GLEngine
0x08642bbe glDrawArrays_IMM_Exec + 332 7 OpenGLES
0x0087c308 glDrawArrays + 57 8? 0x0c3c9b34 0x0 + 205298484 9?
0x0c3c9a9c 0x?
0x0f0956c8 0x0 + 252270280 11
0x0f0939c4 0x0 + 252262852 12?
0x0f09397c 0x0 + 252262780 13 ???
0x0ecdb286 0x0 + 248361606 14 ???
0x0c3c709a 0x0 + 205287578 15 ???
0x0f0927c4 0x0 + 252258244 16 ???
0x0c3c44cd 0x0 + 205276365 17 ???
0x0c3c3fed 0x0 + 205275117 18 ???
0x0c3c3e9a 0x0 + 205274778 19 ???
0x0c3c3d73 0x0 + 205274483 20 ???
0x0cc03166 0x0 + 213922150 21 ???
0x0cbfd578 0x0 + 213898616 22 ???
0x0cbfd130 0x0 + 213897520 23?
0x05e861e8は0x0 + 99115496 24 aChicks 0x0000fa9b mono_jit_runtime_invoke + 1332 25 aChicks
0x001d9f01 mono_runtime_invoke + 137 26 aChicks
0x0027e52b monotouch_trampoline + 2527 27財団
0x00619749 NSFireTimer + 125 28 CoreFoundationの
0x014398c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
+ 19 29 CoreFoundation 0x0143ae74 __CFRunLoopDoTimer + 1220 30 Co reFoundation
0x013972c9 __CFRunLoopRun + 1817年31 CoreFoundationの
0x01396840 CFRunLoopRunSpecific + 208 32 CoreFoundationの
0x01396761 CFRunLoopRunInMode + 97 33 GraphicsServices
0x028bc1c4 GSEventRunModal + 217 34 GraphicsServices
0x028bc289 GSEventRun + 115 35のUIKit 0x008abc93 UIApplicationMain + 1160 36 ???
0x05e84b8b 0x0 + 99109771 37 ???
0x05e83fb4 0x0 + 99106740 38 ???
0x05e83cee 0x0 + 99106030 39 ???
0x05e83e46は0x0 + 99106374 40 aChicks 0x0000fa9b mono_jit_runtime_invoke + 1332 41 aChicks
0x001d9f01 mono_runtime_invoke + 137 42 aChicks
0x001dc560 mono_runtime_exec_main + 669 43 aChicks
0x001db96e mono_runtime_run_main + 843 44 aChicks
0x0009cdd2 mono_jit_exec + 200 45 aChicks
0x00003362メイン+ 3838 46 aChicks
0x00002249 _start + 208 47 aChicks
GDBから 0x00002178開始+ 40

デバッグ情報:

/tmp/mono-gdb-commands.ZEI8zH:1:エラーソース化コマンド・ファイル内の :できない デバッグ自己

+0

あなたは色の配列を可能にしましたか? glEnableClientState(GL_COLOR_ARRAY) – datenwolf

+0

私は、私がそれを試したと言いましたが、エラーを持って私の記事を編集中でした... – tweetypi

答えて

4

にあなたColorPointerの引数が間違っています。最初の引数は色ごとのコンポーネントの数です。 RGBカラーには3を使用します。

はこれを試してみてください:

byte[] squareColors = new byte[simpleVertices.Count * 3]; 
Random.NextBytes(squareColors); 
GL.ColorPointer (3, All.UnsignedByte, 0, squareColors); 
+0

ああblimey、あなたは正しい!残念ながら、修正プログラムをコードに追加しても、クラッシュの問題は解決しませんでした... – tweetypi

+1

おそらく、色を指定していないところでDrawArrayを追加呼び出しすることがありますか?その場合は、上記のコードでDrawArrayの呼び出しの後にglDisableClientState(GL_COLOR_ARRAY)を呼び出す必要があります。それ以外の場合、DrawArrayのもう1つの呼び出しは、もはや割り当てられていないローカルバッファからのカラー値を使用しようとします。 –

2

あなたはテクスチャリングを有効にする必要があります

glEnable(GL_TEXTURE_2D); 

(OpenTk相当を把握することは容易でなければなりません)

関連する問題