Пример #1
0
        public void RenderTexture(RTexture texture, Math.Rectangle bounds, RColor color, Matrix matrix, bool font)
        {
            RViewport viewport = REngine.Instance._viewport;

            UpdateQuad(bounds);
            blendState.PlatformApplyState();

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

            defaultShader.Bind();
            defaultShader.SetSamplerValue(RTextureLayer.DIFFUSE, texture);
            vertexQuad2D.Bind();
            vertexQuad2D.BindVertexArray();
            indexQuad2D.Bind();


            defaultShader.SetUniformValue("projection", camera2d.Projection);
            defaultShader.SetUniformValue("view", camera2d.View);
            defaultShader.SetUniformValue("diffuse_color", color.ToVector4());
            defaultShader.SetUniformValue("model", matrix);
            defaultShader.SetUniformValue("font", font);
            vertexQuad2D.VertexDeclaration.Apply(defaultShader, IntPtr.Zero);


            GL.DrawElements(PrimitiveType.Triangles, indexQuad2D.IndexCount, DrawElementsType.UnsignedShort, IntPtr.Zero);
            REngine.CheckGLError();

            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.DstAlpha);
            GL.Disable(EnableCap.Blend);
            indexQuad2D.Unbind();
            vertexQuad2D.UnbindVertexArray();
            vertexQuad2D.Unbind();
            defaultShader.Unbind();
        }
Пример #2
0
        public void RenderText(RFont font, Vector2 penPoint, string text, RColor color)
        {
            blendState.PlatformApplyState();
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.CullFace);
            defaultShader.Bind();
            defaultShader.SetSamplerValue(RTextureLayer.DIFFUSE, font.Texture);


            defaultShader.SetUniformValue("projection", camera2d.Projection);
            defaultShader.SetUniformValue("view", camera2d.View);
            defaultShader.SetUniformValue("diffuse_color", color.ToVector4());
            defaultShader.SetUniformValue("model", Matrix.Identity);
            font.Render(ref defaultShader, ref vertexQuad2D, ref indexQuad2D, text, penPoint, color, Matrix.Identity);


            REngine.CheckGLError();

            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.DstAlpha);
            GL.Disable(EnableCap.Blend);

            defaultShader.Unbind();

            /*text = text.Replace("\r\n", "\n");
             * char lastChar = '\0';
             * Vector2 originalPoint = penPoint;
             * foreach(char c in text)
             * {
             *  if(c == ' ')
             *  {
             *      penPoint.X += font.Kerning(lastChar, c).X+font.SpaceWidth;
             *      lastChar = ' ';
             *      continue;
             *  }
             *  if(c == '\t')
             *  {
             *      penPoint.X += (font.Kerning(lastChar, c).X+(font.SpaceWidth * 2));
             *      continue;
             *  }
             *  if(c == '\r' || c=='\n')
             *  {
             *      penPoint.Y += font.LineHeight + (font.font.Height>>6);
             *      penPoint.X = originalPoint.X+font.Kerning(lastChar, c).X;
             *      continue;
             *  }
             *  penPoint.X += font.Kerning(lastChar, c).X;
             *  RTextureGlyph glyph = font.GetGlyph(c);
             *  int x0 = (int)(penPoint.X + (glyph.bitmapLeft));
             *  int y0 = (int)(penPoint.Y - (glyph.bitmapTop));
             *  //penPoint.X += glyph.Offset.X;
             *
             *  RenderTexture(glyph, new Rectangle(x0, y0, (int)glyph.Bounds.Width, (int)glyph.Bounds.Height), color, Matrix.Identity, true);
             *  penPoint.X += glyph.advance.X;
             *  lastChar = c;
             * }
             * //font.RenderText(defaultShader, text, penPoint.X, penPoint.Y, size, size);
             */
        }
Пример #3
0
        public void Clear(RColor color, bool depth = false, bool stencil = false)
        {
            Reactor.Math.Vector4 clearColor = color.ToVector4();
            GL.ClearColor(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W);
            ClearBufferMask mask = ClearBufferMask.ColorBufferBit;

            if (depth)
            {
                mask |= ClearBufferMask.DepthBufferBit;
            }
            if (stencil)
            {
                mask |= ClearBufferMask.StencilBufferBit;
            }
            GL.Clear(mask);

            Atmosphere.Update();

            REngine.CheckGLError();
        }
Пример #4
0
        public void SetClearColor(RColor color)
        {
            var c = color.ToVector4();

            GL.ClearColor(c.X, c.Y, c.Z, c.W);
        }
Пример #5
0
 public void SetUniformValue(string name, RColor value)
 {
     SetUniformValue(name, value.ToVector4());
 }