I have been developing xith under RPC. It works prefectly. Now because of security reasons, I need to convert it to run on pure Swt Composite/Application. I attached code here. Hope somebody can help me.
package test;
import org.eclipse.swt.SWT;
public class PanelXithCanvas extends Composite {
private Xith3DEnvironment XITH3D_ENVIRONMENT = null;
private RenderLoop RENDER_LOOP;
private GLCanvas GL_CANVAS;
private int GL_WIDTH = 1000;
private int GL_HEIGHT = 1000;
private int GL_MARGIN = 2;
private Canvas3D CANVAS_3D;
private Composite XITH_COMPOSITE;
/**
* Create the composite.
* @param parent
* @param style
*/
public PanelXithCanvas(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
XITH_COMPOSITE = new Composite(this, SWT.NONE);
// XITH_COMPOSITE.setLayout(new GridLayout(1, false));
XITH_COMPOSITE.setLayout(new FillLayout(SWT.HORIZONTAL));
setSceneRecord();
}
private void ClearRenderer() {
CANVAS_3D.clear();
RENDER_LOOP.getXith3DEnvironment().getCanvas().clear();
RENDER_LOOP.getXith3DEnvironment().removeCanvas( CANVAS_3D );
RENDER_LOOP.getXith3DEnvironment().removeAllCanvas3Ds();
RENDER_LOOP.getXith3DEnvironment().removeAllBranchGraphs();
RENDER_LOOP.getXith3DEnvironment().destroy();
RENDER_LOOP.setStopOperation(StopOperation.DESTROY_AND_EXIT);
RENDER_LOOP.end();
GL_CANVAS.dispose();
}
public void setSceneRecord() {
initCommunicationToComposite();
addDisposeListener(new DisposeListener() {
public void widgetDisposed(final DisposeEvent e) {
System.out.println("PanelXithCanvas widgetDisposed");
ClearRenderer();
}
});
}
public void setSceneRecord(int glWidth, int glHeight ) {
GL_WIDTH = glWidth;
GL_HEIGHT = glHeight;
setSceneRecord();
}
private void initCommunicationToComposite() {
//DisplayMode displayMode = DisplayModeSelector.getImplementation( OpenGLLayer.JOGL_SWT ).getBestMode( 800, 600 );
//CanvasConstructionInfo ConstructionInfo = new CanvasConstructionInfo( displayMode, DisplayMode.WINDOWED, "TESTING" );
//CANVAS_3D = Canvas3DFactory.create( ConstructionInfo, PARENT );
Colorf c = new Colorf( 38, 82, 245 );
CANVAS_3D = Canvas3DFactory.create(OpenGLLayer.JOGL_SWT, GL_WIDTH, GL_HEIGHT, FullscreenMode.WINDOWED_UNDECORATED, false, FSAA.OFF, XITH_COMPOSITE );
CANVAS_3D.setBackgroundColor(c);
InitGLCanvas();
XITH3D_ENVIRONMENT = createXithEnvironment();
RENDER_LOOP = new RenderLoop();
RENDER_LOOP.setMaxFPS(120f);
RENDER_LOOP.setXith3DEnvironment(XITH3D_ENVIRONMENT);
RENDER_LOOP.begin(RunMode.RUN_IN_SEPARATE_THREAD);
}
private Xith3DEnvironment createXithEnvironment() {
Tuple3f eyePosition = new Vector3f(0.0f, 0.0f, 10.0f);
Tuple3f viewFocus = new Vector3f(0.0f, 0.0f, 0.0f);
Tuple3f vecUp = new Vector3f(0.0f, 1.0f, 0.0f);
Xith3DEnvironment env = new Xith3DEnvironment();
env.getView().lookAt(eyePosition, viewFocus, vecUp);
env.addCanvas(CANVAS_3D);
env.checkRenderPreferences();
// env.addPerspectiveBranch(createScene());
return env;
}
private void InitGLCanvas(){
// Constraints on the GLCanvas that "holds" the Canvas3D
GridData gdcan = new GridData();
gdcan.widthHint = GL_WIDTH;
gdcan.heightHint = GL_WIDTH;
gdcan.grabExcessHorizontalSpace = true;
gdcan.grabExcessVerticalSpace = true;
gdcan.minimumHeight = GL_WIDTH ;
gdcan.minimumWidth = GL_WIDTH;
GL_CANVAS = ((CanvasPeerImplSWT) CANVAS_3D.getPeer()).getComponent();
GL_CANVAS.setLayoutData(gdcan);
GL_CANVAS.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
System.out.println( " InitGLCanvas() Moved ");
}
public void controlResized(ControlEvent e) {
System.out.println( " InitGLCanvas() Resize = " + XITH_COMPOSITE.getSize() +
" GL_CANVAS Size = " + GL_CANVAS.getSize() +
" CANVAS_3D Size = " + CANVAS_3D.getSize());
}
});
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
The other problem I'm having is exiting the program. In eclipse after terminating the Swt app, the red button still active and I have to force an exit like System.exit(0);
package test;
import org.eclipse.swt.SWT;
public class gcEclipseTestMain {
protected Shell shell;
protected PanelXithCanvas xithCanvas;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
gcEclipseTestMain window = new gcEclipseTestMain();
window.open();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
}
});
shell.setSize(450, 300);
shell.setText("TESTING XITH COMPOSITE");
shell.setLayout(new FillLayout(SWT.HORIZONTAL));
PanelXithCanvas xithCanvas = new PanelXithCanvas(shell, SWT.NONE);
}
}