Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 01:08:28 am
Xith3D CommunityXith3D InternalsDeveloper discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)HowTo: Render controls in Eclipse Rich Client Plugin with Xith3D
Pages: [1] 2 3
Print
Author Topic: HowTo: Render controls in Eclipse Rich Client Plugin with Xith3D  (Read 7779 times)
simonb
Just dropped in

Offline Offline

Posts: 10

sbar888@hotmail.com
View Profile Email
« on: 17. September 2007, 04:02:11 pm »

Hi,

Firstly, cool library guys!

I am using Xith3D to render controls in an Eclipse RCP (for those not in the know, Eclipse is based on SWT, so I'm using the SWT/JOGL binding).  I am using Eclipse 3.3, and I used all the libraries from the Xith3D-0.9.0-beta2 release, except SWT (those come with Eclipse). 

Creating a plugin for Eclipse that uses 3rdparty libraries requires a fair bit of Eclipse RCP development know-how.  If you gets stumped on ClassNotFoundExceptions even tho the Eclipse IDE can find your classes, then you have fallen into a common trap.  Google Eclipse-RegisterBuddy and Eclipse-BuddyPolicy for help.  Eclipse's class loader mechanisms are not for the faint hearted.

I couldn't find anything in the library (or source) or on the forum about getting it to work in this environment.  If someone has done it before, please let me know, otherwise this is what I did...

 Grin I have managed to get it (mostly) working.

 Undecided I had to perform a little surgery in CanvasPeerSWTImpl.

Eclipse has it's own Display already, and SWT only supports one Display at a time.

Minor surgery
  • Use the Display and Shell from the owner (Object owner is a Composite) when one is provided to the CanvasPeerSWTImpl constructor rather than creating a new Display in the constructor.

Invasive surgery
  • Comment out display.readAndDispatch(); in CanvasPeerSWTImpl.doRender() Eclipse is not expecting it to run outside it's control, I don't know if running it here does bad things to Eclipse or not, but Eclipse can be quiet sensitive, and as it thinks it is in control, lets leave control there.
  • Add this.glCanvas.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true)); right after this.glCanvas = new GLCanvas( comp, SWT.NONE, data );  The control doesn't fill (or show at all) in the owner area if you don't have this.

Eclipse has it's own render loop, and SWT updates must all be done from the same thread.  This means we can't use the Xith3D RenderLoop in either mode because using it in RUN_IN_SEPARATE_THREAD mode will upset Eclipse's SWT and in RUN_IN_SAME_THREAD it requires a shutdown to return control to the Eclipse event loop.

I have included the full ViewPart source.  Please bear in mind that this is an illustration on how I got it to work (and also my first Xith3D attempt).  I still can't figure out what is going on in the lighting!  Shocked 

Code:
package opengl.views;

import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Tuple3f;
import javax.vecmath.Vector3f;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.xith3d.geometry.Cube;
import org.xith3d.geometry.Sphere;
import org.xith3d.render.Canvas3D;
import org.xith3d.render.CanvasPeer.OpenGLLayer;
import org.xith3d.render.base.Xith3DEnvironment;
import org.xith3d.render.canvas.Canvas3DWrapper;
import org.xith3d.render.canvas.CanvasConstructionInfo;
import org.xith3d.render.canvas.Canvas3DWrapper.Resolution;
import org.xith3d.render.config.FSAA;
import org.xith3d.scenegraph.Appearance;
import org.xith3d.scenegraph.BranchGroup;
import org.xith3d.scenegraph.GeometryArray;
import org.xith3d.scenegraph.Light;
import org.xith3d.scenegraph.Material;
import org.xith3d.scenegraph.PointLight;
import org.xith3d.scenegraph.Transform3D;
import org.xith3d.scenegraph.TransformGroup;

/**
 * This sample class demonstrates how to plug-in a new
 * workbench view. The view shows data obtained from the
 * model. The sample creates a dummy model on the fly,
 * but a real implementation would connect to the model
 * available either in this or another plug-in (e.g. the workspace).
 * The view is connected to the model using a content provider.
 * <p>
 * The view uses a label provider to define how model
 * objects should be presented in the view. Each
 * view can present the same model objects using
 * different labels and icons, if needed. Alternatively,
 * a single label provider can be shared between views
 * in order to ensure that objects of the same type are
 * presented in the same way everywhere.
 * <p>
 */

public class Xith3DView extends ViewPart {

    private Xith3DEnvironment env;
    private Canvas3D canvas;

    private Transform3D t3d;
    private TransformGroup tg;
    private int rot;

    private long lastTick = 0;

