using System;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace PlanetExpress.Tools {	
	
	public class BackgroundStarsClass {
		
		private TexClass Star;
		public BackgroundStarsClass() {
			Star = TexMan.LoadTexture(
	                           GameApp.GameFileName("data", "background", "stars.png")
	                           );
		}
		
		public void Render() {
			GL.PushMatrix(); {
				GL.Translate(0f, 0f, 1f);
				GL.Disable(EnableCap.Texture2D);
				GL.Begin(BeginMode.Quads); {
					GL.Color3(new float[]{0f, 0f, 0.05f});
					GL.Vertex2(0, 0); GL.Vertex2(800, 0);
					GL.Color3(new float[]{0f, 0f, 0.25f});
					GL.Vertex2(GameApp.ScreenWidth, GameApp.ScreenHeight); GL.Vertex2(0, GameApp.ScreenHeight);
				} GL.End();
				
				GL.Enable(EnableCap.Texture2D);
				
				int t = Environment.TickCount;
							
				Random r = new Random(GetHashCode());
				int w = GameApp.ScreenWidth;
				for (int i=0; i<50; i++) {
					GL.Color4(new float[]{1f, 1f, 1f, 1f/60f*i});
					int l = -((t/(20-i/5)) % (w*2)) + r.Next(w*2);
					if (l<-Star.Width) l += w*2;
					Star.Render(l,
				    r.Next(GameApp.ScreenHeight - Star.Height));
				}	
			}GL.PopMatrix();
		}
	}
}
