VB .NET 中的 OpenTK (OpenGL)
我试图学习如何在 VB .NET 环境中进行 openGL,似乎推荐使用 Tai 框架或 OpenTK,其中 OpenTK 的推荐度更高,所以我选择尝试使用它。
由于我对此是全新的,所以我尝试只画一个简单的盒子、三角形或任何真正的东西,以便我可以在制作更复杂的东西之前理解这一切。到目前为止我在这方面还没有成功,所以我将按顺序列出我到目前为止所做的事情,希望这里有人可以帮助我纠正它或提供一个新的例子,这样我就可以绘制一个简单的形状。
1) 我使用 opentk-2010-10-06.exe 安装了 OpenTK
2) 在新项目中,我添加了对 OpenTK.dll 和 OpenTK.Compatibility.dll 的引用
3) 我添加了控件 (opentk.glcontrol.dll)
4)我将实际控件添加到我的表单中。
使用一些在线示例,我添加了其余部分:
5)我在以下位置写了我的引用:
Imports OpenTK
Imports OpenTK.GLControl
Imports OpenTK.Platform
Imports OpenTK.Graphics.OpenGL
Imports System.Math
6)我的全局变量:
Dim _STARTED As Boolean = False
7)我写了我的事件:
Private Sub GlControl1_Resize(ByVal sender As Object,ByVal e As System.EventArgs)Handles GlControl1.Resize _开始=真 调整GL大小() End Sub
Private Sub ResizeGL()
GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
GL.MatrixMode(MatrixMode.Projection) ' Select The Projection Matrix
GL.MatrixMode(MatrixMode.Modelview) ' Select The Modelview Matrix
GL.LoadIdentity() ' Reset The Modelview Matrix
End Sub
Public Sub ViewPerspective() ' Set Up A Perspective View
GL.MatrixMode(MatrixMode.Projection) ' Select Projection
GL.LoadIdentity() ';
Dim perspective1 As Matrix4 = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, _
CSng((GlControl1.Width) / (GlControl1.Height)), 0.1, 1000)
GL.LoadMatrix(perspective1)
GL.MatrixMode(MatrixMode.Modelview) ' Select The Modelview Matrix
GL.LoadIdentity() ' Reset The Matrix
GL.Enable(EnableCap.DepthTest) ' This doesnt need to be here but.. If your using the Z buffer.. It dont hurt.
End Sub
Public Sub ViewOrtho()
GL.MatrixMode(MatrixMode.Projection) 'Select Projection
GL.LoadIdentity() ' Reset The Matrix
GL.Ortho(0, GlControl1.Width, -GlControl1.Height, 0, 0.1, 100.0) ' Select Ortho Mode
GL.MatrixMode(MatrixMode.Modelview) ' Select Modelview Matrix
GL.LoadIdentity() ' Reset The Matrix
End Sub
8) 最后,我尝试给他们打电话:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ViewOrtho()
End Sub
上面的结果没有显示,所以任何帮助将不胜感激。
即使您不知道完整的解决方案,任何回应都会很好。
I was trying to learn how to do openGL within a VB .NET environment and it seems that the Tao framework or OpenTK is recommended with OpenTK having a higher recommendation so that is what I chose to try using.
Since I am brand new to this, I am trying to just draw a simple box, triangle, or anything really so that I can understand it all before making more complex things. I have been unsuccessful at this so far so I will list in order what I have done so far and hopefully someone here can help me correct it or provide a new example just so I can draw a simple shape.
1) I installed OpenTK using opentk-2010-10-06.exe
2) In a new project I added the references to OpenTK.dll and OpenTK.Compatibility.dll
3) I added the control (opentk.glcontrol.dll)
4) I added the actual control to my form.
Using some examples online I added the rest:
5) I wrote my references in:
Imports OpenTK
Imports OpenTK.GLControl
Imports OpenTK.Platform
Imports OpenTK.Graphics.OpenGL
Imports System.Math
6) My global variable:
Dim _STARTED As Boolean = False
7) I wrote my events:
Private Sub GlControl1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles GlControl1.Resize
_STARTED = True
ResizeGL()
End Sub
Private Sub ResizeGL()
GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
GL.MatrixMode(MatrixMode.Projection) ' Select The Projection Matrix
GL.MatrixMode(MatrixMode.Modelview) ' Select The Modelview Matrix
GL.LoadIdentity() ' Reset The Modelview Matrix
End Sub
Public Sub ViewPerspective() ' Set Up A Perspective View
GL.MatrixMode(MatrixMode.Projection) ' Select Projection
GL.LoadIdentity() ';
Dim perspective1 As Matrix4 = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, _
CSng((GlControl1.Width) / (GlControl1.Height)), 0.1, 1000)
GL.LoadMatrix(perspective1)
GL.MatrixMode(MatrixMode.Modelview) ' Select The Modelview Matrix
GL.LoadIdentity() ' Reset The Matrix
GL.Enable(EnableCap.DepthTest) ' This doesnt need to be here but.. If your using the Z buffer.. It dont hurt.
End Sub
Public Sub ViewOrtho()
GL.MatrixMode(MatrixMode.Projection) 'Select Projection
GL.LoadIdentity() ' Reset The Matrix
GL.Ortho(0, GlControl1.Width, -GlControl1.Height, 0, 0.1, 100.0) ' Select Ortho Mode
GL.MatrixMode(MatrixMode.Modelview) ' Select Modelview Matrix
GL.LoadIdentity() ' Reset The Matrix
End Sub
8) Lastly, I tried to call them:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ViewOrtho()
End Sub
The above results in no display, so any help would be greatly appreciated.
Even if you don't know a full solution, any response wouldbe nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请也发布您的渲染代码(即您的 Paint 事件处理程序)。您发布的代码设置了 OpenGL 视口和投影矩阵,但实际上并没有渲染任何内容。
Please post your rendering code, too (i.e. you Paint event handler). The code you posted sets up the OpenGL viewport and projection matrix, but doesn't actually render anything.
我已经解决了我自己的问题:p 我创建了一个包装类,以便我可以根据输入绘制一些基元,这应该允许我绘制许多东西:圆形、多边形、三角形和文本。
I have solved my own question :p I have created a wrapper class so that I can draw some primatives based on inputs which should allow me to draw many things: a circle, polygon, triangle, and text.