Imports System
Imports System.Collections.Generic
Imports System.Threading
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO

Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Imports EZGL2D

Namespace EZGL2DexampleBasic
	Public Class GL2Dexample ' inherit the GameWindow class
		Inherits GameWindow

		Private Const SCREEN_WIDTH As Integer = 800 ' screen dimension
		Private Const SCREEN_HEIGHT As Integer = 600

		Private plantSprite As GL2D.SpriteGL ' our sprite


		' Init screen
		Public Sub New()
			MyBase.New(SCREEN_WIDTH, SCREEN_HEIGHT)

		End Sub

		' this is where you would initialize everything
		' like loading textures, setting up OpenGL screen, etc.
		Protected Overrides Sub OnLoad(ByVal e As EventArgs)
			MyBase.OnLoad(e)

			VSync = VSyncMode.On ' force vertical synching
			Title = "EZGL2D is too easy to use it hurts!" ' set the title
			'WindowBorder = WindowBorder.Hidden;             // hide the window

			' Load our sprite
			plantSprite = GL2D.LoadSprite("data/EZGL2DexampleBasic/plant.png", CInt(TextureMinFilter.Linear))

		End Sub

		Protected Overrides Sub OnResize(ByVal e As EventArgs)
			MyBase.OnResize(e)
			GL2D.Screen2D(Width, Height) ' reset the screen every resize
		End Sub

		' this is where all your game logic
		' should be done. (Input, Entity movement, collisions, etc)
		Protected Overrides Sub OnUpdateFrame(ByVal e As FrameEventArgs)
			MyBase.OnUpdateFrame(e)

			' get input
			If Keyboard(OpenTK.Input.Key.Escape) Then
				Me.Exit()
				Return
			End If
		End Sub

		' This is where all rendering/drawing should be done
		Protected Overrides Sub OnRenderFrame(ByVal e As FrameEventArgs)
			MyBase.OnRenderFrame(e)

			GL2D.ClearScreen() ' clear the screen
			GL2D.EnableAntialias(True) ' smoothen the primitives
			GL2D.Begin2D() ' start 2D drawing mode

			' Draw boxes that get smaller continuously
			GL.Color4(0.0F, 0.7F, 0.5F, 1.0F) 'cyan-ish Box
			For i As Integer = 0 To 29
				GL2D.Box(10 + i * 10, 10 + i * 10, (Width - 10) - i * 10, (Height - 10) - i * 10)
			Next i

			' Draw a little box on the upper-left corner
			GL.Color4(1.0F, 0.7F, 0.5F, 1.0F)
			GL2D.BoxFilled(100, 100, 30, 40)

			' Draw a triangle on the lower-right corner
			GL.Color4(0.0F, 0.0F, 1.0F, 1.0F)
			GL2D.TriangleFilled(600, 400, 750, 500, 500, 550)

			' Draw some blue colored spokes
			GL.Color4(0.0F, 1.0F, 0.0F, 1.0F)
			For i As Integer = 0 To 359 Step 10
				Dim angle As Double = i * Math.PI/180
'INSTANT VB NOTE: The variable x was renamed since Visual Basic does not handle local variables named the same as class members well:
				Dim x_Renamed As Integer = CInt(Math.Truncate(Math.Cos(angle) * 200))
'INSTANT VB NOTE: The variable y was renamed since Visual Basic does not handle local variables named the same as class members well:
				Dim y_Renamed As Integer = CInt(Math.Truncate(Math.Sin(angle) * 200))
				Dim cx As Integer = Width\2
				Dim cy As Integer = Height\2

				GL2D.Line(cx + x_Renamed, cy + y_Renamed, cx - x_Renamed, cy - y_Renamed)

			Next i

			' draw two simple sprites
			GL.Color4(1.0F, 1.0F, 1.0F, 1.0F)
			GL2D.BlendMode(GL2D.BLEND_MODE.GL2D_ALPHA)
			GL2D.SpriteRotateScale(85, 500, 0, 1, 1, GL2D.SpriteGL.FLIP_H, plantSprite)
			GL2D.SpriteRotateScale(Width-85, 100, 0, 1, 1, GL2D.SpriteGL.FLIP_NONE, plantSprite)

			GL2D.End2D()

			Me.SwapBuffers() ' copy what we draw to screen

			Thread.Sleep(1) ' sleep so that we don't hog CPU

		End Sub


        <STAThread()> _
  Public Shared Sub Main()
            Using example As New GL2Dexample()
                example.Run(60) ' run the game at 60 frames per second
            End Using
        End Sub

	End Class
End Namespace
