Example #1
0
        /// <summary>
        /// Called each time the game window is resized, recomputes the scale and offset of the tiles.
        /// </summary>
        /// <param name="width">The width of the game window, in pixels</param>
        /// <param name="height">The height of the game window, in pixels</param>
        internal void OnResize(int width, int height)
        {
            GL.Viewport(0, 0, width, height);

            TileScale =
                Math.Min((float)width /
                         (TileCount.Width * TileSize.Width), (float)height / (TileCount.Height * TileSize.Height));

            float      resScale = (float)width / height;
            float      ratio    = (float)(TileCount.Width * TileSize.Width) / (TileCount.Height * TileSize.Height);
            RectangleF quad     = new RectangleF(0, 0, TileCount.Width, TileCount.Height);

            int tileOffsetX = 0, tileOffsetY = 0;

            if (resScale > ratio)
            {
                quad.Width *= (resScale / ratio);
                quad.X      = (TileCount.Width - quad.Width) / 2;
                tileOffsetX = (int)((width - (TileCount.Width * TileSize.Width * TileScale)) * .5f);
            }
            else
            {
                quad.Height /= (resScale / ratio);
                quad.Y       = (TileCount.Height - quad.Height) / 2;
                tileOffsetY  = (int)((height - (TileCount.Height * TileSize.Height * TileScale)) * .5f);
            }
            TileOffset = new Position(tileOffsetX, tileOffsetY);

            Shader.SetProjection(Matrix4.CreateOrthographicOffCenter(quad.Left, quad.Right, quad.Bottom, quad.Top, 0, 1));
        }
Example #2
0
        internal static void ResetOrtho(Rectangle?ortho = null)
        {
            Ortho = ortho ?? new Rectangle(0, 0, GameBase.WindowManager.Width, GameBase.WindowManager.Height);

            ProjectionMatrix = Matrix4.CreateOrthographicOffCenter(Ortho.Left, Ortho.Right, Ortho.Bottom, Ortho.Top, -1, 1);
            Shader.SetGlobalProperty(@"g_ProjMatrix", ProjectionMatrix);
        }
Example #3
0
        public static GameView DefaultView(int width, int height)
        {
            Matrix4 projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, width, height, 0, 1.0f, 1000.0f);
            Matrix4 viewMatrix       = Matrix4.LookAt(new Vector3(0, 0, 1.0f), Vector3.Zero, Vector3.UnitY);

            return(new GameView(width, height, viewMatrix, projectionMatrix));
        }
        // Uploads our text Bitmap to an OpenGL texture
        // and displays is to screen.
        private void DrawText()
        {
            System.Drawing.Imaging.BitmapData data = TextBitmap.LockBits(
                new System.Drawing.Rectangle(0, 0, TextBitmap.Width, TextBitmap.Height),
                System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, TextBitmap.Width, TextBitmap.Height, PixelFormat.Bgra,
                             PixelType.UnsignedByte, data.Scan0);
            TextBitmap.UnlockBits(data);

            Matrix4 text_projection = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref text_projection);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Color4(Color4.White);
            GL.Enable(EnableCap.Texture2D);
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0, 0); GL.Vertex2(0, 0);
            GL.TexCoord2(1, 0); GL.Vertex2(TextBitmap.Width, 0);
            GL.TexCoord2(1, 1); GL.Vertex2(TextBitmap.Width, TextBitmap.Height);
            GL.TexCoord2(0, 1); GL.Vertex2(0, TextBitmap.Height);
            GL.End();
            GL.Disable(EnableCap.Texture2D);
        }
Example #5
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if (viewport_changed)
            {
                viewport_changed = false;

                GL.Viewport(0, 0, Width, Height);

                Matrix4 ortho_projection = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref ortho_projection);
            }

            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.Begin(BeginMode.Quads);

            GL.TexCoord2(0, 0); GL.Vertex2(0, 0);
            GL.TexCoord2(1, 0); GL.Vertex2(TextBitmap.Width, 0);
            GL.TexCoord2(1, 1); GL.Vertex2(TextBitmap.Width, TextBitmap.Height);
            GL.TexCoord2(0, 1); GL.Vertex2(0, TextBitmap.Height);

            GL.End();

            SwapBuffers();
        }
