예제 #1
0
        /// <summary>
        /// Initializes the renderer.
        /// </summary>
        public void Initialize()
        {
            _renderContext.Initialize();
            _colorShader = new ShaderProgram();
            var vshader = new VertexShader();
            vshader.Compile(SimpleVertexShader.SourceCode);
            var fshader = new FragmentShader();
            fshader.Compile(SimpleFragmentShader.SourceCode);
            _colorShader.Link(vshader, fshader);
            OpenGLInterops.Enable(OpenGLInterops.GL_BLEND);
            OpenGLInterops.AlphaBlend();
            SetTransform(Matrix2x3.Identity);
            OpenGLColor clearColor = OpenGLHelper.ConvertColor(_graphicsDevice.ClearColor);
            OpenGLInterops.ClearColor(clearColor);
            _windowSize = _window.Size;
            OpenGLInterops.Viewport(0, 0, (int) _windowSize.X, (int) _windowSize.Y);
            _sourceVao = new VertexArray();
            _sourceVao.Bind();
            _colorShader.Bind();
            _sourceEbo = new IndexBuffer();

            var elements = new ushort[]
            {
                0, 1, 2,
                2, 3, 0
            };

            _sourceEbo.Bind();
            _sourceEbo.SetData(elements);

            _sourceVbo = new VertexBuffer();
            _sourceVbo.Bind();

            _graphicsDevice.ClearColorChanged += GraphicsDeviceClearColorChanged;
            _window.ScreenSizeChanged += WindowScreenSizeChanged;
        }
예제 #2
0
 /// <summary>
 /// Links a vertex shader and a fragment shader to this program.
 /// </summary>
 /// <param name="vShader">The VertexShader.</param>
 /// <param name="fShader">The FragmentShader.</param>
 public void Link(VertexShader vShader, FragmentShader fShader)
 {
     OpenGLInterops.AttachShader(Id, vShader.Id);
     OpenGLInterops.AttachShader(Id, fShader.Id);
     OpenGLInterops.BindFragDataLocation(Id, 0, "outColor");
     OpenGLInterops.LinkProgram(Id);
 }