Exemplo n.º 1
0
        /// <summary>
        /// Create device and renderbuffer, initialize NV_DX_interop and start rendering.
        /// </summary>
        private void StartRendering()
        {
            _gl = new OpenGL();

            _hwnd = new HwndSource(0, 0, 0, 0, 0, "test", IntPtr.Zero).Handle;

            _gl.Create(SharpGL.Version.OpenGLVersion.OpenGL2_1, RenderContextType.HiddenWindow, 1, 1, 32, _hwnd);

            //  Set the most basic OpenGL styles.
            _gl.ShadeModel(OpenGL.GL_SMOOTH);
            _gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            _gl.ClearDepth(1.0f);

            _gl.Enable(OpenGL.GL_BLEND);
            _gl.Disable(OpenGL.GL_DEPTH_TEST);

            _gl.Enable(OpenGL.GL_TEXTURE_2D);
            _gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_REPLACE);

            _gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);

            //_gl.Enable(OpenGL.GL_MULTISAMPLE);
            //_gl.Enable(OpenGL.GL_MULTISAMPLE_ARB);

            _gl.Hint(0x8534, OpenGL.GL_FASTEST);

            ResizeRendering();

            // leverage the Rendering event of WPF's composition target to
            // update the custom D3D scene
            CompositionTarget.Rendering += OnRenderOpenGL;

            if (GLInitialize != null)
                GLInitialize(this, new EventArgs());
        }
Exemplo n.º 2
0
        protected void BeforeRendering(OpenGL gl, RenderMode renderMode)
        {
            IScientificCamera camera = this.camera;
            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix = ortho.GetViewMat4();
                }
                else
                { throw new NotImplementedException(); }
            }

            modelMatrix = glm.scale(mat4.identity(), new vec3(1, 1, this.ZAxisScale));

            gl.Enable(OpenGL.GL_VERTEX_PROGRAM_POINT_SIZE);
            gl.Enable(OpenGL.GL_POINT_SPRITE_ARB);
            gl.TexEnv(OpenGL.GL_POINT_SPRITE_ARB, OpenGL.GL_COORD_REPLACE_ARB, OpenGL.GL_TRUE);
            gl.Enable(OpenGL.GL_POINT_SMOOTH);
            gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_NICEST);
            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendEquation(OpenGL.GL_FUNC_ADD_EXT);
            gl.BlendFuncSeparate(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA, OpenGL.GL_ONE, OpenGL.GL_ONE);

            ShaderProgram shaderProgram = this.shaderProgram;
            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);

            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
            shaderProgram.SetUniform1(gl, "canvasWidth", viewport[2] + 0.0f);
            shaderProgram.SetUniform1(gl, "canvasHeight", viewport[3] + 0.0f);
            shaderProgram.SetUniform1(gl, "opacity", this.Opacity);

            this.texture.Bind(gl);
            shaderProgram.SetUniform1(gl, "tex", this.texture.TextureName);
            shaderProgram.SetUniform1(gl, "brightness", this.Brightness);
        }