Example #6
0
        public Viewport(Resolution resolution, Vector2?position = null, Camera camera = null)
        {
            this.Resolution = resolution;
            this.Position   = position ?? Vector2.Zero;

            var pos = new Vector3[] {
                new Vector3(this.Resolution.Width, 0, 0),
                new Vector3(this.Resolution.Width, this.Resolution.Height, 0),
                new Vector3(0, this.Resolution.Height, 0),
                new Vector3(0, 0, 0),
            };

            var tex = new Vector2[] {
                new Vector2(1.0f, 0.0f),
                new Vector2(1.0f, 1.0f),
                new Vector2(0.0f, 1.0f),
                new Vector2(0.0f, 0.0f),
            };

            ViewportShader = Game.ContentManager.Load <ShaderProgram> ("viewport");

            this.ViewportTarget = new Model(new Geometry(BeginMode.Quads)
                                            .AddBuffer("v_pos", new GLBuffer <Vector3> (GLBufferSettings.StaticDraw3FloatArray, pos))
                                            .AddBuffer("v_tex", new GLBuffer <Vector2> (GLBufferSettings.StaticDraw2FloatArray, tex)));

            Matrix = Matrix4.CreateOrthographicOffCenter(0, this.Resolution.Width, 0, this.Resolution.Height, 0, 16);
        }
Example #7
0
        public virtual void Render()
        {
            GL.UseProgram(_shader.Program);

            DrawGridLines();

            var viewRect = new RectangleF(
                x:      (float)AxisX.VisibleMinimum,
                y:      (float)AxisY.VisibleMaximum,
                width:  (float)(AxisX.VisibleMaximum - AxisX.VisibleMinimum),
                height: (float)(AxisY.VisibleMinimum - AxisY.VisibleMaximum)
                );

            _shader.SetShaderMatrix(
                Matrix4.CreateOrthographicOffCenter(
                    viewRect.Left, viewRect.Right, viewRect.Bottom, viewRect.Top, -1, 1
                    )
                );

            DrawSelection();

            foreach (var data in Data.Where(d => d.Visible))
            {
                data.Render(_shader, viewRect, ParentSize, TimeStamp.Zero);
            }
        }
Example #8
0
        private void Window_RenderFrame(object sender, FrameEventArgs e)
        {
            Matrix4 projMat = Matrix4.CreateOrthographicOffCenter(0, window.Width, window.Height, 0, 0, 1);

            GL.LoadMatrix(ref projMat);

            view.ApplyTransforms();

            GL.ClearColor(Color.CornflowerBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            foreach (Block block in level)
            {
                if (block == null)
                {
                    continue;
                }

                SpriteBatch.DrawBlock(block.Type, block.Position, world.BlockSize);
            }

            SpriteBatch.DrawGrid(world);

            window.SwapBuffers();
        }
Example #9
0
        static Sprite()
        {
            SpriteVertex[] vertices = new SpriteVertex[]
            {
                new SpriteVertex(-0.5f, -0.5f, 0.0f, 0.0f),
                new SpriteVertex(+0.5f, -0.5f, 1.0f, 0.0f),
                new SpriteVertex(+0.5f, +0.5f, 1.0f, 1.0f),
                new SpriteVertex(-0.5f, -0.5f, 0.0f, 0.0f),
                new SpriteVertex(+0.5f, +0.5f, 1.0f, 1.0f),
                new SpriteVertex(-0.5f, +0.5f, 0.0f, 1.0f)
            };
            vertexBuffer.Update(vertices);

            int positionLocation = GL.GetAttribLocation(shaderProgram.ID, "Position");

            GL.EnableVertexAttribArray(positionLocation);
            GL.VertexAttribPointer(positionLocation, 2, VertexAttribPointerType.Float, false, Marshal.SizeOf(typeof(Vertex)), 0);

            int texCoordLocation = GL.GetAttribLocation(shaderProgram.ID, "TexCoord");

            GL.EnableVertexAttribArray(texCoordLocation);
            GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, Marshal.SizeOf(typeof(Vertex)), 2 * 4);

            viewMatrixLocation = GL.GetUniformLocation(shaderProgram.ID, "ViewMatrix");
            float   screenHeight = 768;
            float   screenWidth  = screenHeight / Viewer.Instance.Height * Viewer.Instance.Width;
            Matrix4 viewMatrix   = Matrix4.CreateOrthographicOffCenter(0, screenWidth, 0, screenHeight, -1, 1);

            shaderProgram.SetMatrix(viewMatrixLocation, viewMatrix);

            modelMatrixLocation = GL.GetUniformLocation(shaderProgram.ID, "ModelMatrix");

            Viewer.Instance.Resize += Instance_Resize;
        }