    /**
     * The constructor.
     */
    public Xith3DView() {
        //     Xith3DDefaults.setDebugMode(true);
        //     Xith3DDefaults.setDebugVerbosity(Integer.MAX_VALUE);
        //        Log.log.registerLog(new ConsoleLog(Integer.MAX_VALUE));
    }

    /**
     * This is a callback that will allow us
     * to create the viewer and initialize it.
     */
    public void createPartControl(final Composite parent) {

        final Composite container = new Composite(parent, SWT.NONE);

        container.setLayout(new GridLayout(1, true));

        env = new Xith3DEnvironment();

        Tuple3f eyePosition = new Vector3f(0.0f, 0.0f, 5.0f);
        Tuple3f viewFocus = new Vector3f(0.0f, 0.0f, 0.0f);
        Tuple3f vecUp = new Vector3f(0.0f, 1.0f, 0.0f);

        env.getView().lookAt(eyePosition, viewFocus, vecUp);

        CanvasConstructionInfo info = new CanvasConstructionInfo();
        info.setOpenGLLayer(OpenGLLayer.JOGL_SWT);
        info.setColorDepth(24);
        info.setDsiplayModeFullscreen(false);
        info.setFSAAMode(FSAA.ON_4X);
        info.setResolution(Resolution.RES_800X600);
        info.setTitle("Woof");

        canvas = new Canvas3DWrapper(info, container);

        env.addCanvas(canvas);

        env.checkRenderPreferences();

        env.addPerspectiveBranch(createScene());

        parent.getDisplay().timerExec(30, new Runnable() {
            @Override
            public void run() {

                if(container.isDisposed()) {
                    return;
                }

                t3d.rotXYZ((float)Math.toRadians(rot), (float)Math.toRadians(rot), (float)Math.toRadians(rot));
                tg.setTransform(t3d);

                rot += 1;
                if(rot == 359) {
                    rot = 0;
                }

                env.render();

                long now = System.currentTimeMillis();

                int msSleep = 40;

                if(now - lastTick > msSleep) {

                    msSleep = 0;

                } else {

                    msSleep = msSleep - (int)(now - lastTick);

                }

                lastTick = now;

                parent.getDisplay().timerExec(msSleep, this);

            }
        });

    }

    /**
     * Passing the focus request to the viewer's control.
     */
    public void setFocus() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void dispose() {
        env.render();
        env.destroy();
        super.dispose();
    }

    /**
     * createScene
     * @return
     */
    private BranchGroup createScene() {

        Light light = new PointLight(new Color3f(1f, 1f, 0f), new Point3f(5f, -5f, 5f), new Point3f(0.005f, 0.005f, 0.005f));

        light.setEnabled(true);

        Appearance app = new Appearance();

        app.setMaterial(new Material(Color3f.BLACK, Color3f.RED, Color3f.WHITE, Color3f.BLACK, 0.8f, true, Material.AMBIENT, true));

        t3d = new Transform3D();
        t3d.rotXYZ((float)Math.toRadians(rot), (float)Math.toRadians(rot), (float)Math.toRadians(rot));
        t3d.setTranslation(1f, 1f, 1f);

        tg = new TransformGroup(t3d);

        Cube cube = new Cube(2f, false);

        tg.addChild(cube);

        cube.setAppearance(app);

        Sphere sphere = new Sphere(24, 18, GeometryArray.COLOR_3, 0.4f);
        sphere.setAppearance(app);

        Transform3D t3dSphere = new Transform3D();
        t3dSphere.setTranslation(1f, 1f, 1f);

        TransformGroup tgSphere = new TransformGroup(t3dSphere);
        tgSphere.addChild(sphere);

        tg.addChild(tgSphere);

        BranchGroup bg = new BranchGroup();
        bg.addChild(light);
        bg.addChild(tg);

        return bg;

    }

}

The working mostly part...  I get the following exception after it runs for a a while (about 10 minutes).  I don't think it's serious, it seems like a timing error somewhere, and I'll continue digging.

