Nic*_*don 16 java opengl performance user-interface swt
我试图为我的Java SWT应用程序实现更好的性能,我发现可以在SWT中使用OpenGL.似乎OpenGL有多个Java绑定.你更倾向哪个?
请注意,我之前从未使用过OpenGL,并且该应用程序需要在Windows,Linux和Mac OS X上运行.
小智 9
我的理由可以引用之前链接的网站:
JOGL提供对OpenGL 2.0规范中的API以及几乎所有供应商扩展的完全访问权限,并与AWT和Swing小部件集集成.
此外,如果你想学习和探索一些有趣的事情,Processing是一个很好的开始方式(Processing也使用JOGL btw ...)
JOGL可能是值得考虑的唯一选择.请注意,至少有两个选项可将其集成到SWT应用程序中.有一个属于SWT的GLCanvas和一个属于AWT的GLCanvas.SWT中的那个功能不完整,并没有真正维护.在SWT_AWT容器中使用AWT GLCanvas要好得多.最近一个项目的一些代码:
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.events.*;
public class Main implements GLEventListener
{
public static void main(String[] args)
{
Display display = new Display();
Main main = new Main();
main.runMain(display);
display.dispose();
}
void runMain(Display display)
{
final Shell shell = new Shell(display);
shell.setText("Q*bert 3D - OpenGL Exercise");
GridLayout gridLayout = new GridLayout();
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
shell.setLayout(gridLayout);
// this allows us to set particular properties for the GLCanvas
GLCapabilities glCapabilities = new GLCapabilities();
glCapabilities.setDoubleBuffered(true);
glCapabilities.setHardwareAccelerated(true);
// instantiate the canvas
final GLCanvas canvas = new GLCanvas(glCapabilities);
// we can't use the default Composite because using the AWT bridge
// requires that it have the property of SWT.EMBEDDED
Composite composite = new Composite(shell, SWT.EMBEDDED);
GridData ld = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(ld);
// set the internal layout so our canvas fills the whole control
FillLayout clayout = new FillLayout();
composite.setLayout(clayout);
// create the special frame bridge to AWT
java.awt.Frame glFrame = SWT_AWT.new_Frame(composite);
// we need the listener so we get the GL events
canvas.addGLEventListener(this);
// finally, add our canvas as a child of the frame
glFrame.add(canvas);
// show it all
shell.open();
// the event loop.
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
}
Run Code Online (Sandbox Code Playgroud)