World Wind Forums

Go Back   World Wind Forums > WorldWind JAVA forums > Development Help

Development Help Help for building applications or diagnosing problems with WWJ

Reply
 
Thread Tools Display Modes
Old 09-28-2010, 04:10 PM   #1
xander
Member
 
Join Date: Jul 2009
Posts: 30
xander is on a distinguished road
Default Tip: WWJ in Stereo 3D Display

I've recently gone through the exercise of getting WWJ to work on a Samsung stereo TV (one with shutter glasses). Code is based on the WWJ Red/Blue anaglyph code and JOGL sample stereo code as a starting point. See: AnaglyphStereo.java in the WWJ distribution and JOGL demos.

For folks that want to get this working, here's what you need to do:

1) Ensure your video card supports 3D. If it does, then make sure support is turned on. NVIDIA has an entry in their control panel to do this - it is turned off by default.

2) Create a new canvas to replace WorldWindowGLCanvas. It is nearly identical to WorldWindowGLCanvas. Can't inherit from it due to the use of "private" for the "caps" field.

The new canvas class (I use StereoWorldWindowGLCanvas as the name) needs to enable stereo in the caps:

static
{
caps.setAlphaBits(8);
caps.setRedBits(8);
caps.setGreenBits(8);
caps.setBlueBits(8);
caps.setDepthBits(24);

caps.setStereo(true);
}
It needs to set the OpenGL chooser class to a custom one that looks for a 3D mode. Change the first line of the constructor from "super(caps)" to:

super(caps, new StereoGLChooser(), null, null);
Otherwise the constructor is the same as WorldWindowGLCanvas.

The chooser can be added right into the StereoWorldWindowGLCanvas file, and would look like this (modify as needed):

public static class StereoGLChooser extends DefaultGLCapabilitiesChooser {

@Override
public int chooseCapabilities(GLCapabilities glc, GLCapabilities[] glcs, int i) {
// See if the desired caps includes stereo
System.err.println("Wants stereo: " + glc.getStereo());

// Go through the list of capabilities and look for the best match
// that has stereo capabilities. If there aren't any with stereo,
// then print a warning and return the default.
if (glcs != null) {
boolean stereoExists = false;
for (int j = 0; j < glcs.length; j++) {
GLCapabilities c = glcs[j];
if (c != null) {
if (c.getStereo()) {
// This one might be ok
stereoExists = true;
}
}
}
StereoWorldWindowGLCanvas.supportsStereo = stereoExists;
System.err.println("Stereo exists: " + stereoExists);

if (i >= 0 && i < glcs.length)
{
boolean selectedIsStereo = false;
GLCapabilities c = glcs[i];
if (c != null && c.getStereo())
selectedIsStereo = true;
System.err.println("Suggested mode supports stereo: " + selectedIsStereo);
}
else
System.err.println("Suggested mode no supported");
}
else
{
System.err.println("OpenGL mode list is empty");
}
int defaultIndex = super.chooseCapabilities(glc, glcs, i);
if (defaultIndex == i)
System.err.println("Selected mode (" + defaultIndex + ") equals suggested mode");
else
System.err.println("Selected mode (" + defaultIndex
+ ") does not equal suggested mode (" + i + ")");
return defaultIndex;
}
}
3) You will need a new scene controller to render the two eyes.

In worldwind.xml, add a reference to your new scene controller:

<Property name="gov.nasa.worldwind.avkey.SceneCont rollerClassName"
value="org.mycompany.worldwind.ColorSter eoSceneController"/>
The default value for the scene controller is BasicSceneController - just look for that and change it to your class name. I recommend modifying the code in "doRepaint()" where it does the Red/Blue drawing to use the quad-buffered mode like this:

else if (displayMode.equals(DISPLAY_MODE_STEREO) && caps.getStereo())
{
// Do full quad buffered stereo
// Draw left eye
gl.glDrawBuffer(GL.GL_BACK_RIGHT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
this.draw(dc);

// Move the view to the right eye
// TODO: use a view model transform that would work with any pitch - instead of changing the heading
Angle viewHeading = view.getHeading();
view.setHeading(view.getHeading().subtra ct(focusAngle));
view.apply(dc);
// Draw right eye frame green and blue only
gl.glDrawBuffer(GL.GL_BACK_LEFT);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glDisable(GL.GL_FOG);
this.draw(dc);
// Restore original view heading
view.setHeading(viewHeading);
view.apply(dc);
}
...
4) Somewhere in your startup code, init() or the like, you need to build the canvas and set the intended display mode. Code will be like this:

// Create World Window GL Canvas
this.wwd = new StereoWorldWindowGLCanvas();
...

// Set the display mode
ColorStereoSceneController asc = (ColorStereoSceneController) this.wwd.getSceneController();
asc.setDisplayMode(this.displayMode);
5) Make sure display is in proper 3D mode to show alternating left/right frames. Left and right may need to be swapped depending on display versus graphics adapter notion of which frame belongs to which eye.

Xander
xander is offline   Reply With Quote
Old 03-03-2011, 06:29 PM   #2
robotfire
Member
 
Join Date: Feb 2011
Posts: 45
robotfire is on a distinguished road
Default

Would you mind posting the class in its entirety? This is really cool stuff, thanks!

EDIT: Nevermind, you have everything in very good detail that is needed. Thanks again!

Last edited by robotfire; 03-03-2011 at 09:36 PM.
robotfire is offline   Reply With Quote
Old 03-08-2011, 07:45 AM   #3
ken138888
Guest
 
