Here's my code (background is now black):
import com.threed.jpct.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
public class JPCTTest {
private World world;
private FrameBuffer buffer;
private Object3D box;
public JPCTTest() throws Exception {
world = new World();
world.setAmbientLight(255, 255, 255);
Texture green = new Texture(8, 8, Color.GREEN);
TextureManager.getInstance().addTexture("green", green);
box = Primitives.getBox(16f, 2f);
box.setTexture("green");
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.setShadingMode(Object3D.SHADING_FAKED_FLAT);
box.build();
world.addObject(box);
world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
buffer = new FrameBuffer(100, 100, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.clear(java.awt.Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
BufferedImage image = (BufferedImage)(buffer.getOutputBuffer());
DataBufferInt buf = (DataBufferInt) image.getRaster().getDataBuffer();
int[] colors = buf.getData();
HashMap<String, Boolean> colorsMap = new HashMap<String, Boolean>();
for(int i = 0; i < colors.length; i++) {
Color c = new Color(colors[i]);
String rgb = Integer.toHexString(c.getRGB());
rgb = rgb.substring(2, rgb.length());
//System.out.print(rgb+",");
if(!colorsMap.containsKey(rgb)) {
colorsMap.put(rgb, true);
}
}
System.out.println("num colors = "+colorsMap.size());
try {
File outputfile = new File("saved.png");
ImageIO.write(image, "png", outputfile);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
new JPCTTest();
}
}
Here's the image that's saved:
![](http://i.imgur.com/Y2Wzn.png)
As you can see, I count the number of colors and the result is
26.
If it was true "flat" shading, I'd expect two colors in the whole file: pure green (0, 255, 0) and black. But there is some blending/dithering going on.
Any advice appreciated, thanks!