SHARE
TWEET

OpenTK

Robomatics Dec 30th, 2012 8,827 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports OpenTK
  2. Imports OpenTK.Graphics
  3. Imports OpenTK.Graphics.OpenGL
  4.  
  5. Public Class Form1
  6.  
  7.     Private Sub GlControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GlControl1.Load
  8.         'Control is loaded, set back color
  9.         GL.ClearColor(Color.Black)
  10.     End Sub
  11.  
  12.     Private Sub GlControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
  13.         'First Clear Buffers
  14.         GL.Clear(ClearBufferMask.ColorBufferBit)
  15.         GL.Clear(ClearBufferMask.DepthBufferBit)
  16.  
  17.         'Basic Setup for viewing
  18.         Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.04, 4 / 3, 1, 10000) 'Setup Perspective
  19.         Dim lookat As Matrix4 = Matrix4.LookAt(100, 20, 0, 0, 0, 0, 0, 1, 0) 'Setup camera
  20.         GL.MatrixMode(MatrixMode.Projection) 'Load Perspective
  21.         GL.LoadIdentity()
  22.         GL.LoadMatrix(perspective)
  23.         GL.MatrixMode(MatrixMode.Modelview) 'Load Camera
  24.         GL.LoadIdentity()
  25.         GL.LoadMatrix(lookat)
  26.         GL.Viewport(0, 0, GlControl1.Width, GlControl1.Height) 'Size of window
  27.         GL.Enable(EnableCap.DepthTest) 'Enable correct Z Drawings
  28.         GL.DepthFunc(DepthFunction.Less) 'Enable correct Z Drawings
  29.  
  30.         'Rotating
  31.         GL.Rotate(NumericUpDown1.Value, 0, 0, 1)
  32.         GL.Rotate(NumericUpDown2.Value, 0, 1, 0)
  33.  
  34.         'Draw pyramid, Y is up, Z is twards you, X is left and right
  35.         'Vertex goes (X,Y,Z)
  36.         GL.Begin(BeginMode.Triangles)
  37.         'Face 1
  38.         GL.Color3(Color.Red)
  39.         GL.Vertex3(50, 0, 0)
  40.         GL.Color3(Color.White)
  41.         GL.Vertex3(0, 25, 0)
  42.         GL.Color3(Color.Blue)
  43.         GL.Vertex3(0, 0, 50)
  44.         'Face 2
  45.         GL.Color3(Color.Green)
  46.         GL.Vertex3(-50, 0, 0)
  47.         GL.Color3(Color.White)
  48.         GL.Vertex3(0, 25, 0)
  49.         GL.Color3(Color.Blue)
  50.         GL.Vertex3(0, 0, 50)
  51.         'Face 3
  52.         GL.Color3(Color.Red)
  53.         GL.Vertex3(50, 0, 0)
  54.         GL.Color3(Color.White)
  55.         GL.Vertex3(0, 25, 0)
  56.         GL.Color3(Color.Blue)
  57.         GL.Vertex3(0, 0, -50)
  58.         'Face 4
  59.         GL.Color3(Color.Green)
  60.         GL.Vertex3(-50, 0, 0)
  61.         GL.Color3(Color.White)
  62.         GL.Vertex3(0, 25, 0)
  63.         GL.Color3(Color.Blue)
  64.         GL.Vertex3(0, 0, -50)
  65.  
  66.         'Finish the begin mode with "end"
  67.         GL.End()
  68.  
  69.         'Finally...
  70.         GraphicsContext.CurrentContext.VSync = True 'Caps frame rate as to not over run GPU
  71.         GlControl1.SwapBuffers() 'Takes from the 'GL' and puts into control
  72.     End Sub
  73.  
  74.     Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
  75.         'Must be called to update the control window!
  76.         GlControl1.Invalidate()
  77.     End Sub
  78.  
  79.     Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
  80.         'Must be called to update the control window!
  81.         GlControl1.Invalidate()
  82.     End Sub
  83. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top