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 EZGL2DexampleParticles
	Public Class GL2Dexample ' inherit the GameWindow class
		Inherits GameWindow

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

		Private bulletSprite As GL2D.SpriteGL ' our bullet texture

		Private particles As New ParticleSystem(2047) ' Particle system

		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

			GL2D.Screen2D(Width, Height) ' init our OpenGL screen

			bulletSprite = GL2D.LoadSprite("data/EZGL2DexampleParticles/bullet.png", CInt(TextureMinFilter.Linear)) ' load the texture

		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)

			' move/kill our particles
			particles.update(Width, Height)

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

		Protected Overrides Sub OnRenderFrame(ByVal e As FrameEventArgs)
			MyBase.OnRenderFrame(e)

			GL2D.ClearScreen() ' clear the screen

			GL2D.Begin2D() ' start 2D drawing mode

			' make the background greenish-blue
			GL.Color4(0.1F, 0.8F, 0.4F, 1.0F)
			' fill the screen with the color by drawing a filled box.
			GL2D.BoxFilled(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)

			' draw our particles in Black for kicks
			GL.Color4(0.0F, 0.0F, 0.0F, 1.0F)
			particles.draw(bulletSprite)

			GL2D.End2D() ' end 2D drawing mode

			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.0) ' run the demo at 60 frames per second
            End Using
        End Sub

	End Class
End Namespace