Example #10
0
        public GLRenderer(bool rendererVisible)
        {
            var mode = new GraphicsMode(new ColorFormat(32), 24, 0, 0, ColorFormat.Empty, 1);
            var win  = new GameWindow(1920, 1080, mode, "NightcoreStudio Renderer", GameWindowFlags.FixedWindow, DisplayDevice.Default, 3, 3, GraphicsContextFlags.Default);

            win.Visible = rendererVisible;
            if (!rendererVisible)
            {
                win.WindowBorder = WindowBorder.Hidden;
            }
            win.MakeCurrent();
            window = win;

            ImageShader = new ImageShader();
            FlatShader  = new FlatShader();

            GL.Enable(EnableCap.Texture2D);
            GL.ClearColor(Color.Purple);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            ProjectionMatrix = Matrix4.CreateOrthographicOffCenter(0f, 1920f, 1080f, 0f, 0.0f, 1.0f);

            Models.BuildModels();
        }
Example #11
0
        protected internal override void OnLoad()
        {
            base.OnLoad();

            renderTexture              = new RenderTexture(MMW.RenderResolution);
            renderTexture.MagFilter    = TextureMagFilter.Linear;
            renderTexture.MinFilter    = TextureMinFilter.Linear;
            renderTexture.WrapMode     = TextureWrapMode.MirroredRepeat;
            renderTexture.ColorFormat0 = MMW.Configuration.DefaultPixelFormat;
            renderTexture.Load();

            dofShader = (BokehDoFShader)MMW.GetAsset <Shader>("Bokeh DoF");
            if (dofShader == null)
            {
                dofShader = new BokehDoFShader();
                MMW.RegistAsset(dofShader);
            }

            if (GameObject != null)
            {
                Camera        = GameObject.GetComponent <Camera>();
                RenderTexture = Camera.TargetTexture;
            }

            orthoMatrix = Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, -1, 1);
        }
Example #12
0
        public ManaWindow(InitializationParameters initializationParameters)
            : base(GameWindowSettings.Default, GetNativeWindowSettings(initializationParameters))
        {
            _pendingInitializationParameters = initializationParameters;

            if (MainWindow == null)
            {
                MainWindow = this;
            }
            else
            {
                throw new InvalidOperationException("Only one ManaWindow is supported at this time.");
            }

            Console.Clear();
            Console.Title = "Mana Console";

            _log.Info($"Current Working Directory: {Directory.GetCurrentDirectory()}");

            InputProvider         = new ManaWindowInputProvider(this);
            Input.CurrentProvider = InputProvider;

            RenderContext = RenderContext.WrapWindowContext(this);

            _projectionMatrix = Matrix4.CreateOrthographicOffCenter(0f, Width, Height, 0f, -1f, 1f);
        }
Example #13
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            InitializeOpenGL();

            LoadLevel();
            LoadDebugMeshes();

            gwenRenderer = new Gwen.Renderer.OpenTK();
            gwenSkin     = new Gwen.Skin.TexturedBase(gwenRenderer, "GwenSkin.png");
            gwenCanvas   = new Gwen.Control.Canvas(gwenSkin);
            gwenInput    = new Gwen.Input.OpenTK(this);

            gwenInput.Initialize(gwenCanvas);
            gwenCanvas.SetSize(Width, Height);
            gwenCanvas.ShouldDrawBackground = false;

            gwenProjection = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1);

            InitializeUI();

            //Pre-JIT compile both SharpNav and this project for faster first-time runs.
            Assembly sharpNavAssebmly = Assembly.Load(Assembly.GetExecutingAssembly().GetReferencedAssemblies().First(n => n.Name == "SharpNav"));

            PreJITMethods(sharpNavAssebmly);
            PreJITMethods(Assembly.GetExecutingAssembly());
        }
