How to use OpenGL in JavaFX? - java

I want to write a very simple Java 3D editor(for experiment). I know the basic JavaFX usage, and I know enough OpenGL knowledge. But all my OpenGL experience is from working with C/C++.
Could I make a 'canvas' in JavaFx application and map OpenGL viewport on it?

Internally, JavaFX can use OpenGL as a rendering pipeline, so some care on integration between the two is required to avoid conflicts.
OpenGLNode in JavaFX
Richard Bair, JavaFX team lead posted on the openjfx development mailing list:
One thing I want to see done (for example) for the 8 update is to have an OpenGLNode or NativeSurfaceNode or something along those lines so that if you are doing your own D3D / OpenGL you can have a way to send those raw commands down to the graphics card but still have your node composited in the scene graph.
So a future JavaFX release update might include an OpenGLNode.
Such a feature would probably not see inclusion in a JavaFX general availability release until the next JavaFX feature release after the initial Java 8 release (my guess is that would put it at about September 2014).
3rd Party OpenGL/JavaFX integration
You don't need to wait so long to start integrating JavaFX and OpenGL. All of the required source code to start an implementation is open in the OpenJFX repository, so you could try building a custom integration of that code with a library such as lwjgl or jogl.
This answer will get dated as developers start performing integrations of JavaFX with existing Java wrappers for OpenGL apis. Some developers have started such work already - run a google search of lwjgl javafx or jogl javafx to find out about current integration projects and their status.
The simplest integration is probably to have a 3rd party library render to an off screen buffer then transfer the pixels from the buffer to a JavaFX WritableImage or Canvas as required to get the OpenGL rendered graphics composited into the JavaFX scene graph.
JavaFX 3D API Alternative
JavaFX has its own lightweight 3D api that provides the ability to composite phong shaded 3d models into the JavaFX scene graph. The JavaFX 3D api is not going to provide all the power of a full OpenGL api integration, however using the JavaFX 3D api is relatively simple. A description, with code examples of the 3D features in Java 8 is on the open-jfx wiki.
Interactive Mesh provides a free 3D model importer for JavaFX, that allows you to very simply bring complex shaded and textured 3D models into a JavaFX scene graph.
There is a 3D Viewer project in the openjfx repository that you could fork to create a basis for your proposed JavaFX based 3D editor.
The nashorn JavaScript engine has a switch that allows you to use JavaFX and its 3D features from JavaScript, so you can use alternative jvm languages to access JavaFX 3D features if you prefer.

Yes, by all means, you can use JOGL to achieve effectively everything you could in Java with OpenGL as you can in C/C++.

You can use the OpenGLFX library, which mixes the previously mentioned JOGL/LWJGL and JavaFX. The code has the best performance available without changing the source code of JavaFX itself.

Related

how to use ArcGis in javafx

i am using ArcGIS Library for a geospatial project. the sample codes available in their website was fully in java Swing. i need to do path animation in it using javaFX. is it possible.? if yes, can any one suggest me a sample code to create a map.?
Sample code for creating a map in Swing
I don't think you can pull this off using JavaFX, since JMap extends JComponent and is a class provided by the ArcGIS. Unless, they release a version which is supporting JavaFX, things are not very good.
The least you can do is to embed this JMap into a JavaFX application using SwingNode. An example on how to achieve this can be found here.
I am not sure what you want to achieve, when you say "path animation in it", but if it has something that can be achieved without using the internal components of JMap, you can do it !
JMap is a Swing component. JavaFX 1 was built on Swing and supported wrapping a Swing component. JavaFX 2 does not use Swing and does not support wrapping a Swing component. It is anticipated that the upcoming JavaFX 8 will support using Swing components in a JavaFX application.
UPDATE: ArcGIS Runtime is getting support for JavaFX! See http://blogs.esri.com/esri/arcgis/2014/09/17/arcgis-runtime-plays-at-10-2-4/ for details.
You have some options:
Go back to JavaFX 1 (not a good idea IMO)
Turn it around and use JavaFX components in a Swing application (see http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm)
Wait for Java 8, or go get the developer preview of Java 8.
Wait for ArcGIS Runtime 10.2.4 (to be released any day now), which will have beta support for JavaFX.
Sources:
How to wrap a swing component in a javaFX 2.0 application
Class SwingNode (JavaFX 8)
Maybe a bit late but... ArcGIS Runtime for Java's latest beta (Quartz) offers much more JavaFX support.
https://developers.arcgis.com/java/beta/guide/release-notes-java.htm

Does HTMLUnit include a functional [HTML5] canvas 2D implementation able to render image data back to Java Code?

Basically, I'd like to be able to retrieve the HTMl[5] canvas image data created from, normal, JavaScript-based in-browser scripting. I'd like to do this in the context of a screen-scraping-type environment, from within [pure] Java code. HTMLUnit appears to fit some of the requirements.
How would I go about retrieving the canvas-rendered image data, and how complete, or not, might HTMLUnit's canvas implementation currently be (version 2.13 at time of writing)?
Two (2) HTMlUnit classes of note, might be:
com.gargoylesoftware.htmlunit.html.HtmlCanvas
com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D
Well [answering my own question], as far as can see, no, there is not a functioning HTML Canvas implementation, as of HTMLUnit version 2.13 (November 2013).
Interestingly, it might be useful to integrate the following HTML Canvas (2D) open-source solution into HTMLUnit, in order to render canvas-based graphics:
https://github.com/w3canvas/javacanvas
It should also be possible to create a WebGL canvas context by appropriating the WebGL interface/class code from something like the gwtGL project, and implementing a 3D layer atop of an existing OpenGL 2.0 Java library.
Can I haz some points now?

Tkzinc like library in java

I need to develop some canvas window with graphical entities.
I want to know is there library similar to Tkzinc in java?
http://www.tkzinc.org/tkzinc/index.php
I've used Eclipse GEF before, but that is built on top of an SWT canvas, not Swing. I'm not sure if that's compatible with what you need.
It allows you to build an object-oriented graphical model which responds to events and can be moved around, etc.
The underlying drawing framework is Draw2D which might be useful on its own if you don't want a full MVC framework for editing a model.

JavaFX: Why are there two different styles?

I am learning JavaFX. I'm adding it to a Java Desktop App and I'm doing this using Netbeans 7. I've been searching the internet for JavaFX examples for whatever I want to do (embed in swing, set background, add gradient, incorporate animation...). I am finding two JavaFX styles.
1st Example: http://download.oracle.com/javafx/2.0/visual_effects/jfxpub-visual_effects.htm
2nd Example: http://javafx.com/samples/MediaBox/
I also found this http://netbeans.org/features/javafx/composer.html which says JavaFX support is currently not available in NetBeans IDE 7.0. And the screen shot is handling an FX Project which I don't have a choice to make in my Netbeans 7. I do have sample FX projects that I can make but these are really Java projects with FX in it (the 1st style of FX).
My guess is that JavaFX has been somewhat redesigned in the latest version, JavaFX 2. The 2nd example being the older style and the 1st being the newer. It seems to me that the 1st example is more like an addition to Java instead of a separate language.
Did I guess right? What's up with the two styles of FX?
The NetBeans JavaFX Composer is a tool that create CustomNodes with JavaFX components, but works with JavaFX 1.3.
NetBeans 7.0 has a JavaFX plug-in, but to version 2.0 (actually in beta).
JavaFX 1.3 is a DSL script language that runs over JVM and JavaFX 2.0 returns to be a Java API. They are totally differents, but conserving same Classes and ideas (CSS style, visual effects, etc).

How to do 3d in a Java applet?

I'd like to render a very simple 3D scene in a java applet. I could do all the math myself and render that to a bitmap, but as I'm sure I'm not the first person in history to have to draw a few cubes to the screen, I was wondering how this is usually done.
Every place I've read has said either Java3D or LWJGL, but as I understand it these rely on platform-dependent code and need to be installed separately from Java, making them both unsuitable for graphics.
So how is this usually done?
This old page lists the demos/apps/libraries of 3D Java applets with no hardware dependencies. Unfortunately very few are open-source, others are not even downloadable.
Personally I recommend you to experiment with Java 1.1 3D renderer by Ken Perlin, which has source code available and free to use for academic purposes.
EDIT: jGL is another Java 3D library with no hardware dependencies. It mimics OpenGL 1.* API. It is licensed under GNU Lesser General Public License (LGPL).
In a plug-in 2 JRE (1.6.0_10+), you can use JWS extensions for embedded applets. This is important because JWS makes it much easier to ensure the correct binaries are on the run-time class path. AFAIU JOGL and Java 3D both offer JWS extensions for their APIs.
Should you choose to go that way, please make the applet has the draggable parameter added, so the end user might choose if they want a (mostly useless) browser window wrapped around a 3D animation.
I ran into similar problems when I needed to do some 3d rendering in an applet. My solution was to simply implement from scratch a 3d rendering library in Java. The fear was that it would be a poor performer but on an I5 processor, this proved to not be the case. The added advantage is that I was able to write the library in the way I always wanted graphics to be done. The real advantage,, though, is that it will run regardless of any need to have some graphics library installed on the client and without regard to any graphics card dependencies.
I will gladly share a subset of this code to anyone who wants to look at it.
Could you use JOGL?
http://download.java.net/media/jogl/demos/www/applettest-jnlp.html
I'm not a Java guy, but 2/3 years ago when I was at univeristy I had the same problem :)
I've tried jogl... and for noob in Java like myself I found it too complicated to configure and write something using it.
I used Java3d and it worked like a charm, the only problem I had back then, was that Java3d did not worked with all graphic cards. But fortunatelly it worked with computers at my univeristy :)

Categories

Resources