protected void beginDrawAnnotations(DrawContext dc, OGLStackHandler stackHandler)
        {
            GL2 gl = dc.getGL().getGL2();                 // GL initialization checks for GL2 compatibility.

            int attributeMask = GL2.GL_COLOR_BUFFER_BIT   // for alpha test func and ref, blend func
                                | GL2.GL_CURRENT_BIT      // for current color
                                | GL2.GL_DEPTH_BUFFER_BIT // for depth test, depth mask, depth func
                                | GL2.GL_ENABLE_BIT       // for enable/disable changes
                                | GL2.GL_HINT_BIT         // for line smoothing hint
                                | GL2.GL_LINE_BIT         // for line width, line stipple
                                | GL2.GL_TRANSFORM_BIT    // for matrix mode
                                | GL2.GL_VIEWPORT_BIT;    // for viewport, depth range

            stackHandler.pushAttrib(gl, attributeMask);

            // Load a parallel projection with dimensions (viewportWidth, viewportHeight)
            stackHandler.pushProjectionIdentity(gl);
            gl.glOrtho(0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);

            // Push identity matrices on the texture and modelview matrix stacks. Leave the matrix mode as modelview.
            stackHandler.pushTextureIdentity(gl);
            stackHandler.pushModelviewIdentity(gl);

            // Enable the alpha test.
            gl.glEnable(GL2.GL_ALPHA_TEST);
            gl.glAlphaFunc(GL2.GL_GREATER, 0.0f);

            // Apply the depth buffer but don't change it.
            if ((!dc.isDeepPickingEnabled()))
            {
                gl.glEnable(GL.GL_DEPTH_TEST);
            }
            gl.glDepthMask(false);

            // Disable lighting and backface culling.
            gl.glDisable(GL2.GL_LIGHTING);
            gl.glDisable(GL.GL_CULL_FACE);

            if (!dc.isPickingMode())
            {
                // Enable blending in premultiplied color mode.
                gl.glEnable(GL.GL_BLEND);
                OGLUtil.applyBlending(gl, true);
            }
            else
            {
                this.pickSupport.beginPicking(dc);
            }
        }
        //**************************************************************//
        //********************  Diagnostic Support  ********************//
        //**************************************************************//

        /**
         * Causes this SurfaceObject to render its bounding sectors to the specified region in geographic coordinates. The
         * specified viewport denotes the geographic region and its corresponding screen viewport.
         * <p/>
         * The bounding sectors are rendered as a 1 pixel wide green outline.
         *
         * @param dc  the current DrawContext.
         * @param sdc the context containing a geographic region and screen viewport corresponding to a surface tile.
         *
         * @see #getSectors(DrawContext)
         */
        protected void drawBoundingSectors(DrawContext dc, SurfaceTileDrawContext sdc)
        {
            List <Sector> sectors = this.getSectors(dc);

            if (sectors == null)
            {
                return;
            }

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

            int attributeMask =
                GL2.GL_COLOR_BUFFER_BIT // For alpha test enable, blend enable, alpha func, blend func.
                | GL2.GL_CURRENT_BIT    // For current color.
                | GL2.GL_LINE_BIT;      // For line smooth, line width.

            OGLStackHandler ogsh = new OGLStackHandler();

            ogsh.pushAttrib(gl, attributeMask);
            ogsh.pushModelview(gl);
            try
            {
                gl.glEnable(GL.GL_BLEND);
                OGLUtil.applyBlending(gl, false);

                gl.glDisable(GL.GL_LINE_SMOOTH);
                gl.glLineWidth(1f);

                gl.glColor4f(1f, 1f, 1f, 0.5f);

                // Set the model-view matrix to transform from geographic coordinates to viewport coordinates.
                Matrix matrix = sdc.getModelviewMatrix();
                gl.glMultMatrixd(matrix.toArray(new double[16], 0, false), 0);

                foreach (Sector s in sectors)
                {
                    LatLon[] corners = s.getCorners();
                    gl.glBegin(GL2.GL_LINE_LOOP);
                    gl.glVertex2f((float)corners[0].getLongitude().degrees, (float)corners[0].getLatitude().degrees);
                    gl.glVertex2f((float)corners[1].getLongitude().degrees, (float)corners[1].getLatitude().degrees);
                    gl.glVertex2f((float)corners[2].getLongitude().degrees, (float)corners[2].getLatitude().degrees);
                    gl.glVertex2f((float)corners[3].getLongitude().degrees, (float)corners[3].getLatitude().degrees);
                    gl.glEnd();
                }
            }
            finally
            {
                ogsh.pop(gl);
            }
        }
