Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports OpenTK
- Imports OpenTK.Graphics
- Imports OpenTK.Graphics.OpenGL
- Public Class Form1
- Private Sub GlControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GlControl1.Load
- 'Control is loaded, set back color
- GL.ClearColor(Color.Black)
- End Sub
- Private Sub GlControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
- 'First Clear Buffers
- GL.Clear(ClearBufferMask.ColorBufferBit)
- GL.Clear(ClearBufferMask.DepthBufferBit)
- 'Basic Setup for viewing
- Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.04, 4 / 3, 1, 10000) 'Setup Perspective
- Dim lookat As Matrix4 = Matrix4.LookAt(100, 20, 0, 0, 0, 0, 0, 1, 0) 'Setup camera
- GL.MatrixMode(MatrixMode.Projection) 'Load Perspective
- GL.LoadIdentity()
- GL.LoadMatrix(perspective)
- GL.MatrixMode(MatrixMode.Modelview) 'Load Camera
- GL.LoadIdentity()
- GL.LoadMatrix(lookat)
- GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height) 'Size of window
- GL.Enable(EnableCap.DepthTest) 'Enable correct Z Drawings
- GL.DepthFunc(DepthFunction.Less) 'Enable correct Z Drawings
- 'Rotating
- GL.Rotate(NumericUpDown1.Value, 0, 0, 1)
- GL.Rotate(NumericUpDown2.Value, 0, 1, 0)
- 'Draw pyramid, Y is up, Z is twards you, X is left and right
- 'Vertex goes (X,Y,Z)
- GL.Begin(BeginMode.Triangles)
- 'Face 1
- GL.Color3(Color.Red)
- GL.Vertex3(50, 0, 0)
- GL.Color3(Color.White)
- GL.Vertex3(0, 25, 0)
- GL.Color3(Color.Blue)
- GL.Vertex3(0, 0, 50)
- 'Face 2
- GL.Color3(Color.Green)
- GL.Vertex3(-50, 0, 0)
- GL.Color3(Color.White)
- GL.Vertex3(0, 25, 0)
- GL.Color3(Color.Blue)
- GL.Vertex3(0, 0, 50)
- 'Face 3
- GL.Color3(Color.Red)
- GL.Vertex3(50, 0, 0)
- GL.Color3(Color.White)
- GL.Vertex3(0, 25, 0)
- GL.Color3(Color.Blue)
- GL.Vertex3(0, 0, -50)
- 'Face 4
- GL.Color3(Color.Green)
- GL.Vertex3(-50, 0, 0)
- GL.Color3(Color.White)
- GL.Vertex3(0, 25, 0)
- GL.Color3(Color.Blue)
- GL.Vertex3(0, 0, -50)
- 'Finish the begin mode with "end"
- GL.End()
- 'Finally...
- GraphicsContext.CurrentContext.VSync = True 'Caps frame rate as to not over run GPU
- GlControl1.SwapBuffers() 'Takes from the 'GL' and puts into control
- End Sub
- Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
- 'Must be called to update the control window!
- GlControl1.Invalidate()
- End Sub
- Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
- 'Must be called to update the control window!
- GlControl1.Invalidate()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement