i’m trying to use SWT as the rendering context for a GL binding and there were some posts in the archive that suggested lwjgl provided this. however, the latest cvs pull doesn’t contain anything.
but maybe someone can help me. i’ve been trying to modify the bindings i’ve found here
http://dev.eclipse.org/viewcvs/index.cgi/platform-swt-home/opengl/opengl.html?rev=1.6
and this derivative
http://www.realityinteractive.com/software/oss/
my plan was to get this working with the provided (basic) opengl binding, then modify it to use lwjgl or jogl, but this window system binding is not my cup of tea and going through lwjgl/jogl source today was not illuminating.
i’m able to create a shell and apparently attach an opengl context, but nothing happens when i call opengl commands. what is required to bind the opengl library to a rendering context?
any help would be appreciated.
sean
-------- attached test files -----------
my modified SwtGLContext file:
public class SwtGLContext
{
private int mContextHandle;
private Control mControl;
private int mGcHandle;
private GCData mGcData;
private int mXDisplayHandle;
private int mXDrawableHandle;
/**
* Constructs a SwtGLContext object.
* @param pControl
*/
public SwtGLContext(Control pControl)
{
if (pControl == null)
{
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
mControl = pControl;
mGcData = new GCData();
mGcHandle = pControl.internal_new_GC(mGcData);
if (mGcHandle == 0)
{
SWT.error(SWT.ERROR_NO_HANDLES);
}
mXDisplayHandle = OS.gdk_x11_drawable_get_xdisplay(mGcData.drawable);
mXDrawableHandle = OS.gdk_x11_drawable_get_xid(mGcData.drawable);
int vAttributes[] = {
XGL.GLX_RGBA,
XGL.GLX_DOUBLEBUFFER,
0 };
int vScreen = OS.XDefaultScreen(mXDisplayHandle);
int vVisualInfoHandle =
XGL.glXChooseVisual(mXDisplayHandle, vScreen, vAttributes);
if (vVisualInfoHandle == 0)
{
SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
}
XVisualInfo vVisualInfo = new XVisualInfo();
XGL.memmove(vVisualInfo, vVisualInfoHandle, XVisualInfo.sizeof);
//OS.XFree(vVisualInfoHandle); // no longer provided
mContextHandle = XGL.glXCreateContext(mXDisplayHandle, vVisualInfo, 0, true);
if (mContextHandle == 0)
{
SWT.error(SWT.ERROR_NO_HANDLES);
}
}
public void makeCurrent()
{
int vCurrent = XGL.glXGetCurrentContext();
// Check to see if context is already current
if (vCurrent == mContextHandle)
{
return;
}
XGL.glXMakeCurrent(mXDisplayHandle, mXDrawableHandle, mContextHandle);
}
public void swapBuffers()
{
XGL.glXSwapBuffers(mXDisplayHandle, mXDrawableHandle);
}
public void dispose()
{
// If the context is current, disable
if (mContextHandle != 0)
{
if (XGL.glXGetCurrentContext() == mContextHandle)
{
XGL.glXMakeCurrent(mXDisplayHandle, 0, 0);
}
// Destroy context
XGL.glXDestroyContext(mXDisplayHandle, mContextHandle);
mContextHandle = 0;
}
if (!mControl.isDisposed())
{
// Dispose of GC
mControl.internal_dispose_GC(mGcHandle, mGcData);
}
mControl = null;
mGcHandle = 0;
mGcData = null;
}
}
and the test class:
public class SwtTest
{
/**
* Constructs a SwtTest object.
*/
public SwtTest()
{
Display vDisplay = new Display();
Shell vShell = new Shell(vDisplay);
vShell.setText(“SwtTest”);
// create the OpenGL context with the shell as its parent
SwtGLContext vContext = new SwtGLContext(vShell);
vContext.makeCurrent();
vShell.open();
while (!vShell.isDisposed())
{
if (!vDisplay.readAndDispatch())
{
vDisplay.sleep();
}
if (vShell.isDisposed())
{
break;
}
GL.glClearColor(1,1,1,1);
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();
GL.glBegin(GL.GL_TRIANGLE_STRIP);
GL.glVertex3d(0, 0, 0);
GL.glVertex3d(0, 1, 0);
GL.glVertex3d(1, 0, 0);
GL.glEnd();
System.out.println("swap");
vContext.swapBuffers();
}
vContext.dispose();
vShell.dispose();
vDisplay.dispose();
}
public static void main(String[] pArguments)
{
new SwtTest();
}
}