Example #14
0
        /// <summary>
        /// This method have it's own Matrix which is not being roated with camera
        /// </summary>
        public void Draw()
        {
            GL.PushMatrix();
            GL.LoadIdentity();

            Matrix4 orthoProjection = Matrix4.CreateOrthographicOffCenter(0, 640, 480, 0, -1, 1);

            GL.MatrixMode(MatrixMode.Projection);

            GL.PushMatrix();//
            GL.LoadMatrix(ref orthoProjection);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Color4(Color);
            GL.PointSize(_size);

            GL.Begin(PrimitiveType.Points);
            GL.Vertex2(Position.Xy);
            GL.End();

            GL.Disable(EnableCap.Blend);

            GL.PopMatrix();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PopMatrix();
        }
Example #15
0
        private void OnRenderFrame(object sender, FrameEventArgs e)
        {
            //GL.ClearColor(Color4.DarkBlue);
            GL.ClearColor(Color.FromArgb(5, 5, 25));
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            var projection = Matrix4.CreateOrthographicOffCenter(0, Window.Width, Window.Height, 0, 0, 1);

            GL.MatrixMode(MatrixMode.Projection);

            GL.LoadMatrix(ref projection);

            //DrawOldSchoolVertexes();

            var world = Matrix4.CreateTranslation(100, 100, 0);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref world);

            DrawVertexBuffers();

            //world = Matrix4.CreateTranslation(200, 100, 0);
            //GL.MatrixMode(MatrixMode.Modelview);
            //GL.LoadMatrix(ref world);

            //GL.DrawArrays(PrimitiveType.Quads, 0, _vertexBuffer.Length);

            GL.Flush();

            Window.SwapBuffers();
        }
Example #16
0
 private void GenerateProjection(Rect orthoAbs, out Matrix4 projMat)
 {
     if (this.renderMode == RenderMatrix.OrthoScreen)
     {
         Matrix4.CreateOrthographicOffCenter(
             orthoAbs.X,
             orthoAbs.X + orthoAbs.W,
             orthoAbs.Y + orthoAbs.H,
             orthoAbs.Y,
             this.nearZ,
             this.farZ,
             out projMat);
         // Flip Z direction from "out of the screen" to "into the screen".
         projMat.M33 = -projMat.M33;
     }
     else
     {
         Matrix4.CreateOrthographicOffCenter(
             orthoAbs.X - orthoAbs.W * 0.5f,
             orthoAbs.X + orthoAbs.W * 0.5f,
             orthoAbs.Y + orthoAbs.H * 0.5f,
             orthoAbs.Y - orthoAbs.H * 0.5f,
             this.nearZ,
             this.farZ,
             out projMat);
         // Flip Z direction from "out of the screen" to "into the screen".
         projMat.M33 = -projMat.M33;
     }
 }
Example #17
0
 public override void SetPars()
 {
     SetTex("tR", 0);
     SetVec4("col", Col);
     SetFloat("blur", Blur);
     SetMat("proj", Matrix4.CreateOrthographicOffCenter(0, AppInfo.RW, AppInfo.RH, 0, -1, 1));
 }
Example #18
0
        private void Rescale()
        {
            GL.ClearColor(_backColor);
            GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);

            //Specify view in natural coordinates (positive X is right, positive Y is up). This works only if Scale is set properly below
            Matrix4 ortoMatrix;

            if (_acCoupled)
            {
                _bottomVolts = -(float)VisibleVolts / 2;
                _topVolts    = (float)VisibleVolts / 2;
            }
            else
            {
                _bottomVolts = 0f;
                _topVolts    = (float)VisibleVolts;
            }

            ortoMatrix = Matrix4.CreateOrthographicOffCenter(0f, (float)VisibleSeconds, _bottomVolts, _topVolts, 0.0f, 1.0f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref ortoMatrix);

            //Invert X so view can be specified naturally (above)
            Vector3 scaleVector = new Vector3(-1f, 1f, 1f);

            GL.Scale(scaleVector);
        }
