示例#1
0
        public void TestDrawQuad()
        {
            var pixel = new Pixel();

            _window = new GameWindow {
                Width = 200, Height = 200
            };
            _window.RenderFrame += (caller, args) =>
            {
                IGL gl = new GLWrapper();
                gl.ReadBuffer(ReadBufferMode.Front);
                gl.Clear(ClearBufferMask.ColorBufferBit);
                gl.Begin(PrimitiveType.Quads);
                {
                    gl.Color3(1.0f, 1.0f, 1.0f);
                    gl.Vertex2(0.0f, 0.0f);
                    gl.Vertex2(-1.0f, 0.0f);
                    gl.Vertex2(-1.0f, -1.0f);
                    gl.Vertex2(0.0f, -1.0f);
                }
                gl.End();
                _window.SwapBuffers();
                pixel.ReadBuffer(0, 0);
                _window.Close();
            };
            _window.Run();
            Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixel);
        }
        public sealed override void Draw(Action <TexturedVertex2D> vertexAction)
        {
            if (RequiresRedraw)
            {
                SharedData.ResetCurrentEffectBuffer();

                using (establishFrameBufferViewport())
                {
                    // Fill the frame buffer with drawn children
                    using (BindFrameBuffer(SharedData.MainBuffer))
                    {
                        // We need to draw children as if they were zero-based to the top-left of the texture.
                        // We can do this by adding a translation component to our (orthogonal) projection matrix.
                        GLWrapper.PushOrtho(screenSpaceDrawRectangle);
                        GLWrapper.Clear(new ClearInfo(backgroundColour));

                        Child.Draw(vertexAction);

                        GLWrapper.PopOrtho();
                    }

                    PopulateContents();
                }

                SharedData.DrawVersion = GetDrawVersion();
            }

            Shader.Bind();

            base.Draw(vertexAction);
            DrawContents();

            Shader.Unbind();
        }
示例#3
0
        public void TestDrawTransparentTexture()
        {
            var pixels = new[] { new Pixel(), new Pixel(), new Pixel(), new Pixel() };

            _window = new GameWindow {
                Width = 200, Height = 200
            };
            _window.RenderFrame += (caller, args) =>
            {
                IGL gl = new GLWrapper();
                gl.Viewport(0, 0, 200, 200);
                gl.ReadBuffer(ReadBufferMode.Front);

                gl.Enable(EnableCap.Texture2D);
                gl.Enable(EnableCap.Blend);
                gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                gl.ClearColor(1.0f, 1.0f, 0.0f, 1.0f);
                int textureId = GL.GenTexture();
                gl.BindTexture(TextureTarget.Texture2D, textureId);
                gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                var bitmap = new Bitmap(@"..\..\Images\testtexture.png");
                var data   = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                             ImageLockMode.ReadOnly,
                                             System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height,
                              0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
                bitmap.UnlockBits(data);

                gl.Clear(ClearBufferMask.ColorBufferBit);
                gl.Begin(PrimitiveType.Quads);
                {
                    gl.TexCoord2(0.0f, 0.0f);
                    gl.Vertex2(-1.0f, -1.0f);
                    gl.TexCoord2(1.0f, 0.0f);
                    gl.Vertex2(1.0f, -1.0f);
                    gl.TexCoord2(1.0f, 1.0f);
                    gl.Vertex2(1.0f, 1.0f);
                    gl.TexCoord2(0.0f, 1.0f);
                    gl.Vertex2(-1.0f, 1.0f);
                }
                gl.End();
                _window.SwapBuffers();
                pixels[0].ReadBuffer(99, 99);
                pixels[1].ReadBuffer(99, 100);
                pixels[2].ReadBuffer(100, 100);
                pixels[3].ReadBuffer(100, 99);
                _window.Close();
            };
            _window.Run();
            Assert.AreEqual(new Pixel(1.0f, 0.0f, 0.0f), pixels[0]);
            Assert.AreEqual(new Pixel(0.0f, 1.0f, 0.0f), pixels[1]);
            Assert.AreEqual(new Pixel(0.0f, 0.0f, 1.0f), pixels[2]);
            Assert.AreEqual(new Pixel(1.0f, 1.0f, 0.0f), pixels[3]);
        }
 protected override void PreDrawMask(FrameBuffer clippingMask)
 {
     clippingMask.Bind();
     GLWrapper.PushViewport(new RectangleI(0, 0, clippingMask.Texture.Width, clippingMask.Texture.Height));
     GLWrapper.Clear(new ClearInfo(Colour4.White));
     GLWrapper.SetBlend(new BlendingParameters
     {
         Source           = BlendingType.Zero,
         Destination      = BlendingType.OneMinusSrcColor,
         SourceAlpha      = BlendingType.Zero,
         DestinationAlpha = BlendingType.OneMinusSrcAlpha,
     });
 }
            private void drawChildren(Action <TexturedVertex2D> vertexAction, Vector2 frameBufferSize)
            {
                // Fill the frame buffer with drawn children
                using (bindFrameBuffer(currentFrameBuffer, frameBufferSize))
                {
                    // We need to draw children as if they were zero-based to the top-left of the texture.
                    // We can do this by adding a translation component to our (orthogonal) projection matrix.
                    GLWrapper.PushOrtho(screenSpaceDrawRectangle);

                    GLWrapper.Clear(new ClearInfo(backgroundColour));
                    base.Draw(vertexAction);

                    GLWrapper.PopOrtho();
                }
            }
