Show Posts

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.


Messages - jasef

Pages: [1]
1
Support / Re: Disable shading?
« on: December 10, 2012, 08:57:40 pm »
Gotcha, thanks!

2
Support / Re: Disable shading?
« on: December 10, 2012, 04:43:54 pm »
Here's my code (background is now black):

Code: [Select]
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:



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!

3
Support / Re: Disable shading?
« on: December 07, 2012, 11:00:01 pm »
Tried it, doesn't work. I'm trying a GLSLShader next.

4
Support / Re: Disable shading?
« on: December 07, 2012, 10:37:12 pm »
What I really want is flat shading, like GL_FLAT back in the day. I tried making my own IRenderHook and did this:

Code: [Select]
public void beforeRendering(int polyID) {
            GL11.glShadeModel(GL11.GL_FLAT);
        }

but no luck.

Are there any examples of using flat shading using the GLSLShader or IRenderHook classes?

Thanks.

5
Support / Disable shading?
« on: December 07, 2012, 05:40:34 pm »
I'm using the software renderer only.

Is it possible to completely turn off shading? For example, here's a shot from my (modified) "Hello World" example:



(created image using buffer.getOutputBuffer() and ImageIO.write())

I want the only colors in the image to be blue and green, without any blending or anti-aliasing.

Is this possible with jPCT?

Thanks!

Pages: [1]