问题标签 [opentk]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
3182 浏览

c# - 如何使用 OpenTK 绘制三角形?

我不确定为什么这段代码不是简单地在屏幕上绘制一个三角形(正交)。我正在使用与 OpenGL 1.1 相同的 OpenTK 1.1。

该代码在绘图函数中的每个更新周期执行一次。我认为我正在做的(但显然不是)是创建一组位置顶点以形成一个三角形并将其绘制在相机前面 10 个单位。

为什么这段代码不画三角形?

0 投票
2 回答
919 浏览

c# - 如何在 Vs 2008 中运行 OpenTk?

我尝试学习 OpenTk(旧版 Tao 框架)但我不能简单地画线:

我看不到坐标系。我认为不能在 vs 2008 中运行 open tk?你最好的建议是什么?

0 投票
4 回答
1475 浏览

c# - 如何找到圆的重叠

嗨,我做了一个应用程序,它有两个球。红色和黄色。用户必须将其拖放RED BALLYELLOW BALLXY 平面中。现在我想计算重叠的精度是多少。我知道如果目标的 XY 等于 Striker 的 XY 那么它是 100% 但你将如何计算呢?好像你把红球往右移动,前锋的 X 值变大,百分比不准确?我一直在使用百分比误差公式,但它不准确

在此处输入图像描述

0 投票
1 回答
357 浏览

c# - 为 C#/Silveright 选择一个 OpenCL 库

我有兴趣在测试项目中试用 OpenCL。但是我应该使用哪个库?

我什至不确定我的选择是什么。我在找:

  • 在高级抽象上工作的东西(OpenCL 是非常低级的)。
  • 适用于 Silverlight/XNA 和 C# 的东西。

似乎存在以下库:

0 投票
1 回答
1565 浏览

c# - 在 C# 中使用交错顶点的 VBO

我正在尝试使用 VBO 使用 OpenTK 在 C# 中绘制我的模型。在我的在线研究中,我在许多地方读到,将交错数据结构的大小设置为 32 字节的精确倍数是一种很好的做法,因此我编写了以下代码:

具体问题:

1.) 我的交错顶点数据结构应该是结构还是类?就 VBO 和/或内存占用而言,这会有所不同吗?(我决定使用结构,即使感觉不对,因为顶点一旦进入内存就不会改变。)

2.) 这个数据结构真的需要是 32 字节大小的倍数吗?(即,我是否需要一个“虚拟”填充成员来强制设置正确的大小?我在网上找到的所有示例都是用 C++ 编写的,所以我特别感兴趣的是相同的想法/动机是否会延续到 C#。

3.) [Serializable] [StructLayout(LayoutKind.Sequential)] 真的有必要吗?我从网上找到的一个例子中复制了这个,所以......

0 投票
2 回答
463 浏览

c# - 在正在绘制的顶点上看不到纹理或颜色

我在 OpenTK 中有以下代码:

我知道为顶点和 uv 提供的数据是正确的(至少它们在我的 XNA 渲染器中工作正常)并且我看到的是在屏幕上正确绘制了白色多边形。

从我上面的代码中,我应该看到各种各样的颜色,因为我正在用随机数量的字节填充 squareColours(我已经验证 squareColors 被随机字节填充)但我不是,顶点都是绘制为白色。

我也尝试过绑定纹理(通过 GL.BindTexture),但也失败了。

任何想法为什么这不起作用?

编辑:当我添加启用颜色时(请参阅这篇文章的第一条评论),应用程序崩溃并显示以下输出:

堆栈跟踪:

在 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 在 /Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine 中的 Jabber.J3D.Shape.Draw () [0x00000] /J3D/Shape.cs:255 在 Jabber.J3D.PhysicShape.Draw () [0x00000] 在 /Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/J3D/PhysicShape.cs:46 在 Jabber.Scene.GameScene .Draw () [0x0001d] 在 Jabber 的 /Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/Scene/GameScene.cs:299 中。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 在 Jabber.GameScreenManager.ScreenManager.Draw () [0x00054] 在 /Users/ahmedhakeem/Documents/Projects/JabberEngine2/MyCode/Engine/GameScreenManager/ ScreenManager.cs:92 在 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] 在 /Users/ahmedhakeem/Documents/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]在 /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 (wrapper runtime-invoke) object.runtime_invoke_void_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 在 /Users/plasma/Source/iphone/monotouch/OpenGLES/OpenTK/Platform/ 中的 OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000af] iPhoneOS/iPhoneOSGameView.cs:592 在 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] 在 /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction.cs:45 在(包装运行时调用)对象。 runtime_invoke_void_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 在 /Users/plasma/Source/iphone/monotouch/OpenGLES/OpenTK/Platform/ 中的 OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000af] iPhoneOS/iPhoneOSGameView.cs:592 在 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] 在 /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction.cs:45 在(包装运行时调用)对象。 runtime_invoke_void_OnRenderFrame (OpenTK.FrameEventArgs) [0x0002e] 在 /Users/ahmedhakeem/Documents/Projects/JabberEngine2/ExEn/ExEnEmTouch/ExEnEmTouchGameView.cs:329 在 OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000af] 在 /Users/plasma /Source/iphone/monotouch/OpenGLES/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs:592 在 /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction 中的 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] .cs:45 at (wrapper runtime-invoke) object.runtime_invoke_void_OnRenderFrame (OpenTK.FrameEventArgs) [0x0002e] 在 /Users/ahmedhakeem/Documents/Projects/JabberEngine2/ExEn/ExEnEmTouch/ExEnEmTouchGameView.cs:329 在 OpenTK.Platform.iPhoneOS.iPhoneOSGameView.RunIteration () [0x000af] 在 /Users/plasma /Source/iphone/monotouch/OpenGLES/OpenTK/Platform/iPhoneOS/iPhoneOSGameView.cs:592 在 /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction 中的 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] .cs:45 at (wrapper runtime-invoke) object.runtime_invoke_void_592 在 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] in /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction.cs:45 at (wrapper runtime-invoke) object.runtime_invoke_void_592 在 MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] in /Users/plasma/Source/iphone/monotouch/shared/Foundation/NSAction.cs:45 at (wrapper runtime-invoke) object.runtime_invoke_void_这个_ (object,intptr,intptr,intptr) at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) 在 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)