示例#6
0
        public void TestSetModelViewMatrix()
        {
            var pixels = new[] { new Pixel(), new Pixel(), new Pixel(), new Pixel() };

            _window = new GameWindow {
                Width = 200, Height = 200
            };
            _window.RenderFrame += (caller, args) =>
            {
                IGL gl = new GLWrapper();
                gl.MatrixMode(MatrixMode.Projection);
                gl.LoadIdentity();
                gl.Ortho(0.0, 2.0, 0.0, 2.0, 0.0, 4.0);
                gl.Viewport(0, 0, 200, 200);
                gl.MatrixMode(MatrixMode.Modelview);
                gl.ReadBuffer(ReadBufferMode.Front);
                gl.Clear(ClearBufferMask.ColorBufferBit);
                gl.Color3(1.0f, 1.0f, 1.0f);
                DrawQuad();
                gl.PushMatrix();
                gl.Translate(0.0f, 1.0f, 0.0f);
                gl.Color3(1.0f, 0.0f, 0.0f);
                DrawQuad();
                gl.PopMatrix();
                gl.PushMatrix();
                gl.Translate(1.0f, 1.0f, 0.0f);
                gl.Color3(0.0f, 1.0f, 0.0f);
                DrawQuad();
                gl.PopMatrix();
                gl.PushMatrix();
                gl.Translate(1.0f, 0.0f, 0.0f);
                gl.Color3(0.0f, 0.0f, 1.0f);
                DrawQuad();
                gl.PopMatrix();
                _window.SwapBuffers();
                pixels[0].ReadBuffer(99, 99);
                pixels[1].ReadBuffer(99, 100);
                pixels[2].ReadBuffer(100, 100);
                pixels[3].ReadBuffer(100, 99);
                _window.Close();
            };
            _window.Run();
            Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixels[0]);
            Assert.AreEqual(new Pixel(1.0f, 0.0f, 0.0f), pixels[1]);
            Assert.AreEqual(new Pixel(0.0f, 1.0f, 0.0f), pixels[2]);
            Assert.AreEqual(new Pixel(0.0f, 0.0f, 1.0f), pixels[3]);
        }
示例#7
0
        public void TestClear()
        {
            var pixel = new Pixel();

            _window              = new GameWindow();
            _window.RenderFrame += (caller, args) =>
            {
                IGL gl = new GLWrapper();
                gl.ReadBuffer(ReadBufferMode.Front);
                gl.ClearColor(0.4f, 0.2f, 1.0f, 1.0f);
                gl.Clear(ClearBufferMask.ColorBufferBit);
                _window.SwapBuffers();
                pixel.ReadBuffer(0, 0);
                _window.Close();
            };
            _window.Run();
            Assert.AreEqual(new Pixel(0.4f, 0.2f, 1.0f), pixel);
        }