Can jReality implement Anaglyph?

Have jReality programming problems or questions? Post them here.
Post Reply
wruiwr
Posts: 7
Joined: Sun 29. Jun 2014, 12:10

Can jReality implement Anaglyph?

Post by wruiwr » Mon 30. Jun 2014, 02:01

Hi,

I'm a newbie about jReality. I'd like to know if jReality can implement Anaglyph. If it can, it uses software or hardware rendering?

Thanks a lot

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Can jReality implement Anaglyph?

Post by gunn » Tue 29. Jul 2014, 14:00

The JOGL backend of jReality supports anaglyph stereo (red/cyan, red/green, and red/cyan). It's unfortunately not treated in a standard tutorial. Here's how to access it:

1. The class de.jreality.scene.Camera has a method setStereo(boolean b). You have to call this method with the argument true, on the current camera, in order to activate stereo viewing.

2. The actual implementation of the stereo mode is handled by the backend. I am familiar with the behavior of the JOGL backend so I'll describe that here. The base JOGL viewer class de.jreality.jogl.AbstractViewer implements the interface de.jreality.scene.StereoViewer. The important method here is setStereoType(int type). The possibilities are contained at the top of the AbstractViewer source file. Set the type to the one you need (red/cyan is 3 for example).

3. To see an example of how the necessary code looks, look at de.jreality.plugin.experimental.ViewerKeyListener, search for "case KeyEvent.VK_Z". This shows how to activate stereo mode (with the 'Z' key), and how to choose among the different stereo types (with the 'shift-Z' key).

Good luck. Please report any further problems here.
jReality core developer

wruiwr
Posts: 7
Joined: Sun 29. Jun 2014, 12:10

Re: Can jReality implement Anaglyph?

Post by wruiwr » Sat 2. Aug 2014, 11:33

Thank you for your reply!
I tried the following code before according ViewerFromScratch, but it does not work. I don't know why.
Another question I'd like to know is about load texture. if the texture is read into BufferedImage, how to load this texture from BufferedImage.

Code: Select all

public static void main(String[] args) {

        StereoViewer stereoViewer = null;

        SceneGraphComponent rootNode = new SceneGraphComponent("root");
        SceneGraphComponent cameraNode = new SceneGraphComponent("camera");
        SceneGraphComponent geometryNode = new SceneGraphComponent("geometry");
        SceneGraphComponent lightNode = new SceneGraphComponent("light");


        rootNode.addChild(geometryNode);
        rootNode.addChild(cameraNode);
        cameraNode.addChild(lightNode);

        Light dl=new DirectionalLight();
        lightNode.setLight(dl);

        IndexedFaceSet ifs = Primitives.icosahedron();
        geometryNode.setGeometry(ifs);

        RotateTool rotateTool = new RotateTool();
        geometryNode.addTool(rotateTool);

        MatrixBuilder.euclidean().translate(0, 0, 3).assignTo(cameraNode);

        Camera camera = new Camera();
        camera.setStereo(true);
        cameraNode.setCamera(camera);
        SceneGraphPath camPath = new SceneGraphPath(rootNode, cameraNode);
        camPath.push(camera);

       JOGLViewer viewer = new JOGLViewer();

        viewer.setSceneRoot(rootNode);
        viewer.setCameraPath(camPath);

        viewer.setStereoType(3);
        //viewer.setStereoType(0);

        ToolSystem toolSystem = ToolSystem.toolSystemForViewer(viewer);
        toolSystem.initializeSceneTools();

        JFrame frame = new JFrame();
        frame.setVisible(true);
        frame.setSize(640, 480);
        frame.getContentPane().add((Component) viewer.getViewingComponent());
        frame.validate();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent arg0) {
                System.exit(0);
            }
        });

        RenderTrigger rt = new RenderTrigger();
        rt.addSceneGraphComponent(rootNode);
        rt.addViewer(viewer);
    }


wruiwr
Posts: 7
Joined: Sun 29. Jun 2014, 12:10

Re: Can jReality implement Anaglyph?

Post by wruiwr » Sat 2. Aug 2014, 12:14

oh, I just found a solution about loading texture from BufferedImage: make an InputStream for a BufferedImage, then use Input(). I still have a question that in Intro07, apply a texture, I changed the cylinder to a Cone, but the texture does not work for the cone. I don't know why...

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Can jReality implement Anaglyph?

Post by gunn » Sat 2. Aug 2014, 12:55

Regarding anaglyph stereo and your code:

It works for me. To make the effect more visible, I set the diffuse color for polygons and lines to white, and I also doubled the eye separation of the stereo camera. The extra code looks like this:

Code: Select all

        rootNode.setAppearance(new Appearance());
        rootNode.getAppearance().setAttribute("polygonShader.diffuseColor", Color.white);
        rootNode.getAppearance().setAttribute("lineShader.diffuseColor", Color.white);
...
        camera.setEyeSeparation(2*camera.getEyeSeparation());
The result looks like this:
Attachments
stereoTest.png
Screenshot of anaglyph stereo code.
stereoTest.png (46.39 KiB) Viewed 997 times
jReality core developer

wruiwr
Posts: 7
Joined: Sun 29. Jun 2014, 12:10

Re: Can jReality implement Anaglyph?

Post by wruiwr » Sat 2. Aug 2014, 16:40

Thank you! :D
The anaglyph effect is not clear before because of the blue color of the object, but now I can see the red and cyan color. Maybe also set transparency is better. I'll try :)

wruiwr
Posts: 7
Joined: Sun 29. Jun 2014, 12:10

Re: Can jReality implement Anaglyph?

Post by wruiwr » Thu 7. Aug 2014, 15:54

Hi gunn,

I also tried to set the type of the stereo to 2(setStereoType(2)) in order to show red-green anaglyph effect, but I'm not sure if it is right. Since the result doesn't look like red-green
Attachments
1.JPG
red-cyan
1.JPG (25.36 KiB) Viewed 972 times
2.JPG
red-green
2.JPG (19.7 KiB) Viewed 972 times

Post Reply