OpenTK (OpenGL) in VB .NET
Imports OpenTK
Imports OpenTK.GLControl
Imports OpenTK.Platform
Imports OpenTK.Graphics.OpenGL
Imports System.Math
Dim _STARTED As Boolean = False
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ViewOrtho()
End Sub
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