什么是最好的OpenGL java绑定?

Nic*_*don 16 java opengl performance user-interface swt

我试图为我的Java SWT应用程序实现更好的性能,我发现可以在SWT中使用OpenGL.似乎OpenGL有多个Java绑定.你更倾向哪个?

请注意,我之前从未使用过OpenGL,并且该应用程序需要在Windows,Linux和Mac OS X上运行.

Rea*_*eal 10

我建议查看LWJGL,即LightWeight Java游戏库.它有OpenGL绑定,但它也有OpenAL绑定和一些很棒的教程,可以帮助您入门.

请记住,Swing/SWT和OpenGL通常用于完全不同的事情.您可能最终想要使用两者的组合.试试LWJGL,看看它与你正在做的事情有多好.


小智 9

JOGL

我的理由可以引用之前链接的网站:

JOGL提供对OpenGL 2.0规范中的API以及几乎所有供应商扩展的完全访问权限,并与AWT和Swing小部件集集成.

此外,如果你想学习和探索一些有趣的事情,Processing是一个很好的开始方式(Processing也使用JOGL btw ...)

  • JOGL提供对OpenGL 1.3 - 3.0,3.1 - 3.3,≥4.0,ES 1.x和ES 2.x规范以及几乎所有供应商扩展的API的完全访问权限.它与AWT和Swing小部件集以及使用NativeWindow API的自定义窗口工具包集成在一起.它是由Sun Microsystems的Game Technology Group发起的一套开源技术的一部分.http://jogamp.org/jogl/www/ (3认同)

sho*_*osh 6

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)