看不到正在绘制的顶点上的纹理或颜色
我在 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);
}
我知道为顶点和 uv 提供的数据是正确的(至少它们在我的 XNA 渲染器中工作正常),并且我看到的是在屏幕上正确绘制了白色多边形。
从上面的代码中,我应该看到各种各样的颜色,因为我用随机数量的字节填充 squareColors (我已经验证 squareColors 正在用随机字节填充),但我没有,顶点都在绘制为白色。
我还尝试绑定纹理(通过 GL.BindTexture),但也失败了。
有什么想法为什么这不起作用吗?
编辑:当我添加启用颜色时(请参阅本文的第一条评论),应用程序崩溃并显示以下输出:
堆栈跟踪:
at(包装器托管到本机) 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/ES11.iPhone/GL.cs:1326 在 Jabber.J3D.Shape.Draw_IOS () [0x00171] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/J3D/Shape_iOS.cs:136 在 Jabber.J3D.Shape.Draw () [0x00000] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/J3D/Shape.cs:255 在 Jabber.J3D.PhysicShape.Draw () [0x00000] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/J3D/PhysicShape.cs:46 在 Jabber.Scene.GameScene.Draw () [0x0001d] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/Scene/GameScene.cs:299 在 Jabber.GameScreenManager.Screen.Draw () [0x0001f] 中 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/GameScreenManager/Screen.cs:150 在 ChicksnVixens.Screens.GameplayScreen.Draw () [0x00000] 中 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/ChicksnVixens/Screens/GameplayScreen.cs:481 在 Jabber.GameScreenManager.ScreenManager.Draw () [0x00054] 中 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/GameScreenManager/ScreenManager.cs:92 在 Jabber.BaseGame.Draw (微软.Xna.Framework.GameTime) [0x0002c] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/Engine/BaseGame.cs:95 在 ChicksnVixens.ChicksnVixensGame.Draw (微软.Xna.Framework.GameTime) [0x00000] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/ChicksnVixens/ChicksnVixensGame.cs:414 在 Microsoft.Xna.Framework.Game.DoDraw (微软.Xna.Framework.GameTime) [0x0001e] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/ExEn/ExEnCommon/Game/GameCommon.cs:205 在 Microsoft.Xna.Framework.ExEnEmTouchGameView.OnRenderFrame (OpenTK.FrameEventArgs) [0x0002e] 在 /用户/ahmedhakeem/文档/项目/JabberEngine2/ExEn/ExEnEmTouch/ExEnEmTouchGameView.cs:329 在 OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000af] 中 /Users/plasma/Source/iphone/monotouch/OpenGLES/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs:592 在 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] 中 /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction.cs:45 at(包装运行时调用) object.runtime_invoke_void_这个_ (对象,intptr,intptr,intptr)在(包装器 托管到本机) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,字符串[],intptr,intptr)在 MonoTouch.UIKit.UIApplication.Main (字符串[],字符串,字符串) [0x00038] 中 /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26 在 ChicksnVixens.Program.Main (字符串[]) [0x00000] 中 /用户/ahmedhakeem/文档/项目/JabberEngine2/MyCode/ChicksnVixens/MonoTouch Program.cs:24 at(包装器 运行时调用) .runtime_invoke_void_object (对象,intptr,intptr,intptr)
本机堆栈跟踪:
0 只小鸡
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
GL引擎
0x08645753 gleLLVMArrayFunc + 67 5
GL引擎
0x0863cba2 gleDrawArraysOrElements_ExecCore + 856 6 GL引擎
0x08642bbe glDrawArrays_IMM_Exec + 332 7 OpenGLES
0x0087c308 glDrawArrays + 57 8 ??? 0x0c3c9b34 0x0 + 205298484 9 ???
0x0c3c9a9c 0x0 + 205298332 10 ???
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 a小鸡
0x001d9f01 mono_runtime_invoke + 137 26 一只小鸡
0x0027e52b monotouch_trampoline + 2527 27 基金会
0x00619749 NSFireTimer + 125 28 核心基础
0x014398c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 19 29 核心基础 0x0143ae74 __CFRunLoopDoTimer + 1220 30 核心基础
0x013972c9 __CFRunLoopRun + 1817 31 核心基础
0x01396840 CFRunLoopRunSpecific + 208 32 核心基础
0x01396761 CFRunLoopRunIn模式 + 97 33 图形服务
0x028bc1c4 GSEventRunModal + 217 34 图形服务
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 a小鸡
0x001d9f01 mono_runtime_invoke + 137 42 一只小鸡
0x001dc560 mono_runtime_exec_main + 669 43 a小鸡
0x001db96e mono_runtime_run_main + 843 44 一只小鸡
0x0009cdd2 mono_jit_exec + 200 45 小鸡
0x00003362 main + 3838 46 aChicks
0x00002249 _start + 208 47 aChicks
0x00002178开始+40来自 gdb 的调试信息:
/tmp/mono-gdb-commands.ZEI8zH:1:错误 在源命令文件中:无法 自我调试
I have the following code in 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);
}
I know the data being given for vertices anduv are correct (at least they work fine in my XNA renderer) and what I'm seeing is white polygons being drawn correctly on screen.
From my code above I should be seeing an assortment of colours since I'm populating squareColours with a random number of bytes (I've verified that squareColors is being filled up with random bytes) but I'm not, the vertices are all being drawn as white.
I've also tried binding a texture (via GL.BindTexture) and that has also failed.
Any ideas why this isn't working?
edit: when I added to enable color (see first comment on this post) the app crashed out with the following output:
Stacktrace:
at (wrapper managed-to-native)
OpenTK.Graphics.ES11.GL/Core.DrawArrays
(OpenTK.Graphics.ES11.All,int,int) at
OpenTK.Graphics.ES11.GL.DrawArrays
(OpenTK.Graphics.ES11.All,int,int)
[0x00000] in
/Users/plasma/Source/iphone/monotouch/OpenGLES/OpenTK/Graphics/ES11.iPhone/GL.cs:1326
at Jabber.J3D.Shape.Draw_IOS ()
[0x00171] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/Shape_iOS.cs:136
at Jabber.J3D.Shape.Draw () [0x00000]
in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/Shape.cs:255
at Jabber.J3D.PhysicShape.Draw ()
[0x00000] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/PhysicShape.cs:46
at Jabber.Scene.GameScene.Draw ()
[0x0001d] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/Scene/GameScene.cs:299
at
Jabber.GameScreenManager.Screen.Draw
() [0x0001f] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/GameScreenManager/Screen.cs:150
at
ChicksnVixens.Screens.GameplayScreen.Draw
() [0x00000] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/ChicksnVixens/Screens/GameplayScreen.cs:481
at
Jabber.GameScreenManager.ScreenManager.Draw
() [0x00054] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/GameScreenManager/ScreenManager.cs:92
at Jabber.BaseGame.Draw
(Microsoft.Xna.Framework.GameTime)
[0x0002c] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/BaseGame.cs:95
at
ChicksnVixens.ChicksnVixensGame.Draw
(Microsoft.Xna.Framework.GameTime)
[0x00000] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/ChicksnVixens/ChicksnVixensGame.cs:414
at Microsoft.Xna.Framework.Game.DoDraw
(Microsoft.Xna.Framework.GameTime)
[0x0001e] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/ExEn/ExEnCommon/Game/GameCommon.cs:205
at
Microsoft.Xna.Framework.ExEnEmTouchGameView.OnRenderFrame
(OpenTK.FrameEventArgs) [0x0002e] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/ExEn/ExEnEmTouch/ExEnEmTouchGameView.cs:329
at
OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration
() [0x000af] in
/Users/plasma/Source/iphone/monotouch/OpenGLES/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs:592
at
MonoTouch.Foundation.NSActionDispatcher.Apply
() [0x00000] in
/Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction.cs:45
at (wrapper runtime-invoke)
object.runtime_invoke_void_this_
(object,intptr,intptr,intptr) at (wrapper
managed-to-native)
MonoTouch.UIKit.UIApplication.UIApplicationMain
(int,string[],intptr,intptr) at
MonoTouch.UIKit.UIApplication.Main
(string[],string,string) [0x00038] in
/Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
at ChicksnVixens.Program.Main
(string[]) [0x00000] in
/Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/ChicksnVixens/MonoTouch
Program.cs:24 at (wrapper
runtime-invoke)
.runtime_invoke_void_object
(object,intptr,intptr,intptr)Native stacktrace:
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 0x0 + 205298332 10 ???
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 Foundation
0x00619749 NSFireTimer + 125 28
CoreFoundation
0x014398c3
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION
+ 19 29 CoreFoundation 0x0143ae74 __CFRunLoopDoTimer + 1220
30 CoreFoundation
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 main + 3838 46 aChicks
0x00002249 _start + 208 47 aChicks
0x00002178 start + 40Debug info from gdb:
/tmp/mono-gdb-commands.ZEI8zH:1: Error
in sourced command file: unable to
debug self
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对 ColorPointer 的参数有错误。第一个参数是每种颜色的分量数。对于 RGB 颜色使用 3。
试试这个:
You have the wrong arguments to ColorPointer. The first argument is the number of components per color. Use 3 for RGB-colors.
Try this:
您需要启用纹理:(
应该很容易找出 OpenTk 的等效项)
You need to enable texturing:
(should be easy to figure out the OpenTk equivalent)