Example #19
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            GL.ClearColor(Color.LightSkyBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            _gridsizeX = _gridsize * (ClientRectangle.Width / (double)_originalWidth);
            _gridsizeY = _gridsize * (ClientRectangle.Height / (double)_originalHeight);
            var world = Matrix4.CreateOrthographicOffCenter(0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);

            GL.LoadMatrix(ref world);
            foreach (var wall in _walls)
            {
                DrawPixel(wall.Item1, wall.Item2, Color.Blue); //TODO iswalkable
            }

            foreach (var monster in _monsters)
            {
                DrawPixel(monster.PositionX, monster.PositionY, Color.Red);
            }

            foreach (var npc in _npcs)
            {
                DrawPixel(npc.PositionX, npc.PositionY, Color.Yellow);
            }

            GL.Flush();
            SwapBuffers();
            Thread.Sleep(32);
        }
        public void CreateViewportMatrix()
        {
            // ビュー、プロジェクション行列
#if false
            // 透視投影
            float   aspect     = (float)Math.Abs((float)m_GLGraphics.GetWidth() / m_GLGraphics.GetHeight());
            Vector3 eyePos     = new Vector3(0.0f, 0.0f, 5.0f);
            Vector3 lookAt     = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 eyeUp      = new Vector3(0.0f, 1.0f, 0.0f);
            Matrix4 viewMatrix = Matrix4.LookAt(eyePos, lookAt, eyeUp);

            Matrix4 projectionMatrix     = Matrix4.CreatePerspectiveFieldOfView((float)System.Math.PI / 4.0f, (float)m_GLGraphics.GetWidth() / (float)m_GLGraphics.GetHeight(), 0.1f, 100.0f);
            Matrix4 viewProjectionMatrix = viewMatrix * projectionMatrix;
#else
            var x      = Position.X + (FrustrumWidth * (1.0f - Zoom) / 2.0f);
            var width  = (Position.X + FrustrumWidth) - (FrustrumWidth * (1.0f - Zoom) / 2.0f);
            var y      = Position.Y + (FrustrumHeight * (1.0f - Zoom) / 2.0f);
            var height = (Position.Y + FrustrumHeight) - (FrustrumHeight * (1.0f - Zoom) / 2.0f);

            // 平行投影
            m_ViewProjectionMatrix = Matrix4.Identity;
            Matrix4.CreateOrthographicOffCenter(
                //0f, FrustrumWidth,
                //FrustrumHeight, 0f,
                x, width,
                height, y,
                0f, 1f,
                out m_ViewProjectionMatrix);
#endif
        }
Example #21
0
        public override void Render()
        {
            GL.UseProgram(_shader.Program);

            DrawGridLines();

            DrawSelection();

            var inputs = Data.Where(d => d.Visible).OfType <ITimeData>();

            if (!inputs.Any())
            {
                return;
            }

            //// 0. if there are 1D signals, sync to them
            //// TODO: feels like a bad idea
            //if (inputs.Any(i => i is DataLine1D)) {
            //    inputs = inputs.OfType<DataLine1D>();
            //}

            //// 1. get biggest length
            //ITimeData biggestData = inputs.First();
            //foreach (var input in inputs) {
            //    if (input.Duration.Begin.AsSeconds() > biggestData.Duration.Begin.AsSeconds()) {
            //        biggestData = input;
            //    }
            //}

            //// 2. get its time point at 0
            //var timeRef = AlignLines ? biggestData.Duration.Begin : TimeStamp.Zero();

            var timeRef = GetCurrentTimeReference();

            // 3. use as reference time point to translate others to
            foreach (var data in Data.Where(d => d.Visible).OfType <ITimeData>())
            {
                var factor = data.SamplesPerSecond / (double)SamplesPerSecond;

                var viewRect = new RectangleF(
                    x: (float)((AxisX.VisibleMinimum) * factor),
                    y: (float)(AxisY.VisibleMaximum),
                    width: (float)(Math.Min(Milliseconds * SamplesPerSecond / 1000 - Math.Max(AxisX.VisibleMinimum, 0), AxisX.VisibleMaximum - AxisX.VisibleMinimum) * factor),
                    height: (float)(AxisY.VisibleMinimum - AxisY.VisibleMaximum)
                    );

                _shader.SetShaderMatrix(
                    Matrix4.CreateOrthographicOffCenter(
                        left:   viewRect.Left,
                        right: (float)((AxisX.VisibleMaximum) * factor),
                        bottom: viewRect.Bottom,
                        top:    viewRect.Top,
                        zNear: -1,
                        zFar:   1
                        )
                    );

                data.Render(_shader, viewRect, ParentSize, timeRef);
            }
        }
