/** Company: Shout3D LLC Project: Shout3D Core Class: TestEffect Date: March 23, 2000 Description: A simple example of a PostRenderEffect that inverts the colors of the scene and adds some text on top. (C) Copyright Shout3D LLC. - 1997-2001 - All rights reserved */ package custom_nodes; import shout3d.core.*; import shout3d.*; import shout3d.core.awt.*; import java.awt.*; import java.awt.image.*; /** * TestEffect * * @author Dave Westwood */ public class InvertPlusTextEffect extends PostRenderEffect{ /** * Constructs a default InvertPlusTextEffect node. */ public InvertPlusTextEffect() {} int[] defaultStartPosition = { 160, 0 }; int[] defaultTextVelocity = { 0, 10 }; final public BooleanField invertEnabled = new BooleanField(this, "invertEnabled", Field.ANY, true); final public StringField overlayText = new StringField(this, "overlayText", Field.ANY, "WAZZUP!"); final public IntArrayField startPosition = new IntArrayField(this, "startPosition", Field.ANY, defaultStartPosition); final public IntArrayField textVelocity = new IntArrayField(this, "textVelocity", Field.ANY, defaultTextVelocity); Font bigFont = new Font("Arial", Font.BOLD, 30); int x, y = 0; int xVelo = 0; int yVelo = 10; boolean firstTime = true; public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight) { if (surface_pixel_bits == null) return; // Invert if (invertEnabled.getValue()) { for (int i=0;i>16)&0xff))<<16) + // invert red ((255-((surface_pixel_bits[i]>>8)&0xff))<<8) + // invert green ((255-((surface_pixel_bits[i])&0xff))); // invert blue } } // initialize position and velocity if (firstTime && startPosition.getValue() != null && startPosition.getValue().length > 1) { x = startPosition.getValue()[0]; y = startPosition.getValue()[1]; } if (firstTime && textVelocity.getValue() != null && textVelocity.getValue().length > 1){ xVelo = textVelocity.getValue()[0]; yVelo = textVelocity.getValue()[1]; } firstTime = false; // Draw some text g.setFont(bigFont); g.setColor(java.awt.Color.green); if (x > deviceWidth) x = 0; else if (x < 0) x = deviceWidth; else x+= xVelo; if (y > deviceHeight) y = 0; else if (y < 0) y = deviceHeight; else y+= yVelo; g.drawString(overlayText.getValue(), x, y); } }