OpenTK (OpenGL) in VB .NET


SUBMITTED BY: Guest

DATE: Nov. 13, 2013, 9:07 p.m.

FORMAT: Text only

SIZE: 3.8 kB

HITS: 1372

  1. OpenTK (OpenGL) in VB .NET
  2. Imports OpenTK
  3. Imports OpenTK.GLControl
  4. Imports OpenTK.Platform
  5. Imports OpenTK.Graphics.OpenGL
  6. Imports System.Math
  7. Dim _STARTED As Boolean = False
  8. Private Sub ResizeGL()
  9. GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height)
  10. GL.MatrixMode(MatrixMode.Projection) ' Select The Projection Matrix
  11. GL.MatrixMode(MatrixMode.Modelview) ' Select The Modelview Matrix
  12. GL.LoadIdentity() ' Reset The Modelview Matrix
  13. End Sub
  14. Public Sub ViewPerspective() ' Set Up A Perspective View
  15. GL.MatrixMode(MatrixMode.Projection) ' Select Projection
  16. GL.LoadIdentity() ';
  17. Dim perspective1 As Matrix4 = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, _
  18. CSng((GlControl1.Width) / (GlControl1.Height)), 0.1, 1000)
  19. GL.LoadMatrix(perspective1)
  20. GL.MatrixMode(MatrixMode.Modelview) ' Select The Modelview Matrix
  21. GL.LoadIdentity() ' Reset The Matrix
  22. GL.Enable(EnableCap.DepthTest) ' This doesnt need to be here but.. If your using the Z buffer.. It dont hurt.
  23. End Sub
  24. Public Sub ViewOrtho()
  25. GL.MatrixMode(MatrixMode.Projection) 'Select Projection
  26. GL.LoadIdentity() ' Reset The Matrix
  27. GL.Ortho(0, GlControl1.Width, -GlControl1.Height, 0, 0.1, 100.0) ' Select Ortho Mode
  28. GL.MatrixMode(MatrixMode.Modelview) ' Select Modelview Matrix
  29. GL.LoadIdentity() ' Reset The Matrix
  30. End Sub
  31. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  32. ViewOrtho()
  33. End Sub
  34. Private Sub GlControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GlControl1.Load
  35. GL.ClearColor(Color.Black)
  36. SetupViewport()
  37. End Sub
  38. Public Sub SetupViewport()
  39. Dim w As Integer = GlControl1.Width
  40. Dim h As Integer = GlControl1.Height
  41. GL.MatrixMode(MatrixMode.Projection)
  42. GL.LoadIdentity()
  43. GL.Ortho(0, w, 0, h, -1, 1)
  44. GL.Viewport(0, 0, w, h)
  45. End Sub
  46. Private Sub GlControl1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GlControl1.Resize
  47. SetupViewport()
  48. GlControl1.Invalidate()
  49. End Sub
  50. Private Sub GlControl1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
  51. GL.Clear(ClearBufferMask.ColorBufferBit)
  52. GL.Clear(ClearBufferMask.DepthBufferBit)
  53. 'go through list and draw shapes
  54. Dim i As Integer = 0
  55. Try
  56. Do Until i = objectsettings.GetUpperBound(1) + 1
  57. Select Case objectsettings(1, i)
  58. Case "circle"
  59. draw_circle(objectsettings(2, i), objectsettings(3, i), objectsettings(5, i), objectsettings(12, i))
  60. Case "polygon"
  61. draw_polygon(objectsettings(2, i), objectsettings(3, i), objectsettings(6, i), objectsettings(7, i), objectsettings(4, i), objectsettings(12, i))
  62. Case "text"
  63. draw_text(objectsettings(2, i), objectsettings(3, i), objectsettings(6, i), objectsettings(7, i), objectsettings(4, i), objectsettings(8, i), objectsettings(12, i))
  64. Case "triangle"
  65. draw_triangle(objectsettings(2, i), objectsettings(3, i), objectsettings(4, i), objectsettings(9, i), objectsettings(10, i), objectsettings(11, i), objectsettings(12, i))
  66. Case Else
  67. Exit Do
  68. End Select
  69. i = i + 1
  70. Loop
  71. Catch
  72. End Try
  73. GlControl1.SwapBuffers()
  74. End Sub

comments powered by Disqus