Example #22
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            InitializeOpenGL();

            if (_level != null)
            {
                LoadLevel();
            }
            LoadDebugMeshes();

            gwenRenderer = new Gwen.Renderer.OpenTK();
            gwenSkin     = new Gwen.Skin.TexturedBase(gwenRenderer, "GwenSkin.png");
            gwenCanvas   = new Gwen.Control.Canvas(gwenSkin);
            gwenInput    = new Gwen.Input.OpenTK(this);

            gwenInput.Initialize(gwenCanvas);
            gwenCanvas.SetSize(Width, Height);
            gwenCanvas.ShouldDrawBackground = false;

            gwenProjection = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1);

            InitializeUI();
            if (true && _level == null && clientData == null)
            {
                LoadClient(@"C:\Dark Age of Camelot_Latest");
                //_levelId = 221;
                _levelId = 79;
            }
        }
        public void Render(FrameEventArgs e)
        {
            GL.Viewport(0, 0, sceneManager.Width, sceneManager.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, sceneManager.Width, 0, sceneManager.Height, -1.0f, +1.0f);

            ball.Render(projectionMatrix);
            paddlePlayer.Render(projectionMatrix);
            paddlePlayer2.Render(projectionMatrix);
            speedPowerUp.Render(projectionMatrix);
            lengthPowerUp.Render(projectionMatrix);

            float width = sceneManager.Width, height = sceneManager.Height, fontSize = Math.Min(width, height) / 10f;

            GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 1f)), ("" + scorePlayer), (int)fontSize / 2, StringAlignment.Near);
            GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 1f)), (scorePlayer2 + ""), (int)fontSize / 2, StringAlignment.Far);
            if (GamerOver == false)
            {
                GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 1f)), ("Time: " + clock + "." + Timer), (int)fontSize / 2, StringAlignment.Center);
            }
            else
            {
                GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 10f)), ("Game Over"), (int)fontSize * 2, StringAlignment.Center);
                GUI.Label(new Rectangle(0, (int)(fontSize * 3f), (int)width, (int)(fontSize * 10f)), (" " + winner), (int)fontSize / 2, StringAlignment.Center);
            }
            //GUI.Label(new Rectangle(0, (int)(fontSize / 16f), (int)width, (int)(fontSize * 4f)), ("Player " + scorePlayer + "       AI: " + scoreAI), (int)fontSize, StringAlignment.Center);
            //GUI.Label(new Rectangle(0, (int)(fontSize / 16f), (int)width, (int)(fontSize * 4f)), ("X " + ball.Velocity.X + "       Y: " + ball.Velocity.Y), (int)fontSize, StringAlignment.Center);
            GUI.Render();
        }
