Advertisement
Robomatics

OpenTK Textures

Aug 28th, 2013
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.91 KB | None | 0 0
  1.  
  2. Imports OpenTK
  3. Imports OpenTK.Graphics
  4. Imports OpenTK.Graphics.OpenGL
  5.  
  6.  
  7.     Private Sub GlControl1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GlControl1.Load
  8.         GL.ClearColor(Color.SkyBlue)
  9.     End Sub
  10.  
  11.     Function texture(ByVal pic As Bitmap)
  12.         Dim tex As Integer
  13.         GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest)
  14.  
  15.         GL.GenTextures(1, tex)
  16.         GL.BindTexture(TextureTarget.Texture2D, tex)
  17.  
  18.         Dim data As Imaging.BitmapData = pic.LockBits(New System.Drawing.Rectangle(0, 0, pic.Width, pic.Height),
  19.             Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
  20.  
  21.         GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
  22.             OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0)
  23.  
  24.         pic.UnlockBits(data)
  25.  
  26.         GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear)
  27.         GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear)
  28.         GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, TextureWrapMode.Repeat)
  29.         GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, TextureWrapMode.Repeat)
  30.  
  31.         Return tex
  32.     End Function
  33.  
  34.     Private Sub GlControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
  35.  
  36.         GL.Clear(ClearBufferMask.ColorBufferBit)
  37.         GL.Clear(ClearBufferMask.DepthBufferBit)
  38.  
  39.         GL.MatrixMode(MatrixMode.Projection)
  40.         GL.PushMatrix()
  41.         GL.LoadIdentity()
  42.  
  43.         GL.Ortho(0, 640, 480, 0, -1, 1)
  44.  
  45.         GL.MatrixMode(MatrixMode.Modelview)
  46.         GL.PushMatrix()
  47.         GL.LoadIdentity()
  48.  
  49.         GL.Disable(EnableCap.Lighting)
  50.  
  51.         GL.Enable(EnableCap.Texture2D)
  52.  
  53.         Dim tempint As Integer = texture(mjpgpics(PBBox1))
  54.         GL.BindTexture(TextureTarget.Texture2D, tempint)
  55.         GL.Begin(BeginMode.Quads)
  56.         GL.TexCoord2(0, 0)
  57.         GL.Vertex3(0, 0, 0)
  58.         GL.TexCoord2(1, 0)
  59.         GL.Vertex3(320, 0, 0)
  60.         GL.TexCoord2(1, 1)
  61.         GL.Vertex3(320, 240, 0)
  62.         GL.TexCoord2(0, 1)
  63.         GL.Vertex3(0, 240, 0)
  64.         GL.End()
  65.         GL.DeleteTexture(tempint)
  66.  
  67.         tempint = texture(mjpgpics(PBBox2))
  68.         GL.BindTexture(TextureTarget.Texture2D, tempint)
  69.         GL.Begin(BeginMode.Quads)
  70.         GL.TexCoord2(0, 0)
  71.         GL.Vertex3(320, 0, 0)
  72.         GL.TexCoord2(1, 0)
  73.         GL.Vertex3(640, 0, 0)
  74.         GL.TexCoord2(1, 1)
  75.         GL.Vertex3(640, 240, 0)
  76.         GL.TexCoord2(0, 1)
  77.         GL.Vertex3(320, 240, 0)
  78.         GL.End()
  79.         GL.DeleteTexture(tempint)
  80.  
  81.         tempint = texture(mjpgpics(PBBox3))
  82.         GL.BindTexture(TextureTarget.Texture2D, tempint)
  83.         GL.Begin(BeginMode.Quads)
  84.         GL.TexCoord2(0, 0)
  85.         GL.Vertex3(0, 240, 0)
  86.         GL.TexCoord2(1, 0)
  87.         GL.Vertex3(320, 240, 0)
  88.         GL.TexCoord2(1, 1)
  89.         GL.Vertex3(320, 480, 0)
  90.         GL.TexCoord2(0, 1)
  91.         GL.Vertex3(0, 480, 0)
  92.         GL.End()
  93.         GL.DeleteTexture(tempint)
  94.  
  95.         tempint = texture(mjpgpics(PBBox4))
  96.         GL.BindTexture(TextureTarget.Texture2D, tempint)
  97.         GL.Begin(BeginMode.Quads)
  98.         GL.TexCoord2(0, 0)
  99.         GL.Vertex3(320, 240, 0)
  100.         GL.TexCoord2(1, 0)
  101.         GL.Vertex3(640, 240, 0)
  102.         GL.TexCoord2(1, 1)
  103.         GL.Vertex3(640, 480, 0)
  104.         GL.TexCoord2(0, 1)
  105.         GL.Vertex3(320, 480, 0)
  106.         GL.End()
  107.         GL.DeleteTexture(tempint)
  108.  
  109.         GL.Disable(EnableCap.Texture2D)
  110.         GL.PopMatrix()
  111.  
  112.         GL.MatrixMode(MatrixMode.Projection)
  113.         GL.PopMatrix()
  114.  
  115.         GL.MatrixMode(MatrixMode.Modelview)
  116.  
  117.         GraphicsContext.CurrentContext.VSync = True
  118.         GlControl1.SwapBuffers()
  119.  
  120.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement