我试图学习如何在VB .NET环境中做openGL,似乎推荐使用Tao框架或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.Math6)我的全局变量:
Dim _STARTED As Boolean = False7)我写下了我的事件:
私有子GlControl1_Resize(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理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 Sub8)最后,我试着给他们打电话:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ViewOrtho()
End Sub上面的结果没有显示,因此任何帮助都将不胜感激。
即使你不知道一个完整的解决方案,任何回应都会很好。
发布于 2012-02-25 05:51:39
我已经解决了我自己的问题:p我已经创建了一个包装类,这样我就可以根据输入绘制一些基本元素,这些输入应该允许我绘制许多东西:圆、多边形、三角形和文本。
Private Sub GlControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GlControl1.Load
GL.ClearColor(Color.Black)
SetupViewport()
End Sub
Public Sub SetupViewport()
Dim w As Integer = GlControl1.Width
Dim h As Integer = GlControl1.Height
GL.MatrixMode(MatrixMode.Projection)
GL.LoadIdentity()
GL.Ortho(0, w, 0, h, -1, 1)
GL.Viewport(0, 0, w, h)
End Sub
Private Sub GlControl1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GlControl1.Resize
SetupViewport()
GlControl1.Invalidate()
End Sub
Private Sub GlControl1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
GL.Clear(ClearBufferMask.ColorBufferBit)
GL.Clear(ClearBufferMask.DepthBufferBit)
'go through list and draw shapes
Dim i As Integer = 0
Try
Do Until i = objectsettings.GetUpperBound(1) + 1
Select Case objectsettings(1, i)
Case "circle"
draw_circle(objectsettings(2, i), objectsettings(3, i), objectsettings(5, i), objectsettings(12, i))
Case "polygon"
draw_polygon(objectsettings(2, i), objectsettings(3, i), objectsettings(6, i), objectsettings(7, i), objectsettings(4, i), objectsettings(12, i))
Case "text"
draw_text(objectsettings(2, i), objectsettings(3, i), objectsettings(6, i), objectsettings(7, i), objectsettings(4, i), objectsettings(8, i), objectsettings(12, i))
Case "triangle"
draw_triangle(objectsettings(2, i), objectsettings(3, i), objectsettings(4, i), objectsettings(9, i), objectsettings(10, i), objectsettings(11, i), objectsettings(12, i))
Case Else
Exit Do
End Select
i = i + 1
Loop
Catch
End Try
GlControl1.SwapBuffers()
End Sub发布于 2012-02-22 18:38:36
也请发布您的渲染代码(即绘制事件处理程序)。您发布的代码设置了OpenGL视口和投影矩阵,但实际上并没有渲染任何内容。
https://stackoverflow.com/questions/9330109
复制相似问题