Example #24
0
        public void Render(float x, float y, float rotation = 0, float scale = 1,
                           float layer = -1, bool fillScreen = false)
        {
            GL.UseProgram(Shader);

            float left = 0, right = fillScreen ? 2 : engine.Width * orthoFactor;
            float bottom = 0, top = fillScreen ? 2 : engine.Height * orthoFactor;
            float posX = x * orthoFactor / scale, posY = y * orthoFactor / scale;

            Matrix4.CreateTranslation(posX + 1, posY + 1, layer, out var model);
            Matrix4.CreateOrthographicOffCenter(left, right, top, bottom, 0.1f, 100f, out var projection);
            Matrix4.CreateRotationZ(rotation, out var rot);
            Matrix4.CreateScale(scale, out var sc);

            GL.BindTexture(TextureTarget.Texture2D, textureID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, EBO);
            GL.BindVertexArray(VAO);

            GL.UniformMatrix4(modelLocation, 1, false, ref model.Row0.X);
            GL.UniformMatrix4(projLocation, 1, false, ref projection.Row0.X);
            GL.UniformMatrix4(scaleLocation, 1, false, ref sc.Row0.X);
            GL.UniformMatrix4(rotLocation, 1, false, ref rot.Row0.X);

            GL.DrawElements(PrimitiveType.Triangles, 8, DrawElementsType.UnsignedInt, 0);
        }
Example #25
0
        public TextureRenderer(ContentManager content, int width, int height)
        {
            shader = content.LoadShaderProgram("Shaders/texture.vs", "Shaders/texture.fs");
            shader.Use();
            shader.SetMatrix4("model", false, Matrix4.Identity);
            shader.SetMatrix4("proj", false, Matrix4.CreateOrthographicOffCenter(0f, width, height, 0f, -1f, 1f));
            shader.SetMatrix4("view", false, Matrix4.Identity);
            shader.SetInt("texture", 0);
            shader.Clear();

            float[] vertexData = new float[] {
                0f, 0f, 0f, 0f,
                0f, 1f, 0f, 1f,
                1f, 0f, 1f, 0f,

                1f, 0f, 1f, 0f,
                0f, 1f, 0f, 1f,
                1f, 1f, 1f, 1f,
            };

            vertexArray = new VertexArray();
            vertexArray.Bind();
            vertexArray.SetBufferData(vertexData);
            vertexArray.EnableAttribute(0, 2, VertexAttribPointerType.Float, 4, 0);
            vertexArray.EnableAttribute(1, 2, VertexAttribPointerType.Float, 4, 2);
            vertexArray.Unbind();
        }
Example #26
0
        public void Draw()
        {
            Rectangle  rect = new Rectangle(0, 0, _textBitmap.Width, _textBitmap.Height);
            BitmapData data = _textBitmap.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, _textBitmap.Width, _textBitmap.Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, data.Scan0);
            _textBitmap.UnlockBits(data);
            GL.PushMatrix();
            GL.LoadIdentity();
            Matrix4 ortho_projection = Matrix4.CreateOrthographicOffCenter(0, _clientSize.Width, _clientSize.Height, 0, -1, 10000);

            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadMatrix(ref ortho_projection);
            GL.Enable(EnableCap.Blend);                   // прозрачность OneMinusSrcColor SrcColor
            GL.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.SrcColor);
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, _textureId);
            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0, 1); GL.Vertex2(0, _clientSize.Height);
            GL.TexCoord2(1, 1); GL.Vertex2(_clientSize.Width, _clientSize.Height);
            GL.TexCoord2(1, 0); GL.Vertex2(_clientSize.Width, 0);
            GL.TexCoord2(0, 0); GL.Vertex2(0, 0);
            GL.End();
            GL.PopMatrix();
            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Texture2D);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PopMatrix();
            _gfx.Clear(Color.FromArgb(255, 170, 170, 175));
        }
