Gotcha, thanks!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
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();
}
}
public void beforeRendering(int polyID) {
GL11.glShadeModel(GL11.GL_FLAT);
}
Page created in 0.019 seconds with 12 queries.