Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JavaFX 3d API and OpenGL  (Read 6731 times)
0 Members and 1 Guest are viewing this topic.
Offline arnaud_couturier
« Posted 2013-02-20 21:42:48 »

Official news from Oracle: JavaFX 3D early access !!!
http://fxexperience.com/2013/02/javafx-3d-early-access-available/comment-page-1/#comment-155899
https://wikis.oracle.com/display/OpenJDK/3D+Features

No sign of OpenGL though, they decided to wrap it (and DirectX), which is the wrong path IMO.
No please, I don't want to learn another 3D API, there are just too many of them. It's OpenGL or nothing for me.

Yet, this could open backdoors for the JOGL team, especially if all of this goes open source.

Julien, any feedback on this news Huh?
Offline ReBirth
« Reply #1 - Posted 2013-02-21 02:19:36 »

Well, it depends on how well they wrap it Wink

Offline arnaud_couturier
« Reply #2 - Posted 2013-02-21 05:51:42 »

It seems they're wrapping it with high level concepts, basically they're making a scenegraph.
Porting "low level" JOGL/LWJGL code to it will be more difficult, and we're losing a lot of control.
And what if we don't need a scenegraph at all, or using our own already...

<rant>
Is it me, or people at Sun/Oracle are so obsessed with object-ville they can't stop wrapping things into objects ?
That's something I hate in the java ecosystem: this tendency to over wrap things into other things until we can't see the whole picture anymore.
</rant>
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #3 - Posted 2013-02-21 06:48:50 »

Looks interesting. Does it have lighting? What's the performance like? Does it work in an applet? Wish I had more time.

Time flies like a bird. Fruit flies like a banana.
Offline arnaud_couturier
« Reply #4 - Posted 2013-02-21 08:25:04 »

It does support lighting. I didn't test it, so I can't speak about performances. If it works in JavaFX, the 3D feature will also work everywhere you can deploy JavaFX, including applets, I guess.
Offline princec

« JGO Spiffy Duke »


Medals: 439
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2013-02-21 09:53:55 »

Looks like Java3D all over again.

Cas Smiley

Offline Roquen
« Reply #6 - Posted 2013-02-21 10:31:42 »

Scenegraphs are great for simple tools & basic 3D and sucks for everything else.  So it depends on the target audience.  But OMG, Phong...are you kidding me? Cookie cutter materials?  So 80s/90s.  Get with the shader program (yuck, yuck) baby.  I'm too lazy to try to dig-up and look at the source to see if there's a sane low level exposed...if not it's pretty worthless.
Offline arnaud_couturier
« Reply #7 - Posted 2013-02-21 12:15:00 »

Looks like Java3D all over again.
Yep.
Can't people learn from History ? Not always it seems...

Scenegraphs are great for simple tools & basic 3D and sucks for everything else.  So it depends on the target audience.  But OMG, Phong...are you kidding me? Cookie cutter materials?  So 80s/90s.  Get with the shader program (yuck, yuck) baby.  I'm too lazy to try to dig-up and look at the source to see if there's a sane low level exposed...if not it's pretty worthless.
I hope LWJGL/JOGL can benefit somehow.
spasi ? Julien ? Save us with a good news please  Grin
Online Spasi
« Reply #8 - Posted 2013-02-21 15:00:26 »

JavaFX exposing a 3D API doesn't change anything for integration purposes, since it's at a level higher than the interesting stuff.

Speaking for LWJGL, we're exploring different options and we won't commit to anything until we try to integrate with JavaFX properly. We're currently waiting for Prism and Glass to be fully open sourced, then we'll see what's possible. There's been a lot of progress with the open sourcing of JavaFX (details here), but we'll have to a wait a few more weeks for Prism.
Offline gouessej
« Reply #9 - Posted 2013-02-21 20:39:26 »

spasi ? Julien ? Save us with a good news please  Grin
Spasi can confirm that it is already possible to use LWJGL to render some JavaFX thingy in a FBO, this code should not be difficult to port to JOGL 2.0 and it would benefit of some helpers allowing to have some fallbacks where FBOs are not available or too slow.

There is already a JOGL backend for JavaFX, it was working with a very old version (prior to JavaFX 2). I already talked to you about that in your bug report, I tried to be extremely accurate.

I don't want to be harsh but there are plenty of things to do with existing APIs. I won't port another temporarily trendy thing, especially if it is only used by a very few people. JavaFX has some interesting features but some of them are already present in JogAmp or we already plan to provide alternatives.

I need the whole source code of Quantum, Prism and Glass. I have to admit that I have other priorities for the next siggraph, your help would be welcome.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline arnaud_couturier
« Reply #10 - Posted 2013-02-21 21:59:52 »

Yep I saw spasi's technique. I succeeded with glReadPixels and WritableImage. It's slow, but fixed pipeline must work in my case. Didn't try with FBOs.

I can't be of much help, I have zero knowledge of JOGL/LWJGL's inner working, and have my hands already more than dirty with a project using JOGL.
I'll wait for what could be done when Quantum, Prism and Glass go open source, if they ever do...

In the meantime as you said there are workarounds: for me the easiest will be to mix JavaFX with Swing+JOGL.
Offline gouessej
« Reply #11 - Posted 2013-02-22 12:11:04 »

Yep I saw spasi's technique. I succeeded with glReadPixels and WritableImage. It's slow, but fixed pipeline must work in my case. Didn't try with FBOs.
Please can you share your source code? I need something working with the fixed pipeline too. Maybe I could help you a little bit but I will start using JavaFX only when it works with OpenJDK.

I can't be of much help, I have zero knowledge of JOGL/LWJGL's inner working, and have my hands already more than dirty with a project using JOGL.
I'll wait for what could be done when Quantum, Prism and Glass go open source, if they ever do...
I have spent a lot of time in improving the environment (the APIs) required for my own project using JOGL during 6 years. Why not sharing your findings? It would be better than nothing.

In the meantime as you said there are workarounds: for me the easiest will be to mix JavaFX with Swing+JOGL.
You're right but what do you mainly use in JavaFX? Personally, I'm interested in the charting API and a bit in CSS.

Edit.: I have to be more precise.

XML dialect of UIWe can use XMLEncoder and XMLDecoder with Java beans to achieve something similar
Scripting languagesNothing prevents a developer from using a scripting engine with JogAmp
Web rendering engine persecutioncomplex -
Swing interoperabilityIt has been working for years and it is possible to render Swing components without AWT thanks to GLG2D
High-performance hardware accelerated graphics pipelineThere are already several efficient scenegraphs supporting JOGL 2.0, including Ardor3D (>= 0.9), JMonkeyEngine (>= 3.0), ...
High-performance media engineThere is already some video and audio playback in JogAmp but there is a lack of backends for some operating systems
Charting & CSSA NEWT backend based on GLG2D for JFreeChart or a port of this charting API is doable if and only if it is well decoupled from the rest.
Ubiquitous deploymentWe are still talking about providing full builds of OpenJDK or of our own JRE

Offline arnaud_couturier
« Reply #12 - Posted 2013-02-23 08:47:18 »

Please can you share your source code? I need something working with the fixed pipeline too. Maybe I could help you a little bit but I will start using JavaFX only when it works with OpenJDK.
Here it is.

It's a JavaFX app, that displays a red triangle on a black background using JOGL 2 rc11 (the only needed lib). The drawing is done in a hidden GLCanvas, then using glReadPixels copied into a WritableImage. You may have to click the "redraw" button to see the result at the beginning.

2 downsides:
- The GLCanvas is inside a JFrame, which must be shown then hidden, otherwise all OpenGL calls will be ignored. So you can see the JFrame flashing when the app starts, which is a bit annoying.
- it's very slow, it takes on average 11ms on my fairly good laptop (i7, gtx660m) mostly the call to glReadPixels I suppose

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
package todel;

