public void Render(MainClass Main) { if (_viewport.Width != Main.Width || _viewport.Height != Main.Height) { _2d = new Bitmap(Main.Width, Main.Height); Graphics g = Graphics.FromImage(_2d); g.FillRectangle(_bg, 0, 0, _2d.Width, _2d.Height); g.DrawString(_text, SystemFonts.DefaultFont, _fg, 0, 0); g.Dispose(); GLUtil.UpdateTexture(_2d, _2dTex); _viewport.Width = Main.Width; _viewport.Height = Main.Height; } GL.UseProgram(0); GL.Enable(EnableCap.Texture2D); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Projection); Matrix4 orth = Matrix4.CreateOrthographicOffCenter(0, 1, 1, 0, -1, 1); GL.LoadMatrix(ref orth); GL.BindTexture(TextureTarget.Texture2D, _2dTex); GL.BindBuffer(BufferTarget.ArrayBuffer, _2dvbo); GL.InterleavedArrays(InterleavedArrayFormat.T2fC4fN3fV3f, 0, (IntPtr)0); GL.DrawArrays(BeginMode.Quads, 0, 4); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); }
public WorldRenderer(MainClass In, World For, float Aspect) { _for = For; _hmap = new HeightmapRenderer(this, _for.Terrain); FragmentShader fsimple = new FragmentShader("res/shader/simple.frag"); FragmentShader fwater = new FragmentShader("res/shader/water.frag"); FragmentShader fuwater = new FragmentShader("res/shader/underwater.frag"); _simple = new ShaderProgram(); _simple.AddFragShader(fsimple); GLUtil.PrintGLError("Simple"); _underwater = new ShaderProgram(); _underwater.AddFragShader(fuwater); GLUtil.PrintGLError("Underwater"); _water = new ShaderProgram(); _water.AddFragShader(fwater); GLUtil.PrintGLError("Water"); _curr = _simple; _aspect = Aspect; _projectionMatrix = Matrix4.CreatePerspectiveFieldOfView((float)(FOV), _aspect, 0.01f, MAX_DEPTH); _modelview = Matrix4.CreateTranslation(-10f, -5f, -10f); _pos = new Vector3(10, 2, 10); _mviewstack = new Stack<Matrix4>(); _in = In; _oldwidth = 0; _oldheight = 0; }
public void Init(MainClass Main) { //XXX:Make this better... _in = Main; //Game world setup. HeightMap map = new HeightMap("res/map.map"); _pe = new PlayerEntity(new Vector3(0, map [0, 0] + 10, 0)); _world = new World(map, _pe); //GFX setup _camOffset = new Vector3(); _ren = new WorldRenderer(Main, _world, (float)Main.Width / Main.Height); GL.ClearColor(OpenTK.Graphics.Color4.SkyBlue); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Fog); float[] fogColor = { OpenTK.Graphics.Color4.SkyBlue.R, OpenTK.Graphics.Color4.SkyBlue.G, OpenTK.Graphics.Color4.SkyBlue.B, OpenTK.Graphics.Color4.SkyBlue.A }; GL.Fog(FogParameter.FogColor, fogColor); GL.Fog(FogParameter.FogEnd, WorldRenderer.MAX_DEPTH); GL.Fog(FogParameter.FogStart, 10f); //Input setup. System.Windows.Forms.Cursor.Hide(); Main.Mouse.ButtonDown += ButtonDown; Main.Mouse.ButtonUp += ButtonUp; Main.Mouse.Move += MouseMove; //2D draw setup _rects = new LinkedList<Rect2D>(); _healthbar = new Bitmap(100, 50); _healthbarRect = new Rect2D(_healthbar, 0, 0, 100, 50); _rects.AddFirst(_healthbarRect); //INput setup _in.MouseCaptureNeeded = true; _in.CaptureMouse = true; }
public void Render(MainClass Win) { GL.Clear(ClearBufferMask.DepthBufferBit); _ren.Render(); _ren.Draw2DRects(_rects); }
public IGameState LeaveTo(MainClass Win) { Win.Mouse.ButtonDown -= ButtonDown; Win.Mouse.ButtonUp -= ButtonUp; return null; }
public void Tick(MainClass Win, double Delta) { if (Win.Keyboard [Key.Escape]) { Win.MouseCaptureNeeded = false; Win.CaptureMouse = false; } if (Win.Keyboard [Key.J]) { Win.MouseCaptureNeeded = true; Win.CaptureMouse = true; } _pe.Move(Win.Keyboard, _mouseDelta); if (_in.CaptureMouse) System.Windows.Forms.Cursor.Position = new Point( _in.X + (_in.Width / 2), _in.Y + (_in.Height / 2) ); if (_lmbDown) { _pe.SwingSword(_world); } _world.Tick((float)Delta); _camOffset.Y = _pe.GetEyeOffset(); _ren.Pos = Vector3.Add(_pe.Pos, _camOffset); _ren.Pitch = _pe.Pitch; _ren.Yaw = _pe.Yaw; foreach (IEntity ent in _world.Ents) { Enemy e = ent as Enemy; if (e != null) { e.AI(_world); } } if (!_pe.Dead) { //Update healthbar bitmap. Graphics g = Graphics.FromImage(_healthbar); g.FillRectangle(Brushes.Gray, 0, 0, 100, 50); int hbw = (int)((_pe.Health / 10.0) * 98); g.FillRectangle(Brushes.Green, 1, 1, hbw, 23); g.FillRectangle(Brushes.Red, 1 + hbw, 1, 98 - hbw, 23); g.DrawString(String.Format("Killed {0} buggers.", _world.BuggersKilled), SystemFonts.DefaultFont, Brushes.Black, 0, 30); g.Dispose(); _healthbarRect.SetTexture(_healthbar); } }