Example #27
0
        /// <summary>
        /// Calculates the texture update.
        /// </summary>
        /// <param name="cont">The controller.</param>
        /// <param name="timeNow">The current time.</param>
        /// <param name="tclient">The game client.</param>
        public void CalcTexture(VRController cont, double timeNow, GameClientWindow tclient)
        {
            if (timeNow == CTime)
            {
                return;
            }
            CTime = timeNow;
            tclient.Shaders.ColorMultShader.Bind();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FBO);
            GL.Disable(EnableCap.CullFace);
            GL.Viewport(0, 0, 512, 512);
            GL.ClearBuffer(ClearBuffer.Color, 0, new float[] { 0.5f, 0.5f, 0.5f, 1.0f });
            GL.ActiveTexture(TextureUnit.Texture0);
            BaseTexture.Bind();
            Matrix4 basic = Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, -1, 1);

            GL.UniformMatrix4(1, false, ref basic);
            GL.UniformMatrix4(2, false, ref id);
            tclient.Engine3D.Rendering.RenderRectangle(-1, -1, 1, 1);
            bool touched = cont.Touched.HasFlag(VRButtons.TRACKPAD);
            bool pressed = cont.Pressed.HasFlag(VRButtons.TRACKPAD);

            if (touched || pressed)
            {
                BaseTexture.Engine.White.Bind();
                tclient.Engine3D.Rendering.SetColor(pressed ? PressSpotColor : TouchSpotColor, tclient.Engine3D.MainView);
                Vector2 hsize = pressed ? PressSpotHalfSize : TouchSpotHalfSize;
                tclient.Engine3D.Rendering.RenderRectangle(cont.TrackPad.X - hsize.X, cont.TrackPad.Y - hsize.X, cont.TrackPad.X + hsize.X, cont.TrackPad.Y + hsize.Y);
            }
            GL.BindTexture(TextureTarget.Texture2D, 0);
            tclient.Engine3D.Rendering.SetColor(Color4.White, tclient.Engine3D.MainView);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, tclient.Engine3D.MainView.cFBO);
            GL.Enable(EnableCap.CullFace);
            tclient.Engine3D.MainView.FixVP();
        }
Example #28
0
        public Renderer(GLControl c)
        {
            camera = new Camera();

            frameRate    = 60;
            control      = c;
            renderThread = null;

            perspective  = Matrix4.CreatePerspectiveFieldOfView((float)(Math.PI / 2), (float)control.Width / (float)control.Height, 1, 1000);
            orthographic = Matrix4.CreateOrthographicOffCenter(0, 2, 0, 2, -1, 1);

            rotateModel      = false;
            updateBuffers    = false;
            updateCamera     = false;
            clearDisplayList = false;

            overlay           = false;
            updateOverlayList = false;
            clearOverlayList  = false;

            nextProjectionMatrix = Matrix4.Identity;

            shaderProgram = 0;
            rotationAngle = (float)(Math.PI / 180);

            nextModels   = new List <UploadableObject>();
            nextOverlays = new List <OverlayUploader>();

            initializeControl();
        }
Example #29
0
        public void Draw()
        {
            GL.PushMatrix();
            GL.LoadIdentity();

            Matrix4 orthoProjection = Matrix4.CreateOrthographicOffCenter(0, ClientSize.Width, ClientSize.Height, 0, -1, 1);

            GL.MatrixMode(MatrixMode.Projection);

            GL.PushMatrix();//
            GL.LoadMatrix(ref orthoProjection);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.DstColor);
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, _textureId);

            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0, 0); GL.Vertex2(0, 0);
            GL.TexCoord2(1, 0); GL.Vertex2(_textBitmap.Width, 0);
            GL.TexCoord2(1, 1); GL.Vertex2(_textBitmap.Width, _textBitmap.Height);
            GL.TexCoord2(0, 1); GL.Vertex2(0, _textBitmap.Height);
            GL.End();
            GL.PopMatrix();

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Texture2D);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.PopMatrix();
        }
Example #30
0
        public void EndRender()
        {
            this.Graphics.Dispose();

            BitmapData data = Image.LockBits(new Rectangle(0, 0, Image.Width, Image.Height),
                                             ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Image.Width, Image.Height, 0,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            Image.UnlockBits(data);

            GL.Enable(EnableCap.Texture2D);

            GL.PushMatrix();

            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Projection);

            GL.PushMatrix();
            Matrix4 ortho = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1);

            GL.LoadMatrix(ref ortho);


            VertexBuffer.Bind(PrimitiveType.Quads);

            GL.PopMatrix();

            GL.MatrixMode(MatrixMode.Modelview);
            GL.PopMatrix();

            GL.Disable(EnableCap.Texture2D);
        }