import com.jogamp.common.nio.Buffers;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;

public class Todel extends Application {

    static int width = 512;
    static int height = 480;
    static ByteBuffer byteBuffer;

    @Override
    public void start(Stage primaryStage) {
        final WritableImage writableImage = new WritableImage(640, 480);
//        final PixelFormat<ByteBuffer> pf = PixelFormat.getByteBgraPreInstance();
        final PixelFormat<ByteBuffer> pf = PixelFormat.getByteRgbInstance();


        //        SwingUtilities.invokeLater(new Runnable() {
//            @Override
//            public void run() {
        final JFrame win = new JFrame("Swing");
        win.setSize(width, height);
        win.setLocationRelativeTo(null);

        GLProfile glProfile = GLProfile.getDefault();
        GLCapabilities glCapabilities = new GLCapabilities(glProfile);
        final GLCanvas glcanvas = new GLCanvas(glCapabilities);
//        final GLWindow newtWindow = new  GLWindow(glCapabilities);
        glcanvas.addGLEventListener(new GLEventListener() {
//        newtWindow.addGLEventListener(new GLEventListener() {
            @Override
            public void init(GLAutoDrawable glad) {
                GL2 gl = (GL2) glad.getContext().getGL();
                gl.glClearColor(.1f, .1f, .1f, .1f);
            }

            @Override
            public void dispose(GLAutoDrawable glad) {
            }

            @Override
            public void display(GLAutoDrawable glad) {
                long startTime = System.currentTimeMillis();
                GL2 gl = (GL2) glad.getContext().getGL();
                gl.glColor4f(1, 0, 0, 1);
                gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
                gl.glBegin(GL2.GL_TRIANGLES);
                gl.glVertex2f(0, 0);
                gl.glVertex2f(1, 0);
                gl.glVertex2f(0, 1);
                gl.glEnd();

                gl.glReadBuffer(GL2.GL_FRONT);
                width = glcanvas.getWidth();
                height = glcanvas.getHeight();
                if (byteBuffer == null) {
                    byteBuffer = Buffers.newDirectByteBuffer(width * height * 3);
                }


                gl.glReadPixels(0, 0, width, height, GL2.GL_RGB, GL2.GL_UNSIGNED_BYTE, byteBuffer);
//                Thread
//                
//                BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
//                int[] imageData = ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData();
//                for (int y = 0; y < height; y++) {
//                    for (int x = 0; x < width; x++) {
//                        int b = 2 * byteBuffer.get();
//                        int g = 2 * byteBuffer.get();
//                        int r = 2 * byteBuffer.get();
//
//                        imageData[(height - y - 1) * width + x] = (r << 16) | (g << 8) | b | 0xFF000000;
//                    }
//                }
//                System.out.println("copied color buffer");
//                try {
//                    ImageIO.write(bufferedImage, "png", new File("C:\\Users\\arnaud\\Desktop\\todel.png"));
//                } catch (IOException ex) {
//                    System.out.println("Could not save image because " + ex);
//                }
//                byte[] bytes = new byte[width * height * 3];
//                PixelWriter pix = new PixelWriter() {}
//                byteBuffer.get(bytes);
//                bytes[0] = (byte)255;

                Thread t = new Thread(new Runnable() {
                    @Override
                    public void run() {
//                        try {
//                            Thread.sleep(1000);
//                        } catch (InterruptedException ex) {
//                            Logger.getLogger(Todel.class.getName()).log(Level.SEVERE, null, ex);
//                        }
                        writableImage.getPixelWriter().setPixels(0, 0, width, height, pf, byteBuffer, width * 3);
                    }
                });
                t.start();
//                writableImage.getPixelWriter().setPixels(0, 0, width, height, pf, byteBuffer, width * 3);
                //                for (int y = 0; y < height; y++) {
                //                    for (int x = 0; x < width; x++) {
                //                        int b = 2 * byteBuffer.get();
                //                        int g = 2 * byteBuffer.get();
                //                        int r = 2 * byteBuffer.get();
                //                        writableImage.getPixelWriter().setColor(x, y, new Color(r/255f, g/255f, b/255f, 1));
                //                    }
                //                }
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException ex) {
//                    Logger.getLogger(Todel.class.getName()).log(Level.SEVERE, null, ex);
//                }
                System.out.println("Displayed in " + (System.currentTimeMillis() - startTime) + " ms");
            }

            @Override
            public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
            }
        });
        win.getContentPane().add(glcanvas);
        win.setVisible(true);
        win.setVisible(false);
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//            }
//        });

        Button btn = new Button();
        btn.setText("Reraw");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                glcanvas.display();
            }
        });



        ImageView imgView = new ImageView(writableImage);

        Pane root = new FlowPane();
        root.getChildren().add(btn);
//        root.getChildren().add(new Button("gg"));
        root.getChildren().add(imgView);

        Scene scene = new Scene(root, 800, 600);

        primaryStage.setTitle("JavaFX");
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.toFront();
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent t) {
                win.dispose();
            }
        });

    }

    public static void main(String[] args) {
        launch(args);
    }
}



I have spent a lot of time in improving the environment (the APIs) required for my own project using JOGL during 6 years. Why not sharing your findings? It would be better than nothing.
There may be a misunderstanding here. I have no finding to share, I'm enjoying JOGL so far. What I meant is: all my time must be devoted to wrapping my project, which is very late already


You're right but what do you mainly use in JavaFX? Personally, I'm interested in the charting API and a bit in CSS.
I need JavaFX
1) to do almost exactly what spasi did in his "Dope" project here http://www.java-gaming.org/topics/tool-dope/27389/view.html. A node-based interface. In the meantime I'm using the Netbeans Visual library, but I find it clunky. I'll definitely have to dump it at some point
2) CSS GUI skinning. Swing + Nimbus is ok, but I'd prefer something more expressive.
3) potentially the animation framework, and integrated browser, but later
The neat thing with JavaFX is that it's part of Java, so (hopefully) very well supported. I try to use as few libs as possible.




Why would you provide your own JRE ?
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #13 - Posted 2013-02-23 11:10:54 »

Downloaded the API.  Not familiar with JavaFx, but can't see how to do fog or fade to grey with distance.

However a quick googling suggests that there is a Shader language compiler for JavaFx, although I can't find anything more.
http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-November/004292.html
Anyone know anything about that?

Edit: After reading more carefully, I think Decora isn't a end-user tool and only is of use to Oracle.  Unless anyone can find a way of bolting stuff on via any unsupported APIs.
Edit2: I found this: http://mail.openjdk.java.net/pipermail/openjfx-dev/2013-February/006136.html

Edit 3: <quote>Our current 3D implementation makes no use of the decora-compiler translator, which means that the 3d shaders are hand written which means they are different, and theoretically could introduce a bit of shader code that isn't as well tested (In practice it isn't that big of a deal). Prism's use of JSL itself is also in need of work since writing a shader is only half the battle. We need to be able to provide flexible vertex data objects/interfaces and manage these in a way that is simple and flexible if we are to provide shaders to developers.</quote>

Oh well, never mind.

Time flies like a bird. Fruit flies like a banana.
Offline arnaud_couturier
« Reply #14 - Posted 2013-02-23 12:54:49 »

I'm not sure I can follow what these guys are talking about, but it seems we're going to have to write OSL/Decora/Pixel Bender code, then it'll be automagically translated into GLSL / HLSL ? Well, why not...  but although it'd make it easier (higher level) we could potentially be losing a lot of control if we need precise results, since we'd be relying on the underlying OSL/Decora/Pixel Bender-compatible renderer.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (13 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (85 views)
2014-12-05 12:39:02

SHC (95 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!