Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub GlControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GlControl1.Paint
- GL.Clear(ClearBufferMask.ColorBufferBit)
- GL.Clear(ClearBufferMask.DepthBufferBit)
- Dim perspective As Matrix4 = Matrix4.CreatePerspectiveFieldOfView(1.04, GlControl1.Width / GlControl1.Height, 1, 100) 'Setup Perspective
- Dim lookat As Matrix4 = Matrix4.LookAt(0, 0, 4, 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
- GL.Enable(EnableCap.Blend)
- GL.Enable(EnableCap.Texture2D)
- 'GL.Rotate(eye(0), 0, eye(1), eye(2))
- If mousing = True Then
- TranslateStart(0) = (MousePosition.X - mousestart.X) / 100
- TranslateStart(1) = (mousestart.Y - MousePosition.Y) / 100
- GL.Translate(TranslateStart(0) + TranslateEnd(0), TranslateStart(1) + TranslateEnd(1), 0)
- End If
- 'Start Tile Find
- Dim starttile As Integer = 0
- Dim starttilefound As Boolean = False
- For i = 0 To TileTypes.Count - 1
- If TileTypes(i).Name = "Starter Tile" Then
- starttilefound = True
- starttile = i
- End If
- Next
- If starttilefound = False Then
- MessageBox.Show("No Start Tile Found, make tile named 'Starter Tile")
- Return
- Timer1.Enabled = False
- End If
- loadtexture(TileTypes(starttile).PicPath, TileTypes(starttile).TextureCoord)
- GL.Begin(BeginMode.Quads)
- GL.Color3(Color.White)
- GL.TexCoord2(1, 0)
- GL.Vertex2(0.5, 0.5)
- GL.TexCoord2(0, 0)
- GL.Vertex2(-0.5, 0.5)
- GL.TexCoord2(0, 1)
- GL.Vertex2(-0.5, -0.5)
- GL.TexCoord2(1, 1)
- GL.Vertex2(0.5, -0.5)
- GL.End()
- For i = 0 To Tiles.Count - 1
- If Tiles(i).Used = True Then
- loadtexture(Tiles(i).PicPath, Tiles(i).TextureCoord)
- GL.Begin(BeginMode.Quads)
- GL.TexCoord2(1, 0)
- GL.Vertex2(0.5 + Tiles(i).GamePos.X, 0.5 + Tiles(i).GamePos.Y)
- GL.TexCoord2(0, 0)
- GL.Vertex2(-0.5 + Tiles(i).GamePos.X, 0.5 + Tiles(i).GamePos.Y)
- GL.TexCoord2(0, 1)
- GL.Vertex2(-0.5 + Tiles(i).GamePos.X, -0.5 + Tiles(i).GamePos.Y)
- GL.TexCoord2(1, 1)
- GL.Vertex2(0.5 + Tiles(i).GamePos.X, -0.5 + Tiles(i).GamePos.Y)
- GL.End()
- End If
- Next
- '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
- 'GL Load Texture
- Private Sub loadtexture(ByVal srcpicpath As String, ByVal texturecoord() As Single)
- Dim srcpic As Bitmap
- Dim srcpicavailable As Boolean = False
- If srcpicpath <> "" Then
- srcpic = New Bitmap(srcpicpath)
- srcpicavailable = True
- Else
- srcpic = New Bitmap(100, 100)
- End If
- Dim TextureID As Integer
- Dim bitmap As New Bitmap(100, 100)
- Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(bitmap)
- If srcpicavailable = True Then
- g.DrawImage(srcpic, New Rectangle(0, 0, bitmap.Width, bitmap.Height),
- New Rectangle(srcpic.Width * texturecoord(0),
- srcpic.Height * texturecoord(1),
- srcpic.Width * texturecoord(2),
- srcpic.Height * texturecoord(3)),
- GraphicsUnit.Pixel)
- Else
- g.FillRectangle(Brushes.White, New Rectangle(0, 0, bitmap.Width, bitmap.Height))
- End If
- GL.GenTextures(1, TextureID)
- GL.BindTexture(TextureTarget.Texture2D, TextureID)
- Dim Data As System.Drawing.Imaging.BitmapData = bitmap.LockBits(New System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
- Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
- GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Data.Width, Data.Height, 0,
- OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data.Scan0)
- bitmap.UnlockBits(Data)
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureMinFilter.Linear)
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureMagFilter.Linear)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement