Esempio n. 1
0
        /// <summary>
        /// Initializes the graphics engine, the renderer, a plain shader program, vertex buffer and the viewport for a given handle.
        /// </summary>
        void InitializeSurface(IntPtr handle)
        {
            System.Diagnostics.Debug.WriteLine("Initialize Engine..");
            // initialize graphics and a renderer using a window handle
            graphics = Engine.initializeGraphics(RenderingAPI.OpenGL);
            renderer = graphics.CreateRenderer(handle);
            renderer.UseSRGBFramebuffer();

            // Create shader program by using shader sources
            ShaderSource[] sources =
            {
                new ShaderSource(ShaderType.VertexShader, Properties.Resources.VertexShader),
                new ShaderSource(ShaderType.PixelShader,  Properties.Resources.FragmentShader)
            };
            shaderProgram = RendererHelper.createShaderProgram(graphics, sources).Value;

            // create shader program manually by creating shaders
            using (IShader vertexShader = graphics.CreateShader(ShaderType.VertexShader, Properties.Resources.VertexShaderColored).Value,
                   pixelShader = graphics.CreateShader(ShaderType.PixelShader, Properties.Resources.FragmentShaderColoredUniform).Value)
            {
                shaderProgramColored = graphics.CreateShaderProgram(new IShader[] { vertexShader, pixelShader }).Value;
            }

            // create textured shader
            ShaderSource[] sourcesTexture =
            {
                new ShaderSource(ShaderType.VertexShader, Properties.Resources.VertexShaderTex),
                new ShaderSource(ShaderType.PixelShader,  Properties.Resources.FragmentShaderTex)
            };
            shaderProgramTextured = RendererHelper.createShaderProgram(graphics, sourcesTexture).Value;

            // Diffuse textures mostly srgb, normals mostly normal rgb
            // create texture
            var settings = new TextureSettings2D(TextureTargetFormat.SRGB8, TextureOriginalFormat.BGR, TextureWrapMode.MirroredRepeat,
                                                 TextureWrapMode.MirroredRepeat, TextureMinifyingFilter.Linear, TextureMagnifyingFilter.Linear, Maybe <Color <float> > .Nothing);

            brickTexture = graphics.CreateTexture2D(settings, @"Resources\BrickGroutless0095_2_XL.jpg").Value;
            mossTexture  = graphics.CreateTexture2D(settings, @"Resources\Moss0177_1_XL.jpg").Value;
            sampler1     = shaderProgramTextured.GetUniform <int>("tex");
            sampler2     = shaderProgramTextured.GetUniform <int>("tex2");

            // use uniform values for shaders
            multiplicator = shaderProgramColored.GetUniform <float>("multiplicator");
            uniformValue  = 0.0f;
            shaderProgramColored.SetUniform(multiplicator, uniformValue);

            CreateVertexBuffer1();

            CreateVertexBuffer2();

            CreateVertexBuffer3();

            renderer.ClearColor(new Color <float>(0.2f, 0.1f, 0.2f, 0.1f));
            renderer.Viewport(new Vec2 <short>(0, 0), new Size <short>((short)Width, (short)Height));
        }