本机堆栈跟踪:

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 OpenGL glES 0x0087c8 OpenGLDrawArrays
8 + OpenGLDrawArrays 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 基础
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主+ 3838 46 aChicks
0x00002249 _start + 208个47 aChicks 0x00002178
开始+ 40

来自 gdb 的调试信息:

/tmp/mono-gdb-commands.ZEI8zH:1:源命令文件中的错误:无法自我调试

0 投票
2 回答
4418 浏览

wpf - 在 WPF 中的 WindowsFormsHost 中不断更新 OpenTK GLControl - 如何?

我在我的 WPF 应用程序的 WindowsFormsHost 中嵌入了一个 OpenTK GLControl。我想不断更新和渲染它。在 Winforms 中,一个解决方案是将 UpdateAndRender 方法附加到 Application.Idle 事件,但在 WPF 中没有这样的事情。

那么更新我的场景和 GLControl 的最佳方法是什么(60FPS)?

0 投票
1 回答
1106 浏览

c# - 使用 OpenTK 的 C# 代码

我刚开始学习 C# 和 OpenTK(我已经了解 Java 和 C++)。我在 OpenTK 提供的演示代码中遇到了这行代码:

如果按下 Esc 按钮,Keyboard[Key.Escape] 将返回 true。但是,我不认识这种语法。键盘不是数组。谁能向我解释一下这种语法是什么以及它是如何工作的?参考链接就足够了。感谢您的时间。

0 投票
1 回答
4843 浏览

c# - 如何使用 OpenGL 制作自定义顶点格式

我正在使用 OpenTK 编写自己的引擎(基本上只是 C# 的 OpenGL 绑定,gl* 变为 GL.*),我将存储大量顶点缓冲区,每个缓冲区中有数千个顶点。因此我需要我自己的自定义顶点格式,因为带有浮点数的 Vec3 只会占用太多空间。(我在这里说的是数百万个顶点)

我想要做的是用这个布局创建我自己的顶点格式:

这是顶点的 C# 代码:

每个轴的位置一个字节就足够了,因为我只需要 32^3 个唯一位置。

我已经编写了自己的顶点着色器,它以两个 vec4 作为输入,用于每组字节。我的顶点着色器是这样的:

为了尝试隔离问题,我使顶点着色器尽可能简单。编译着色器的代码是用立即模式绘图测试的,它可以工作,所以不能这样。

这是我的函数,它生成、设置并用数据填充顶点缓冲区并建立指向属性的指针。

据我了解,这是正确的过程: 生成顶点数组对象并绑定它 生成顶点缓冲区并绑定它 用数据填充顶点缓冲区 设置属性指针

Shaders.*DataID 在编译和使用着色器后使用此代码设置。

这是我的渲染功能:

谁能给我一些指示(不是双关语)?我是按错误的顺序执行此操作还是需要调用某些函数?

我在网上搜索过,但找不到一个好的教程或指南来解释如何实现自定义顶点。如果您需要更多信息,请说出来。

0 投票
1 回答
1666 浏览

c# - 纹理缺乏颜色

我有以下图片:

在此处输入图像描述

窗口显示两个纹理,左边的纹理是通过将其绑定到一个 FBO 并渲染到 FBO 生成的,50 个随机三角形。

正确的纹理是由具有蒙娜丽莎全彩图像的 glTexImage2D 生成的,但是正如您所看到的图像缺少红色,我认为问题出在 OpenGL 部分,因为我已经研究了传递给 glTexImage2D 的字节和它们确实包含红色...

这是 C#/Mono/OpenTK 源代码