Exemple #1
0
        /**
         * Sets the GL color state to the specified {@link java.awt.Color}, and with the specified color mode. If
         * <code>premultiplyColors</code> is true, this premultipies the Red, Green, and Blue color values by the Alpha
         * value. Otherwise, this does not modify the Red, Green, and Blue color values.
         *
         * @param gl                the GL context.
         * @param color             the Red, Green, Blue, and Alpha values to set.
         * @param premultiplyColors true to premultiply the Red, Green and Blue color values by the Alpha value, false to
         *                          leave the Red, Green, and Blue values unmodified.
         *
         * @throws ArgumentException if the GL is null, if the Color is null, if the opacity is less than 0, or if
         *                                  the opacity is greater than 1.
         */
        public static void applyColor(GL2 gl, java.awt.Color color, bool premultiplyColors)
        {
            if (gl == null)
            {
                String message = Logging.getMessage("nullValue.GLIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (color == null)
            {
                String message = Logging.getMessage("nullValue.ColorIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            float[] compArray = new float[4];
            color.getRGBComponents(compArray);

            if (premultiplyColors)
            {
                compArray[0] *= compArray[3];
                compArray[1] *= compArray[3];
                compArray[2] *= compArray[3];
            }

            gl.glColor4fv(compArray, 0);
        }
Exemple #2
0
        /**
         * Sets the GL color state to the specified {@link java.awt.Color} and opacity, and with the specified color mode.
         * If <code>premultiplyColors</code> is true, this premultipies the Red, Green, and Blue color values by the opacity
         * value. Otherwise, this does not modify the Red, Green, and Blue color values.
         *
         * @param gl                the GL context.
         * @param color             the Red, Green, and Blue values to set.
         * @param opacity           the opacity to set.
         * @param premultiplyColors true to premultiply the Red, Green, and Blue color values by the opacity value, false to
         *                          leave the Red, Green, and Blue values unmodified.
         *
         * @throws ArgumentException if the GL is null, if the Color is null, if the opacity is less than 0, or if
         *                                  the opacity is greater than 1.
         */
        public static void applyColor(GL2 gl, java.awt.Color color, double opacity, bool premultiplyColors)
        {
            if (gl == null)
            {
                String message = Logging.getMessage("nullValue.GLIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (color == null)
            {
                String message = Logging.getMessage("nullValue.ColorIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (opacity < 0d || opacity > 1d)
            {
                String message = Logging.getMessage("generic.OpacityOutOfRange", opacity);
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            float[] compArray = new float[4];
            color.getRGBComponents(compArray);
            compArray[3] = (float)opacity;

            if (premultiplyColors)
            {
                compArray[0] *= compArray[3];
                compArray[1] *= compArray[3];
                compArray[2] *= compArray[3];
            }

            gl.glColor4fv(compArray, 0);
        }
Exemple #3
0
        protected void draw(DrawContext dc)
        {
            try
            {
                // Draw the layers.
                if (dc.getLayers() != null)
                {
                    foreach (Layer layer in dc.getLayers())
                    {
                        try
                        {
                            if (layer != null)
                            {
                                dc.setCurrentLayer(layer);
                                layer.render(dc);
                            }
                        }
                        catch (Exception e)
                        {
                            String message = Logging.getMessage("SceneController.ExceptionWhileRenderingLayer",
                                                                (layer != null ? layer.GetType().Name : Logging.getMessage("term.unknown")));
                            Logging.logger().log(Level.SEVERE, message, e);
                            // Don't abort; continue on to the next layer.
                        }
                    }

                    dc.setCurrentLayer(null);
                }

                // Draw the deferred/ordered surface renderables.
                this.drawOrderedSurfaceRenderables(dc);

                if (this.isDeferOrderedRendering())
                {
                    return;
                }

                if (this.screenCreditController != null)
                {
                    this.screenCreditController.render(dc);
                }

                // Draw the deferred/ordered renderables.
                dc.setOrderedRenderingMode(true);
//            dc.applyGroupingFilters();
                dc.applyClutterFilter();
                while (dc.peekOrderedRenderables() != null)
                {
                    try
                    {
                        dc.pollOrderedRenderables().render(dc);
                    }
                    catch (Exception e)
                    {
                        Logging.logger().log(Level.WARNING,
                                             Logging.getMessage("BasicSceneController.ExceptionDuringRendering"), e);
                    }
                }
                dc.setOrderedRenderingMode(false);

                // Draw the diagnostic displays.
                if (dc.getSurfaceGeometry() != null && dc.getModel() != null && (dc.getModel().isShowWireframeExterior() ||
                                                                                 dc.getModel().isShowWireframeInterior() || dc.getModel().isShowTessellationBoundingVolumes()))
                {
                    Model model = dc.getModel();

                    float[] previousColor = new float[4];
                    GL2     gl            = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
                    gl.glGetFloatv(GL2.GL_CURRENT_COLOR, previousColor, 0);

                    foreach (SectorGeometry sg in dc.getSurfaceGeometry())
                    {
                        if (model.isShowWireframeInterior() || model.isShowWireframeExterior())
                        {
                            sg.renderWireframe(dc, model.isShowWireframeInterior(), model.isShowWireframeExterior());
                        }

                        if (model.isShowTessellationBoundingVolumes())
                        {
                            gl.glColor3d(1, 0, 0);
                            sg.renderBoundingVolume(dc);
                        }
                    }

                    gl.glColor4fv(previousColor, 0);
                }
            }
            catch (Throwable e)
            {
                Logging.logger().log(Level.SEVERE, Logging.getMessage("BasicSceneController.ExceptionDuringRendering"), e);
            }
        }