Code:
javax.media.opengl.GLException: array vertex_buffer_object must be enabled to call this method
at com.sun.opengl.impl.GLImpl.checkBufferObject(GLImpl.java:28017)
at com.sun.opengl.impl.GLImpl.checkArrayVBOEnabled(GLImpl.java:28074)
at com.sun.opengl.impl.GLImpl.glVertexPointer(GLImpl.java:25309)
at org.xith3d.render.jsr231.ShapeAtomPeer.bindGeometryComponent(ShapeAtomPeer.java:558)
at org.xith3d.render.jsr231.ShapeAtomPeer.setupBuffers(ShapeAtomPeer.java:578)
at org.xith3d.render.jsr231.ShapeAtomPeer.drawGeometry(ShapeAtomPeer.java:685)
at org.xith3d.render.jsr231.ShapeAtomPeer.renderAtom(ShapeAtomPeer.java:1045)
at org.xith3d.render.CanvasPeer.renderAtom(CanvasPeer.java:622)
at org.xith3d.render.jsr231.CanvasPeerImplBase.drawBin(CanvasPeerImplBase.java:490)
at org.xith3d.render.jsr231.CanvasPeerImplBase.renderMain(CanvasPeerImplBase.java:880)
at org.xith3d.render.jsr231.CanvasPeerImplBase.display(CanvasPeerImplBase.java:1052)
at org.xith3d.render.jsr231.CanvasPeerSWTImpl.display(CanvasPeerSWTImpl.java:304)
at org.xith3d.render.jsr231.CanvasPeerSWTImpl.doRender(CanvasPeerSWTImpl.java:320)
at org.xith3d.render.jsr231.CanvasPeerSWTImpl.render(CanvasPeerSWTImpl.java:332)
at org.xith3d.render.jsr231.CanvasPeerImplBase.render(CanvasPeerImplBase.java:1139)
at org.xith3d.render.Renderer.renderOnceInternal(Renderer.java:602)
at org.xith3d.render.Renderer.renderOnce(Renderer.java:628)
at org.xith3d.render.Renderer.renderOnce(Renderer.java:672)
at org.xith3d.render.Renderer.renderOnce(Renderer.java:687)
at org.xith3d.scenegraph.VirtualUniverse.renderOnce(VirtualUniverse.java:161)
at org.xith3d.scenegraph.View.renderOnce(View.java:816)
at org.xith3d.render.base.Xith3DEnvironment.render(Xith3DEnvironment.java:408)
at org.xith3d.render.base.Xith3DEnvironment.render(Xith3DEnvironment.java:425)
at opengl.views.Xith3DView$1.run(Xith3DView.java:120)
at org.eclipse.swt.widgets.Display.timerProc(Display.java:3766)
at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1487)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2969)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 17. September 2007, 07:43:40 pm »

Hi, simonb. Welcome to Xith3D Smiley.

Please checkout the latest SVN trunk. IIRC there were many changes to the SWT renderer AFTER the latest beta release. Kevin Finley (horati) actively uses the JOGL_SWT renderer WITH Xith's RenderLoop. You must use RUN_IN_SAME_THREAD. But in the latest beta the whole SWT stuff is handeled totally differently.

Marvin
Logged
simonb
Just dropped in

Offline Offline

Posts: 10

sbar888@hotmail.com
View Profile Email
« Reply #2 on: 18. September 2007, 08:42:34 am »

Excellent.  I'll check it out. 

I have to be cautious about using development branches.

Any idea when the next stable release is planned?

Thanks.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 18. September 2007, 11:00:20 am »

Any idea when the next stable release is planned?

Well, in principle it should have already be release. We're waiting for some JOODE fixes. So it won't be too long, I guess.

Marvin
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #4 on: 18. September 2007, 12:02:53 pm »

I have to be cautious about using development branches.

Actually I think depending on stable releases for xith is very limiting this days. In my experience, the SVN-builds get better rather then worse for most aspects. Given the fact that most changes to the core are comitted by Marvin, there is little danger of code regression like in project with commits of multiple different people.
Logged

simonb
Just dropped in

Offline Offline

Posts: 10

sbar888@hotmail.com
View Profile Email
« Reply #5 on: 02. October 2007, 02:45:02 pm »

Hi, thanks for the quick responses  Grin

