⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geographictextrenderer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    {                        OrderedText ot = (OrderedText) nextItem;                        if (ot.getRenderer() != GeographicTextRenderer.this)                            return;                        GeographicTextRenderer.this.drawText(dc, ot);                        dc.getOrderedRenderables().poll(); // take it off the queue                        nextItem = dc.getOrderedRenderables().peek();                    }                }            }            catch (WWRuntimeException e)            {                Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionWhileRenderingText", e);            }            catch (Exception e)            {                Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionWhileRenderingText", e);            }            finally            {                GeographicTextRenderer.this.endRendering(dc);            }        }        public void pick(DrawContext dc, java.awt.Point pickPoint)        {        }    }    private Rectangle2D computeTextBounds(DrawContext dc, OrderedText uText) throws Exception    {        GeographicText geographicText = uText.text;        final CharSequence charSequence = geographicText.getText();        if (charSequence == null)            return null;        final Vec4 screenPoint = dc.getView().project(uText.point);        if (screenPoint == null)            return null;        Font font = geographicText.getFont();        if (font == null)            font = DEFAULT_FONT;        try        {            TextRenderer textRenderer = dc.getTextRendererCache().getOrCreate(font);            if (textRenderer != this.lastTextRenderer)            {                if (this.lastTextRenderer != null)                    this.lastTextRenderer.end3DRendering();                textRenderer.begin3DRendering();                this.lastTextRenderer = textRenderer;            }            this.setDepthFunc(dc, uText, screenPoint);            Rectangle2D textBound = textRenderer.getBounds(charSequence);            float x = (float) (screenPoint.x - ( textBound.getWidth() / 2d));            Rectangle2D rect = new Rectangle2D.Float();            rect.setRect(x, (float) (screenPoint.y), textBound.getWidth() , (float)textBound.getHeight());            return rect;        }        catch (Exception e)        {            handleTextRendererExceptions(e);            return null;        }    }        private final int[] viewportArray = new int[4];    private void beginRendering(DrawContext dc)    {        GL gl = dc.getGL();        int attribBits =            GL.GL_ENABLE_BIT // for enable/disable changes                | GL.GL_COLOR_BUFFER_BIT // for alpha test func and ref, and blend                | GL.GL_CURRENT_BIT      // for current color                | GL.GL_DEPTH_BUFFER_BIT // for depth test, depth func, and depth mask                | GL.GL_TRANSFORM_BIT    // for modelview and perspective                | GL.GL_VIEWPORT_BIT;    // for depth range        gl.glPushAttrib(attribBits);        gl.glGetIntegerv(GL.GL_VIEWPORT, viewportArray, 0);        gl.glMatrixMode(GL.GL_PROJECTION);        gl.glPushMatrix();        gl.glLoadIdentity();        glu.gluOrtho2D(0, viewportArray[2], 0, viewportArray[3]);        gl.glMatrixMode(GL.GL_MODELVIEW);        gl.glPushMatrix();        gl.glLoadIdentity();        gl.glMatrixMode(GL.GL_TEXTURE);        gl.glPushMatrix();        gl.glLoadIdentity();        // Enable the depth test but don't write to the depth buffer.        gl.glEnable(GL.GL_DEPTH_TEST);        gl.glDepthMask(false);        // Suppress polygon culling.        gl.glDisable(GL.GL_CULL_FACE);        // Suppress any fully transparent image pixels        gl.glEnable(GL.GL_ALPHA_TEST);        gl.glAlphaFunc(GL.GL_GREATER, 0.001f);    }    private void endRendering(DrawContext dc)    {        if (this.lastTextRenderer != null)        {            this.lastTextRenderer.end3DRendering();            this.lastTextRenderer = null;        }        GL gl = dc.getGL();        gl.glMatrixMode(GL.GL_PROJECTION);        gl.glPopMatrix();        gl.glMatrixMode(GL.GL_MODELVIEW);        gl.glPopMatrix();        gl.glMatrixMode(GL.GL_TEXTURE);        gl.glPopMatrix();        gl.glPopAttrib();    }    private Vec4 drawText(DrawContext dc, OrderedText uText) throws Exception    {        if (uText.point == null)        {            String msg = Logging.getMessage("nullValue.PointIsNull");            Logging.logger().fine(msg);            return null;        }        GeographicText geographicText = uText.text;        final CharSequence charSequence = geographicText.getText();        if (charSequence == null)            return null;        final Vec4 screenPoint = dc.getView().project(uText.point);        if (screenPoint == null)            return null;        Font font = geographicText.getFont();        if (font == null)            font = DEFAULT_FONT;        try        {            TextRenderer textRenderer = dc.getTextRendererCache().getOrCreate(font);            if (textRenderer != this.lastTextRenderer)            {                if (this.lastTextRenderer != null)                    this.lastTextRenderer.end3DRendering();                textRenderer.begin3DRendering();                this.lastTextRenderer = textRenderer;            }            this.setDepthFunc(dc, uText, screenPoint);            Rectangle2D textBounds = textRenderer.getBounds(charSequence);//note:may already be calculated during culling            Point.Float drawPoint = computeDrawPoint(dc, textBounds, screenPoint);            if (drawPoint != null)            {                Color color = geographicText.getColor();                if (color == null)                    color = DEFAULT_COLOR;                Color background = geographicText.getBackgroundColor();                if (background != null)                {                    textRenderer.setColor(background);                    textRenderer.draw3D(charSequence, drawPoint.x + 1, drawPoint.y - 1, 0, 1);                }                textRenderer.setColor(color);                textRenderer.draw3D(charSequence, drawPoint.x, drawPoint.y, 0, 1);                textRenderer.flush();            }        }        catch (Exception e)        {            handleTextRendererExceptions(e);        }        return screenPoint;    }    protected void handleTextRendererExceptions(Exception e) throws Exception    {        if (e instanceof IOException)        {            if (!this.hasJOGLv111Bug)            {                // This is likely a known JOGL 1.1.1 bug - see AMZN-287 or 343                // Log once and then ignore.                Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionWhileRenderingText", e);                this.hasJOGLv111Bug = true;            }        }        else        {            throw e;        }    }    /**     * Computes the final draw point for the given rectangle lower left corner and target screen point.     * If the returned point is <code>null</code> the text will not be drawn.     *     * @param dc the current {@link DrawContext}     * @param rect the text rectangle to draw.     * @param screenPoint the projected screen point the text relates to.     * @return the final draw point for the given rectangle lower left corner or <code>null</code>.     */    @SuppressWarnings({"UnusedDeclaration"})    protected Point.Float computeDrawPoint(DrawContext dc, Rectangle2D rect, Vec4 screenPoint)    {        return new Point.Float((float) (screenPoint.x - rect.getWidth() / 2d), (float) (screenPoint.y));    }    @SuppressWarnings({"UnusedDeclaration"})    private void setDepthFunc(DrawContext dc, OrderedText uText, Vec4 screenPoint)    {        GL gl = dc.getGL();        //if (uText.text.isAlwaysOnTop())        //{        //    gl.glDepthFunc(GL.GL_ALWAYS);        //    return;        //}        Position eyePos = dc.getView().getEyePosition();        if (eyePos == null)        {            gl.glDepthFunc(GL.GL_ALWAYS);            return;        }        double altitude = eyePos.getElevation();        if (altitude < (dc.getGlobe().getMaxElevation() * dc.getVerticalExaggeration()))        {            double depth = screenPoint.z - (8d * 0.00048875809d);            depth = depth < 0d ? 0d : (depth > 1d ? 1d : depth);            gl.glDepthFunc(GL.GL_LESS);            gl.glDepthRange(depth, depth);        }        //else if (screenPoint.z >= 1d)        //{        //    gl.glDepthFunc(GL.GL_EQUAL);        //    gl.glDepthRange(1d, 1d);        //}        else        {            gl.glDepthFunc(GL.GL_ALWAYS);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -