如何在 Java 中使用 Opengl/DirectX

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23721322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:52:36  来源:igfitidea点击:

How to use Opengl/DirectX in Java

javaopengldirectx

提问by Stefnotch

My questions are:

我的问题是:

  • How to use Opengl or DirectX in Java.
  • Does DirectX have any major advantages over Opengl when using it in Java?
  • Is there a way to do so without using an API?
  • Should I use a API such as: JOGL LWJGL
  • Would Java FX be useful for making 3D things?
  • 如何在 Java 中使用 Opengl 或 DirectX。
  • 在 Java 中使用 DirectX 时,DirectX 与 Opengl 相比有什么主要优势吗?
  • 有没有办法在不使用 API 的情况下做到这一点?
  • 我应该使用 API,例如:JOGL LWJGL
  • Java FX 对制作 3D 东西有用吗?

Also, I am using Windows. Is there a different way to draw 3D objects??

另外,我正在使用Windows。有没有不同的方式来绘制 3D 对象?

采纳答案by Bartvbl

How to use Opengl or DirectX in Java.

如何在 Java 中使用 Opengl 或 DirectX。

There are a number of OpenGL bindings available for Java. Java does not seem to support DirectX by itself, and neither do there seem to be libraries available that provide bindings.

有许多可用于 Java 的 OpenGL 绑定。Java 本身似乎不支持 DirectX,似乎也没有提供绑定的库。

Does DirectX have any major advantages over Opengl when using it in Java?

在 Java 中使用 DirectX 时,DirectX 与 Opengl 相比有什么主要优势吗?

I'd say DirectX is at a disadvantage compared to OpenGL due to its lack of support on Linux or OSX. If you want to write cross-platform games using Java, I'd recommend taking a look at OpenGL.

我认为 DirectX 与 OpenGL 相比处于劣势,因为它缺乏对 Linux 或 OSX 的支持。如果您想使用 Java 编写跨平台游戏,我建议您查看 OpenGL。

Is there a way to do so without using an API?

有没有办法在不使用 API 的情况下做到这一点?

I assume you mean a library here. Java offers an API for drawing: Java2D. This might be a nice starting point if you want to write games and are starting out with computer graphics in general. Java does not provide bindings for either OpenGL or DirectX as part of the standard library.

我假设你的意思是这里的图书馆。Java 提供了一个用于绘图的 API:Java2D。如果您想编写游戏并且一般从计算机图形开始,这可能是一个不错的起点。Java 不为 OpenGL 或 DirectX 提供绑定作为标准库的一部分。

Should I use a API such as: JOGL LWJGL

我应该使用 API,例如:JOGL LWJGL

I have VERY good experiences with LWJGL. I can therefore recommend using their bindings if you want to try using OpenGL.

我在 LWJGL 方面有很好的经验。因此,如果您想尝试使用 OpenGL,我可以推荐使用它们的绑定。

Would Java FX be useful for making 3D things?

Java FX 对制作 3D 东西有用吗?

JavaFX is still somewhat buggy as far as my experience goes (came across several bugs when trying it). I don't know how well it works for doing 3D graphics.

就我的经验而言,JavaFX 仍然有些问题(尝试时遇到了几个错误)。我不知道它在制作 3D 图形时效果如何。

回答by gouessej

JOGL is a Java binding for the OpenGL and OpenGL ES API. I have used JOGL since 2006 and I'm very happy with it, it's very easy to install as you can see here. It works both in desktop and embedded environments, it supports Android too, it is used by almost all major middle and high level APIs including JogAmp's Ardor3D Continuation, JMonkeyEngine, Java3D, Xith3D, LibGDX, ... GLG2Dallows to benefit OpenGL when coding in plain Java2D without having to know OpenGL.

JOGL 是 OpenGL 和 OpenGL ES API 的 Java 绑定。我从 2006 年开始使用 JOGL,我对它非常满意,正如您在此处看到的,安装非常容易。它适用于桌面和嵌入式环境,也支持 Android,几乎所有主要的中高级 API 都使用它,包括JogAmp 的 Ardor3D ContinuationJMonkeyEngineJava3D、Xith3D、LibGDX...... GLG2D允许在编码时受益 OpenGL无需了解 OpenGL 即可使用纯 Java2D。

I agree with Bartvbl about JavaFX 3D API which is noticeably poorer than the APIs I quoted above.

我同意 Bartvbl 关于 JavaFX 3D API 的看法,它明显比我上面引用的 API 差。

JOGL is the only unified Java binding for the OpenGL and OpenGL ES API. It is suitable both for games and for other applications (CAD, ...) as it supports several displays, several screens, several monitors. You can use it with JInput if you want to support joysticks.

JOGL 是唯一统一的 OpenGL 和 OpenGL ES API 的 Java 绑定。它适用于游戏和其他应用程序(CAD,...),因为它支持多个显示器、多个屏幕、多个监视器。如果你想支持操纵杆,你可以将它与 JInput 一起使用。