Posts: n/a
Default

thanks for the info
  Reply With Quote
Old 03-09-2011, 01:27 PM   #4
robotfire
Member
 
Join Date: Feb 2011
Posts: 45
robotfire is on a distinguished road
Default

Xander,

Could you tell me what video card you used and what model of TV?

Also, are there any plans to build this capability directly into World Wind in a future release?

Thanks!
robotfire is offline   Reply With Quote
Old 03-18-2011, 01:50 PM   #5
xander
Member
 
Join Date: Jul 2009
Posts: 30
xander is on a distinguished road
Default

This is in answer to the last two posts...

The display is a Samsung 50" stereo display. The display board has a DVI out, from there is a DVI -> HDMI adapter and an HDMI cable to the screen. Really nothing special.

Up to now on the PC I'm using to drive the screen, the only display adapters I have been able to use successfully have been NVIDIA based (I've tried three or four each of ATI and NVIDIA cards). However, it appears that ATI has made some driver updates that make now make it possible to drive OpenGL in the quad-buffer stereo mode. My MacBook also supports stereo output. You will be able to tell if the board/driver supports stereo without having the actual display - the mode will be available to the chooseCapabilities() method in the canvas.

There's not really a lot special you have to do if the driver/control panel for the card has the 3D support. For the NVIDIA based boards there's a selection you need to turn on to enable stereo display (it doesn't appear if the board/driver doesn't support stereo). With the changes from private to protected in the Worldwind classes, the code to start things up is pretty small. I've attached everything you need for a simple applet: an applet that says it wants a stereo mode, a GLCanvas that has a chooser that looks for stereo, and a scene controller that draws to both back buffers.

The canvas is a minor modification of the JOGL code for selecting a stereo mode. The controller is taken from the Red/Blue anaglyph controller in the Worldwind source code.

I couldn't figure out how to ensure which of the buffers goes to left and right eyes. The display doesn't seem to be consistent. You may need to do what did and have an option to force the swap in code (the NVIDIA control panel has an option for that as well, but that's tedious to do every time you start your app).
Attached Files
File Type: zip stereosrc.zip (3.8 KB, 121 views)
xander is offline   Reply With Quote
Old 03-22-2011, 03:52 PM   #6
baellwe
weekend warrior
 
Join Date: May 2008
Posts: 95
baellwe is on a distinguished road
Default

I earlier mentioned the unextensability of WWGLJPanel and WWGLCanvas in this thread http://forum.worldwindcentral.com/sh...ad.php?t=28846 but didn't get any traction. Perhaps someone at WorldWind will notice this and put a patch in place such that we can set custom GLCapabilities with our applications without duplicating the whole class?
baellwe is offline   Reply With Quote
Old 03-22-2011, 06:28 PM   #7
xander
Member
 
Join Date: Jul 2009
Posts: 30
xander is on a distinguished road
Default

Quote:
Originally Posted by baellwe View Post
I earlier mentioned the unextensability of WWGLJPanel and WWGLCanvas in this thread http://forum.worldwindcentral.com/sh...ad.php?t=28846 but didn't get any traction. Perhaps someone at WorldWind will notice this and put a patch in place such that we can set custom GLCapabilities with our applications without duplicating the whole class?
Take a look at the attached files from previous post - between my original posting and that one I was able to move from a rewritten class to one that inherits.
xander is offline   Reply With Quote
Old 03-22-2011, 09:00 PM   #8
baellwe
weekend warrior
 
Join Date: May 2008
Posts: 95
baellwe is on a distinguished road
Default

I updated to the latest WorldWind jar and was able to easily switch to something which looks similar to what you posted. Not quite ideal, but much better!
baellwe is offline   Reply With Quote
Old 03-25-2011, 05:41 PM   #9
robotfire
Member
 
Join Date: Feb 2011
Posts: 45
robotfire is on a distinguished road
Default

So do a lot of cards have the capability to do this?

To get this working, I essentially take your source code and run it.

That leaves one more tiny issue, which is in reference to editing worldwind.xml. Am I supposed to unzip worldwind.jar, edit that file, and zip it up again? You say:

In worldwind.xml, add a reference to your new scene controller:

<Property name="gov.nasa.worldwind.avkey.SceneCont rollerClassName"
value="org.mycompany.worldwind.ColorSter eoSceneController"/>

Thanks!
robotfire is offline   Reply With Quote
Old 07-02-2012, 12:59 PM   #10
mostafa_fahim
Junior Member
 
Join Date: Mar 2012
Posts: 22
mostafa_fahim is on a distinguished road
Default

My main task is to " use a view model transform that would work with any pitch - instead of changing the heading". I want it steroe all the time and can't get the point why the heading only works with a certain range of pitch and why you chose it then? (It's also so in the AnaglyphSceneConrtolloer by PatMurris)..
Which view model transfrom you suggest that works with any pitch?

Thank You
mostafa_fahim is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to setup WWJ Hervé Development Help 96 03-04-2013 03:42 PM
3D stereo anaglyph view for WWJ patmurris Development Help 11 07-02-2012 01:03 PM
How to display 3D models on WWJ? xuqingxin Development Help 7 12-29-2010 01:51 PM
display GEOTIFF files in WWJ martin_ulmschneider Development Help 6 04-30-2009 09:10 AM
WWJ SDK Alpha 3 - 0.3.0 available patmurris WWJ Release Announcements 35 12-03-2007 08:56 PM


All times are GMT +1. The time now is 01:54 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.