Ejemplo n.º 3
0
        /**
         * Configures the GL attached to the specified DrawContext for rendering a 2D model to a texture. The modelview
         * matrix is set to the identity, the projection matrix is set to an orthographic projection aligned with the
         * specified draw rectangle (x, y, width, height), the viewport and scissor boxes are set to the specified draw
         * rectangle, and the depth test and depth write flags are disabled. Because the viewport and scissor boxes are set
         * to the draw rectangle, only the texels intersecting the specified drawing rectangle (x, y, width, height) are
         * affected by GL commands. Once rendering is complete, this should always be followed with a call to {@link
         * #endRendering(gov.nasa.worldwind.render.DrawContext)}.
         *
         * @param dc     the current DrawContext.
         * @param x      the x-coordinate of the draw region's lower left corner.
         * @param y      the y-coordinate of the draw region's lower left corner.
         * @param width  the draw region width.
         * @param height the draw region height.
         *
         * @throws ArgumentException if the DrawContext is null.
         */
        public void beginRendering(DrawContext dc, int x, int y, int width, int height)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

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

            this.drawRegion = new java.awt.Rectangle(x, y, width, height);

            // Note: there is no attribute bit for framebuffer objects. The default framebuffer object state (object ID 0
            // is bound as the current fbo) is restored in endRendering().
            this.stackHandler.pushAttrib(gl,
                                         GL2.GL_COLOR_BUFFER_BIT   // For clear color.
                                         | GL2.GL_DEPTH_BUFFER_BIT // For depth test and depth mask.
                                         | GL2.GL_SCISSOR_BIT      // For scissor test and scissor box.
                                         | GL2.GL_TRANSFORM_BIT    // For matrix mode.
                                         | GL2.GL_VIEWPORT_BIT);   // For viewport state.

            this.stackHandler.pushTextureIdentity(gl);
            this.stackHandler.pushProjectionIdentity(gl);
            gl.glOrtho(x, x + width, y, y + height, -1, 1);
            this.stackHandler.pushModelviewIdentity(gl);

            // Disable the depth test and writing to the depth buffer. This provides consistent render to texture behavior
            // regardless of whether we are using copy-to-texture or framebuffer objects. For copy-to-texture, the depth
            // test and depth writing are explicitly disabled. For fbos there is no depth buffer components, so the depth
            // dest is implicitly disabled.
            gl.glDisable(GL.GL_DEPTH_TEST);
            gl.glDepthMask(false);
            // Enable the scissor test and set both the scissor box and the viewport to the specified region. This enables
            // the caller to set up rendering to a subset of the texture. Note that the scissor box defines the region
            // affected by a call to glClear().
            gl.glEnable(GL.GL_SCISSOR_TEST);
            gl.glScissor(x, y, width, height);
            gl.glViewport(x, y, width, height);

            if (this.useFramebufferObject(dc))
            {
                this.beginFramebufferObjectRendering(dc);
            }
        }
Ejemplo n.º 4
0
        public void beginPicking(DrawContext dc)
        {
            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_CURRENT_BIT);

            gl.glDisable(GL.GL_DITHER);
            gl.glDisable(GL2.GL_LIGHTING);
            gl.glDisable(GL2.GL_FOG);
            gl.glDisable(GL.GL_BLEND);
            gl.glDisable(GL.GL_TEXTURE_2D);

            if (dc.isDeepPickingEnabled())
            {
                gl.glDisable(GL.GL_DEPTH_TEST);
            }
        }
Ejemplo n.º 5
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);
        }