public GradientBackground(Component canvas) { super("Background"); this.canvas = canvas; canvas.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { super.componentResized(e); update(); } }); int width = Math.max(canvas.getWidth(), 10); int height = Math.max(canvas.getHeight(), 10); backgroundQuad = new Quad("BackgroundQuad", width, height); backgroundQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); backgroundQuad.getSceneHints().setOrthoOrder(1); update(); attachChild(backgroundQuad); final ZBufferState zstate = new ZBufferState(); zstate.setWritable(false); zstate.setEnabled(false); setRenderState(zstate); getSceneHints().setRenderBucketType(RenderBucketType.Skip); }
private void update() { int width = Math.max(canvas.getWidth(), 10); int height = Math.max(canvas.getHeight(), 10); backgroundQuad.resize(width, height); backgroundQuad.setTranslation(width / 2.0, height / 2.0, 0.0); BufferedImage gradientImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) gradientImage.getGraphics(); GradientPaint gp = new GradientPaint(0, 0, colorButtom, 0, height, colorTop); g2d.setPaint(gp); g2d.fillRect(0, 0, width, height); g2d.dispose(); final TextureState ts = new TextureState(); ts.setTexture( TextureManager.loadFromImage( AWTImageLoader.makeArdor3dImage(gradientImage, false), Texture.MinificationFilter.Trilinear)); backgroundQuad.setRenderState(ts); }
/** * Initialize texture renderers. Load water textures. Create shaders. * * @param r */ private void initialize(final Renderer r) { if (cam == null || initialized) { return; } initialized = true; final ContextCapabilities caps = ContextManager.getCurrentContext().getCapabilities(); if (useRefraction && useProjectedShader && caps.getNumberOfFragmentTextureUnits() < 6 || useRefraction && caps.getNumberOfFragmentTextureUnits() < 5) { useRefraction = false; logger.info("Not enough textureunits, falling back to non refraction water"); } if (!caps.isGLSLSupported()) { supported = false; } if (!(caps.isPbufferSupported() || caps.isFBOSupported())) { supported = false; } if (isSupported()) { tRenderer = TextureRendererFactory.INSTANCE.createTextureRenderer( // cam.getWidth() / renderScale, // width cam.getHeight() / renderScale, // height 8, // Depth bits... TODO: Make configurable? 0, // Samples... TODO: Make configurable? r, caps); // blurSampleDistance = 1f / ((float) cam.getHeight() / renderScale); tRenderer.setMultipleTargets(true); tRenderer.setBackgroundColor(new ColorRGBA(0.0f, 0.0f, 0.0f, 1.0f)); tRenderer .getCamera() .setFrustum( cam.getFrustumNear(), cam.getFrustumFar(), cam.getFrustumLeft(), cam.getFrustumRight(), cam.getFrustumTop(), cam.getFrustumBottom()); textureState = new TextureState(); textureState.setEnabled(true); setupTextures(); fullScreenQuad = new Quad("FullScreenQuad", cam.getWidth() / 4, cam.getHeight() / 4); fullScreenQuad.setTranslation(cam.getWidth() / 2, cam.getHeight() / 2, 0); fullScreenQuad.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); fullScreenQuad.getSceneHints().setCullHint(CullHint.Never); fullScreenQuad.getSceneHints().setTextureCombineMode(TextureCombineMode.Replace); fullScreenQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off); final TextureState ts = new TextureState(); ts.setTexture(textureReflect); fullScreenQuad.setRenderState(ts); fullScreenQuad.setRenderState(blurShaderVertical); fullScreenQuad.updateWorldRenderStates(false); } if (!isSupported()) { createFallbackData(); } else { noFog = new FogState(); noFog.setEnabled(false); } getSceneHints().setCullHint(CullHint.Never); setWaterEffectOnSpatial(this); }