Ejemplo n.º 1
0
        /**
         * Implement no stereo ("Mono") while using a stereo device.
         * <p/>
         * Note that this method draws the image twice, once to each of the left and right eye buffers, even when stereo is
         * not in effect. This is to prevent the stereo device from drawing blurred scenes.
         *
         * @param dc the current draw context.
         */
        protected void doDrawStereoNone(DrawContext dc)
        {
            // If running on a stereo device but want to draw a normal image, both buffers must be filled or the
            // display will be blurry.

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glDrawBuffer(GL2.GL_BACK_LEFT);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            super.draw(dc);

            gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            super.draw(dc);
        }
Ejemplo n.º 2
0
        /**
         * Implement stereo using the stereo-enabled graphics device. The mode has an effect only if the display device
         * implements stereo.
         *
         * @param dc the current draw context.
         */
        protected void doDrawToStereoDevice(DrawContext dc)
        {
            GL2  gl     = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
            View dcView = dc.getView();

            // Draw the left eye
            if (this.isSwapEyes())
            {
                gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
            }
            else
            {
                gl.glDrawBuffer(GL2.GL_BACK_LEFT);
            }

            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            super.draw(dc);

            // Move the view to the right eye
            Angle viewHeading = dcView.getHeading();

            dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle()));
            dcView.apply(dc);

            // Draw the right eye
            try
            {
                if (this.isSwapEyes())
                {
                    gl.glDrawBuffer(GL2.GL_BACK_LEFT);
                }
                else
                {
                    gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
                }

                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                super.draw(dc);
            }
            finally
            {
                // Restore the original view heading
                dcView.setHeading(viewHeading);
                dcView.apply(dc);
            }
        }
Ejemplo n.º 3
0
        protected bool generateTexture(DrawContext dc, int width, int height)
        {
            GL2             gl   = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
            OGLStackHandler ogsh = new OGLStackHandler();

            Matrix geoToCartesian = this.computeGeographicToCartesianTransform(this.sector);

            try
            {
                ogsh.pushAttrib(gl, GL2.GL_COLOR_BUFFER_BIT
                                | GL2.GL_ENABLE_BIT
                                | GL2.GL_TRANSFORM_BIT
                                | GL2.GL_VIEWPORT_BIT);

                // Fill the frame buffer with transparent black.
                gl.glClearColor(0f, 0f, 0f, 0f);
                gl.glClear(GL.GL_COLOR_BUFFER_BIT);

                gl.glDisable(GL.GL_BLEND);
                gl.glDisable(GL.GL_CULL_FACE);
                gl.glDisable(GL.GL_DEPTH_TEST);

                // Setup a viewport with the dimensions of the texture, and a projection matrix of dimension 2.0 (along
                // each axis) centered at the origin. Using a projection matrix with these dimensions ensures that incoming
                // vertices are rasterized without any rounding error.
                ogsh.pushProjectionIdentity(gl);
                gl.glViewport(0, 0, width, height);
                gl.glOrtho(-1d, 1d, -1d, 1d, -1d, 1d);

                ogsh.pushModelviewIdentity(gl);
                ogsh.pushTextureIdentity(gl);

                if (this.sourceTexture != null)
                {
                    try
                    {
                        gl.glEnable(GL.GL_TEXTURE_2D);
                        if (!this.sourceTexture.bind(dc))
                        {
                            return(false);
                        }

                        this.sourceTexture.applyInternalTransform(dc);

                        // Setup the texture to replace the fragment color at each pixel.
                        gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);

                        int tessellationDensity = this.getTessellationDensity();
                        this.drawQuad(dc, geoToCartesian, tessellationDensity, tessellationDensity);
                    }
                    finally
                    {
                        gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, OGLUtil.DEFAULT_TEX_ENV_MODE);
                        gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
                    }
                }
            }
            finally
            {
                ogsh.pop(gl);
            }

            return(true);
        }
Ejemplo n.º 4
0
        /**
         * Implement stereo using the red-blue anaglyph technique.
         *
         * @param dc the current draw context.
         */
        protected void doDrawStereoRedBlue(DrawContext dc)
        {
            GL2  gl     = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
            View dcView = dc.getView();

            // Draw the left eye
            if (this.isSwapEyes())
            {
                if (this.isHardwareStereo())
                {
                    gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
                }
                gl.glColorMask(false, true, true, true); // right eye in green/blue
            }
            else
            {
                if (this.isHardwareStereo())
                {
                    gl.glDrawBuffer(GL2.GL_BACK_LEFT);
                }
                gl.glColorMask(true, false, false, true); // left eye in red only
            }

            if (this.isHardwareStereo())
            {
                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            }

            super.draw(dc);

            // Move the view to the right eye
            Angle viewHeading = dcView.getHeading();

            dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle()));
            dcView.apply(dc);

            // Draw the right eye frame green and blue only
            try
            {
                gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
                if (this.isSwapEyes())
                {
                    if (this.isHardwareStereo())
                    {
                        gl.glDrawBuffer(GL2.GL_BACK_RIGHT);
                    }
                    gl.glColorMask(true, false, false, true); // right eye in red only
                }
                else
                {
                    if (this.isHardwareStereo())
                    {
                        gl.glDrawBuffer(GL2.GL_BACK_LEFT);
                    }
                    gl.glColorMask(false, true, true, true); // right eye in green/blue
                }

                if (this.isHardwareStereo())
                {
                    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                }
                super.draw(dc);
            }
            finally
            {
                // Restore the original view heading
                dcView.setHeading(viewHeading);
                dcView.apply(dc);
                gl.glColorMask(true, true, true, true);
            }
        }