I checked out the Xith3D trunk today and have been trying to get it to render to a composite on an Eclipse ViewPart.  (https://xith3d.svn.sourceforge.net/svnroot/xith3d [rev.1016])

The render loop looks much the same as before.  I am missing something in understanding how the render loop should be run in the ViewPart.  I assume that you are referring to org.xith3d.render.loop.RenderLoop.

If you have a little time, please can you post an outline or a sample of a trivial ViewPart so that I can see the intent.  My attention was drawn to the next tick function, but it expects to be executed between begin and end calls.  If I use begin the current thread is captured when 'run in same thread' is used.  Should I be calling next tick after ending the loop?

Thanks,
Simon.
Logged
horati
Global Moderator
Getting respectable
*****
Offline Offline

Posts: 393


View Profile
« Reply #6 on: 04. October 2007, 01:35:41 am »

Hi all, sorry to be m.i.a. so long but I've been busy with other tasks.  Thanks for sending the personal message as well as keeping this topic in one thread for me.

Short response to what you did: no, no, no!!!  The brief history of the SWT implementation is that it was originally developed as a straight port using JOGL-SWT.  Then, nobody actually used it.  I joined the project and was the first to really use it and discovered the issues you mentioned.  They only arise when running inside a ViewPart within Eclipse so we are a limited group Wink  The CanvasPeerSWTImple was extensively recoded and has been thoroughly tested (although I still have a few If you are using beta2, I thought my changes got published there; however, I cannot remember for certain so they may actually be only in the SVN version.

If you care in more detail than "it works", the implementation creates a 2nd xith render loop thread and manages the inter-thread communication for you.  The only extra work you will notice is that you need to gather up any Eclipse data into some kind of data container; place it in a synchronized queue, and read it from the queue within the XithRenderLoop (probably by overriding loopIteration).

Here is all you need to do to correctly use the SWT implementation.
Code:
    @Override
    public final void createPartControl( Composite parent )
    {
       ...
       this.canvas = Canvas3DFactory.create( OpenGLLayer.JOGL_SWT, displaySize.width, displaySize.height, false, FSAA.OFF, parent );
       ...
    }

IIRC, Canvas3DFactory.create() throws an Exception if parent == null so you must be using a different constructor or old code.

I hope this helps.  If you need more, drop me another PM.


P.S. (for everyone)

If anybody needs me, please be sure to send me a PM via the forum (or use one of my IM accounts if you have that info).
Logged

Kevin
"It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k."
http://stackoverflow.com/users/3474/sylvarking
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #7 on: 04. October 2007, 02:03:28 am »

Short response to what you did: no, no, no!!!  The brief history of the SWT implementation is that it was originally developed as a straight port using JOGL-SWT.  Then, nobody actually used it.  I joined the project and was the first to really use it and discovered the issues you mentioned.  They only arise when running inside a ViewPart within Eclipse so we are a limited group Wink  The CanvasPeerSWTImple was extensively recoded and has been thoroughly tested (although I still have a few If you are using beta2, I thought my changes got published there; however, I cannot remember for certain so they may actually be only in the SVN version.

The latest cooker release is pretty fresh. And it contains all the latest SWT related changes. Though I would not advise you to use this release, since there are pretty heavy changes in the SVN compared to this release (vecmath2 port, merged projects, etc.). So you would have to port your code, if you would use the latest release. SVN trunk is the best choice at the moment (as it almost always is Wink).

(probably by overriding loopIteration).

This is prepareNextFrame() nowadays. Are you still using that old release, Kevin?

IIRC, Canvas3DFactory.create() throws an Exception if parent == null so you must be using a different constructor or old code.

This is true, but only for SWT!


Oh, btw. Thanks for giving support, Kevin Smiley.

Marvin
Logged
horati
Global Moderator
Getting respectable
*****
Offline Offline

Posts: 393


View Profile
« Reply #8 on: 04. October 2007, 10:25:49 am »

(probably by overriding loopIteration).
This is prepareNextFrame() nowadays. Are you still using that old release, Kevin?

Yeah Sad  I really need to get up to date.  As you can see, other issues have been keeping me from working with all the cool stuff Wink

IIRC, Canvas3DFactory.create() throws an Exception if parent == null so you must be using a different constructor or old code.

This is true, but only for SWT!

Absolutely!  Since we now have other folks using the SWT implementation in other contexts, maybe we should discuss logic/alternatives.
Logic:
  • Assumption: SWT will be slower than LWJGL or AWT (and by my testing, it is 2-5% slower which is no big deal to me)
  • Conclusion: SWT will only be used by the limited set of people who want to develop 3D Eclipse plug-ins
  • Assumption: SWT implementation only needs to work within Eclipse
  • Assumption: SWT impementation only needs to work as a plug-in; i.e., something displayed on a ViewPart where the Eclipse launching framework is in control
  • Assumption: Canvas3DFactory is the only valid way to construct a Canvas3D (Should we make the constructor package accessible so that people MUST use the Factory?)
  • Conclusion: Require all users creating an SWT canvas to pass a non-null owner of type org.eclipse...Composite to the factory method

I am by no means the world's expert on the Eclipse framework; it's huge!  If anybody has a better idea how we might cooperate with SWT and/or enforce correct usage, I'll be happy to make minor adjustments.  Thanks Marvin for protecting that area for me Smiley

Also, if somebody using SWT as intended (i.e., within an Eclipse plug-in) has the time to add an example, I would be most appreciative!  It actually doesn't take me too long to create the code for a Hello World plug-in that uses Xith3D; however, I most definitely don't have the time right now to write up documentation or do extensive hand-holding to help someone else get it working.  From past experience, I seem to be the only person who can do it easily/quickly; obviously the goal is for everyone to be able to do it just as easily.  I'll be happy to advise the brave soul willing to take up the task.

Oh, btw. Thanks for giving support, Kevin Smiley.

Happy to help.  I never forget about Xith so I'm just a PM or IM away!

extensively recoded and has been thoroughly tested (although I still have a few If you are using beta2, I thought my changes got published there; however, I cannot remember for certain so they may actually be only in the SVN version.
If anybody needs me, please be sure to send me a PM via the forum (or use one of my IM accounts if you have that info).

should have read:

extensively recoded and has been thoroughly tested (although I still have a few HIAL keyboard issues).  If you are using beta2, I thought my changes got published there; however, I cannot remember for certain so they may actually be only in the SVN version.
If anybody needs me, please be sure to send me a PM via the forum (or use one of my IM accounts if you have that info).
Logged

Kevin
"It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k."
http://stackoverflow.com/users/3474/sylvarking
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #9 on: 04. October 2007, 12:03:22 pm »

Assumption: Canvas3DFactory is the only valid way to construct a Canvas3D (Should we make the constructor package accessible so that people MUST use the Factory?)

Because of the fact, that this assumption is correct, it is implied, that the Canvas3D constructors are already protected Wink.

Conclusion: Require all users creating an SWT canvas to pass a non-null owner of type org.eclipse...Composite to the factory method

This is also already the case. (You implemented that Wink.)

extensively recoded and has been thoroughly tested (although I still have a few HIAL keyboard issues).  If you are using beta2, I thought my changes got published there; however, I cannot remember for certain so they may actually be only in the SVN version.

Everything, which currently is in the HIAL SVN trunk, is already populated through a jar and in being used in Xith3D. I don't know, which HIAL changes you're talking about. Well, I anyway want to fix some Dual-Core threading issues, which this one is one of. But I first want to finish some other tasks.

Marvin
Logged
horati
Global Moderator
Getting respectable
*****
Offline Offline

Posts: 393


View Profile
« Reply #10 on: 05. October 2007, 02:12:51 am »

Because of the fact, that this assumption is correct, it is implied, that the Canvas3D constructors are already protected Wink.

Code:
    public void createPartControl(final Composite parent) {

        final Composite container = new Composite(parent, SWT.NONE);

        canvas = new Canvas3DWrapper(info, container);

Ah, I never checked because I didn't consider using them directly.  Looking at only the above lines from Simon's code snippet, I assumped the Canvas was being created incorrectly and the constructors were public.  I didn't actually notice that it was his modified version of Canvas3DWrapperImpl LOL


This is also already the case. (You implemented that Wink.)

Doesn't mean it was the right thing to do Tongue

Everything, which currently is in the HIAL SVN trunk, is already populated through a jar and in being used in Xith3D. I don't know, which HIAL changes you're talking about. Well, I anyway want to fix some Dual-Core threading issues, which this one is one of. But I first want to finish some other tasks.

Actually, I'm glad to see that you might have a test case for this.  I have test cases (that I've never been able to resolve because I didn't dive into the guts of HIAL) that demonstrate the HIAL issues on my dual-core Mac.  I know I mentioned them in the past but I seemed to be the only one (including folks on my own product's team) experiencing the problem.  Since this was the case, I wrote it off as a Kevin or a Mac issue.  I know that testCaseInMarvinsHands == soonToBeFixedBug.  For me, these problems have been around a very long time and are unrelated to recent HIAL changes.
Logged

Kevin
"It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k."
http://stackoverflow.com/users/3474/sylvarking
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #11 on: 05. October 2007, 11:26:39 am »

Code:
    public void createPartControl(final Composite parent) {

        final Composite container = new Composite(parent, SWT.NONE);

        canvas = new Canvas3DWrapper(info, container);

Ah, I never checked because I didn't consider using them directly.  Looking at only the above lines from Simon's code snippet, I assumped the Canvas was being created incorrectly and the constructors were public.  I didn't actually notice that it was his modified version of Canvas3DWrapperImpl LOL

Well, actually the lines above are simply outdated code (for a long time).

Marvin
Logged
simonb
Just dropped in

Offline Offline

Posts: 10

sbar888@hotmail.com
View Profile Email
« Reply #12 on: 05. October 2007, 04:15:59 pm »

Hi again  Grin

Based on what I've read on this topic and the latest code from the repository, I had another go at getting a simple Eclipse ViewPart going.  Cool!  It is a lot simpler.  Thanks for that.

I noticed that the org.xith3d.render.jsr231.CanvasPeerImplSWT performs the render (interaction with SWT) in the SWT display thread by using display.syncExec(); (if not already in the SWT display thread).

Now the bad news... I just get a grey screen area where the nice rotating cube should be Sad  I have taken everything apart (the libraries with the 3rd party bits) and step by step re-assembled ensuring that everything that is required is available to the RCP framework.  The shared libraries and jars.  I just can't seem to get past the grey area.  I'm running on Linux with nVidia graphics.  I noticed some of the other topics were growling about nVidia.

I've included the full ViewPart source below.  Xith Guru's might spot a glaring fault in initialization or model management (it's the same scene as my first attempt).  I'm really hoping an Eclipse guru can point out that I've missed a part of the initialization if they have a moment to spare.

Many thanks guys.

I have included the profile log of an execution run as well.

Once I have this working, I'll post it as an example and 'Howto' if anyone is interested.

Code:
package opengl.views;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.part.ViewPart;
import org.jagatoo.datatypes.Sized2i;
import org.jagatoo.datatypes.util.ResizeListener2i;
import org.jagatoo.logging.FileLog;
import org.jagatoo.logging.LogChannel;
import org.jagatoo.logging.LogLevel;
import org.openmali.vecmath2.Colorf;
import org.openmali.vecmath2.Point3f;
import org.openmali.vecmath2.Tuple3f;
import org.openmali.vecmath2.Vector3f;
import org.xith3d.base.Xith3DEnvironment;
import org.xith3d.loop.RenderLoop;
import org.xith3d.loop.RenderLoop.RunMode;
import org.xith3d.loop.RenderLoop.StopOperation;
import org.xith3d.render.Canvas3D;
import org.xith3d.render.Canvas3DFactory;
import org.xith3d.render.config.CanvasConstructionInfo;
import org.xith3d.render.config.DisplayMode;
import org.xith3d.render.config.FSAA;
import org.xith3d.render.config.OpenGLLayer;
import org.xith3d.scenegraph.Appearance;
import org.xith3d.scenegraph.BranchGroup;
import org.xith3d.scenegraph.GeometryArray;
import org.xith3d.scenegraph.Light;
import org.xith3d.scenegraph.Material;
import org.xith3d.scenegraph.PointLight;
import org.xith3d.scenegraph.Transform3D;
import org.xith3d.scenegraph.TransformGroup;
import org.xith3d.scenegraph.Material.ColorTarget;
import org.xith3d.scenegraph.primitives.Cube;
import org.xith3d.scenegraph.primitives.Sphere;
import org.xith3d.utility.logging.X3DLog;

/**
 * This sample class demonstrates how to plug-in a new
 * workbench view.
 */

public class Xith3DView extends ViewPart {

    private Xith3DEnvironment env;
    private Canvas3D canvas;
   
    private RenderLoop renderLoop;

    private Transform3D t3d;
    private TransformGroup tg;
    private int rot;

    /**
     * The constructor.
     */
    public Xith3DView() {
        super();
       
        try {
            FileLog log = new FileLog("xith3d.log");
            log.setLogLevel(LogLevel.PROFILE);
            log.setChannelFilter(LogChannel.MASK_ALL);
            X3DLog.getLogManager().registerLog(log);
        } catch (Exception ex) {
            System.err.println("Failed to create log.");
        }
       
    }

    /**
     * This is a callback that will allow us
     * to create the viewer and initialize it.
     */
    public void createPartControl(final Composite parent) {

        try {

            env = new Xith3DEnvironment();
   
            Tuple3f eyePosition = new Vector3f(0.0f, 0.0f, 5.0f);
            Tuple3f viewFocus = new Vector3f(0.0f, 0.0f, 0.0f);
            Tuple3f vecUp = new Vector3f(0.0f, 1.0f, 0.0f);
   
            env.getView().lookAt(eyePosition, viewFocus, vecUp);
   
            CanvasConstructionInfo info = new CanvasConstructionInfo();
            info.setOpenGLLayer(OpenGLLayer.JOGL_SWT);
            info.setDisplayMode(new DisplayMode(OpenGLLayer.JOGL_SWT,100,100,16,60));
            info.setFSAAMode(FSAA.ON_4X);
            info.setTitle("Woof");
            info.setFullscreen(false);
            info.setVSyncEnabled(true);
   
            canvas = Canvas3DFactory.create(info,parent);
           
            canvas.addResizeListener(new ResizeListener2i(){
                @Override
                public void onObjectResized(Sized2i arg0, int arg1, int arg2, int arg3, int arg4) {
                    System.out.println("resized");
                }
            });
           
            env.addCanvas(canvas);
           
            env.checkRenderPreferences();
   
            env.addPerspectiveBranch(createScene());
           
            renderLoop = new RenderLoop(env,20) {
             
                @Override
                protected void prepareNextFrame(long gameTime, long frameTime, TimingMode timingMode) {
                   
                    t3d.rotXYZ((float)Math.toRadians(rot), (float)Math.toRadians(rot), (float)Math.toRadians(rot));
                    tg.setTransform(t3d);
   
                    rot += 1;
                    if(rot == 359) {
                        rot = 0;
                    }
                   
                    super.prepareNextFrame(gameTime, frameTime, timingMode);
                }
               
            };
           
            renderLoop.setStopOperation(StopOperation.DO_NOTHING);
           
            renderLoop.begin(RunMode.RUN_IN_SEPARATE_THREAD);
           
        } catch (Throwable ex) {
           
            System.err.println(ex.toString());
           
        }

    }

    /**
     * Passing the focus request to the viewer's control.
     */
    public void setFocus() {
       
        ((Control)canvas.getCanvasPeer().getComponent()).setFocus();
       
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void dispose() {
        renderLoop.end();
        env.destroy();
        super.dispose();
    }

    /**
     * createScene
     * @return
     */
    private BranchGroup createScene() {

        // create a light

        Light light = new PointLight(new Colorf(1f, 1f, 0f), new Point3f(5f, -5f, 5f), new Point3f(0.005f, 0.005f, 0.005f));

        light.setEnabled(true);

        // general appearance

        Appearance app = new Appearance();

        app.setMaterial(new Material(Colorf.BLACK, Colorf.RED, Colorf.WHITE, Colorf.BLACK, 0.8f, ColorTarget.AMBIENT, true, true));

        // create a cube

        t3d = new Transform3D();
        t3d.rotXYZ((float)Math.toRadians(rot), (float)Math.toRadians(rot), (float)Math.toRadians(rot));
        t3d.setTranslation(1f, 1f, 1f);

        tg = new TransformGroup(t3d);

        Cube cube = new Cube(2f);

        tg.addChild(cube);

        cube.setAppearance(app);

        // put a sphere on a corner of the cube

        Sphere sphere = new Sphere(0.4f, 24, 18, GeometryArray.COLOR_3);
        sphere.setAppearance(app);

        Transform3D t3dSphere = new Transform3D();
        t3dSphere.setTranslation(1f, 1f, 1f);

        TransformGroup tgSphere = new TransformGroup(t3dSphere);
        tgSphere.addChild(sphere);

        tg.addChild(tgSphere);

        // put everything into a branch group

        BranchGroup bg = new BranchGroup();
        bg.addChild(light);
        bg.addChild(tg);

        return bg;

    }

}

LOG File

Code:
JavaSound sound driver initialized with 61 available sources

STARTING FRAME

AtomsCollector.collectNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
Adding light
AtomsCollector.collectNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
AtomsCollector.collectNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
AtomsCollector.collectNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
AtomsCollector.collectNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
AtomsCollector.collectNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
We have 0 Sound Nodes to process in the sound processor org.xith3d.sound.SoundProcessor@17dbeaf
Starting to render the frame
Rendering opaque and transparent bin
Lighting enabled
Blending disabled
Activating texture unit 0
Activating texture unit 0
tetxure mode is MODULATE
Activating texture unit 1
Activating texture unit 2
Activating texture unit 3
Use glsl program id 0
Rendering a shape with geometry : org.xith3d.scenegraph.IndexedTriangleStripArray :
Activating texture unit 0
Rendering a shape with geometry : org.xith3d.scenegraph.TriangleArray :
Activating texture unit 0
Drawing a triangle array with 36 vertices
Done with this Program, so disabling
Done with this Program, so disabling
Done rendering the frame

STARTING FRAME

FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
We have 0 Sound Nodes to process in the sound processor org.xith3d.sound.SoundProcessor@17dbeaf
Starting to render the frame
Rendering opaque and transparent bin
Lighting enabled
Blending disabled
Activating texture unit 0
Activating texture unit 0
tetxure mode is MODULATE
Activating texture unit 1
Activating texture unit 2
Activating texture unit 3
Use glsl program id 0
Rendering a shape with geometry : org.xith3d.scenegraph.IndexedTriangleStripArray :
Activating texture unit 0
Rendering a shape with geometry : org.xith3d.scenegraph.TriangleArray :
Activating texture unit 0
Drawing a triangle array with 36 vertices
Done with this Program, so disabling
Done with this Program, so disabling
Done rendering the frame

STARTING FRAME

FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
We have 0 Sound Nodes to process in the sound processor org.xith3d.sound.SoundProcessor@17dbeaf
Starting to render the frame
Rendering opaque and transparent bin
Lighting enabled
Blending disabled
Activating texture unit 0
Activating texture unit 0
tetxure mode is MODULATE
Activating texture unit 1
Activating texture unit 2
Activating texture unit 3
Use glsl program id 0
Rendering a shape with geometry : org.xith3d.scenegraph.IndexedTriangleStripArray :
Activating texture unit 0
Rendering a shape with geometry : org.xith3d.scenegraph.TriangleArray :
Activating texture unit 0
Drawing a triangle array with 36 vertices
Done with this Program, so disabling
Done with this Program, so disabling
Done rendering the frame

STARTING FRAME

FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
We have 0 Sound Nodes to process in the sound processor org.xith3d.sound.SoundProcessor@17dbeaf
Starting to render the frame
Rendering opaque and transparent bin
Lighting enabled
Blending disabled
Activating texture unit 0
Activating texture unit 0
tetxure mode is MODULATE
Activating texture unit 1
Activating texture unit 2
Activating texture unit 3
Use glsl program id 0
Rendering a shape with geometry : org.xith3d.scenegraph.IndexedTriangleStripArray :
Activating texture unit 0
Rendering a shape with geometry : org.xith3d.scenegraph.TriangleArray :
Activating texture unit 0
Drawing a triangle array with 36 vertices
Done with this Program, so disabling
Done with this Program, so disabling
Done rendering the frame

STARTING FRAME

FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
We have 0 Sound Nodes to process in the sound processor org.xith3d.sound.SoundProcessor@17dbeaf
Starting to render the frame
Rendering opaque and transparent bin
Lighting enabled
Blending disabled
Activating texture unit 0
Activating texture unit 0
tetxure mode is MODULATE
Activating texture unit 1
Activating texture unit 2
Activating texture unit 3
Use glsl program id 0
Rendering a shape with geometry : org.xith3d.scenegraph.IndexedTriangleStripArray :
Activating texture unit 0
Rendering a shape with geometry : org.xith3d.scenegraph.TriangleArray :
Activating texture unit 0
Drawing a triangle array with 36 vertices
Done with this Program, so disabling
Done with this Program, so disabling
Done rendering the frame

... many many frames later ...

STARTING FRAME

FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.BranchGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.PointLight ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Cube ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.TransformGroup ""
FrustumCuller.cullNodeAtoms(): Checking node org.xith3d.scenegraph.primitives.Sphere ""
We have 0 Sound Nodes to process in the sound processor org.xith3d.sound.SoundProcessor@17dbeaf
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #13 on: 05. October 2007, 11:29:41 pm »

Hmm.. I don't see anything crucial in your code. Maybe it has to do with your driver. Please read this thread about driver issues. You could also try to run any example from xith-tk, which do work. If you still get a gray screen with the examples, it's something on your system.

You should at least try to disable FSAA to make sure, there are no problems with that.

Just a few notes to make your code cleaner:
  • Don't use methods from the Math, where you have to cast. Use OpenMaLi's FastMath class instead. Some of the methods there are even way faster.
  • You don't need to create Tuple3f instances to use the lookAt() method. Yuo can use plain floats.
  • Don't call env.checkRenderPreferences() and env.destroy() manually. They are called by the rendering system automatically at the right time.
  • The super call of the prepareNextFrame() method should mostly always be the first one.

Marvin
Logged
simonb
Just dropped in

Offline Offline

Posts: 10

sbar888@hotmail.com
View Profile Email
« Reply #14 on: 12. November 2007, 03:45:14 pm »

Hi, I finally got to get to spend some more time on getting it going.  Grin

I managed to resolve that it wasn't (well, I don't think it is) a driver problem.  I downloaded snippet209 (the rotating torus) that uses JOGL/SWT - the same platform I run Xith on, and it works.

I then ported it to run as an RCP View, and it works.

So, I assumed it was something to do with the initialization of JOGL/SWT by Xith, because all the rest of the Xith code works for lots of people.

After comparing the snippet startup with the org.xith3d.render.jsr231.CanvasPeerImplSWT.java code,
I found that if I changed
(rev 1088, line 2077) glCanvas = new GLCanvas( owner, SWT.EMBEDDED, data );
to
glCanvas = new GLCanvas( owner, SWT.NONE, data );
my model was rendered to the view (rather than just a grey panel).

The SWT.EMBEDDED flag, as I understand it, is intended for embedding AWT controls in SWT.  Part of the bridging mechanism.

I haven't tried interacting with my 3D model (ie, I don't know whether mouse clicks for selecting work).  Have I turned something off, is this required?

If I have to turn SWT.EMBEDDED back on again, I'm going to get a grey canvas again  Undecided

Thanks,
Simon.
« Last Edit: 12. November 2007, 03:51:30 pm by simonb » Logged
Pages: [1] 2 3
Print
Jump to:  

Theme orange-lt created by panic