Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
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  
  embedding javaFX inside opengl  (Read 12351 times)
0 Members and 1 Guest are viewing this topic.
Offline deepthought
« Posted 2015-06-30 15:40:02 »

this code allows you to use Javafx as your GUI in OpenGL. Includes an example using LWJGL3 and GLFW

http://pastebin.java-gaming.org/e0c5c939d2a19
http://pastebin.java-gaming.org/a067532503d19
http://pastebin.java-gaming.org/c5c3d1a093f15

Mad Scientist
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 123
Projects: 15


★★★★★


« Reply #1 - Posted 2015-07-01 09:24:05 »

This looks interesting, not very familiar with JavaFX yet but would you mind explaining briefly the technique you are using here to embed JavaFX inside OpenGL? are you simply rendering the javafx gui to a javafx image and then copying that over to an opengl texture? or some other method?
Offline deepthought
« Reply #2 - Posted 2015-07-01 19:59:44 »

JavaFX has components for embedding itself into Swing and SWT. What i'm doing is loading the image into a ByteBuffer and then using that to update a texture (you could subclass texupdater and use a PBO with a mapped bytebuffer too). then in my demo, I'm using GLFW to get input from the mouse and keyboard to feed to Javafx.

Mad Scientist
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spasi
« Reply #3 - Posted 2015-07-01 20:17:49 »

(you could subclass texupdater and use a PBO with a mapped bytebuffer too)

The org.lwjgl.util.stream package in LWJGL-FX contains a few implementations and supports buffering.
Offline deepthought
« Reply #4 - Posted 2015-07-01 20:26:54 »

How are you getting mouse and keyboard events into javafx?

Mad Scientist
Offline Spasi
« Reply #5 - Posted 2015-07-01 20:31:32 »

I'm not. It is a proof of concept demo, from 3 years ago using LWJGL 2. It features both rendering JavaFX content in an OpenGL scene and rendering the OpenGL scene as a JavaFX node. It isn't something I'd use in a real application, so never bothered with event translation.
Offline deepthought
« Reply #6 - Posted 2015-07-22 19:02:12 »

any ideas how i could draw a cursor in the texture for if the window hides the system cursor or if i'm doing an in-game screen like in doom3?

Mad Scientist
Offline Spasi
« Reply #7 - Posted 2015-07-22 19:20:59 »

Have you tried GLFW cursor functions? I don't see why you would need to draw it in the texture.
Offline deepthought
« Reply #8 - Posted 2015-07-22 19:31:35 »

that works for GLFW, but i want the capability so i can do those in-game terminals like in doom3.

Mad Scientist
Offline Spasi
« Reply #9 - Posted 2015-07-22 19:53:49 »

I'm assuming you're projecting the JavaFX texture on a 3D surface then. In the same way, you could project a custom cursor texture, after rendering the JavaFX texture.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deepthought
« Reply #10 - Posted 2015-07-22 20:02:10 »

texture's going to be UV mapped. I could just use java to composite the cursor on top before i update the texture. Or maybe do it inside my shader.

Mad Scientist
Offline deepthought
« Reply #11 - Posted 2015-09-06 23:38:55 »

i need a bit of help with the compositing.
This is what I'm using now.

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  
public boolean getPixels(IntBuffer dest, int width, int height)
    {
       if(scenePeer!=null)
       {
        boolean success=scenePeer.getPixels(dest, width, height);
       
       
       
       if(success)
       {
         
       
          if(drawcursor&&currentframe!=null)
          {
         
             cursorlock.lock();
             System.out.println("draw cursor");
             //NOTE composite the cursor
             
          com.sun.prism.Image img =(com.sun.prism.Image) currentframe.getPlatformImage();
       
             
             
             for(int x=0;x<currentframe.getWidth();x++)
             {
                for(int y=0;y<currentframe.getHeight();y++)
                {
                   
                   int framex=(int) (mousex-currentframe.getHotspotX()+x);
                   int framey=(int) (mousey-currentframe.getHotspotY()+y);
                   
                   
                   if(framex>=0&&framex<=width&&framey>=0&&framey<=height)
                   {
                     
                      int index=framex+(framey*width);
                     
                      int destcolor=dest.get(index);
                     
                      int destb=destcolor&0xff;
                      int destg=(destcolor>>8)&0xff;
                      int destr= (destcolor>>16)&0xff;
                      int desta=(destcolor>>24)&0xff;
                     
                     
                      int srccolor=img.getArgb(x, y);
                     
                      int srcb=srccolor&0xff;
                      int srcg=(srccolor>>8)&0xff;
                      int srcr= (srccolor>>16)&0xff;
                      int srca=(srccolor>>24)&0xff;
                     
                     
                     
                      int enda=srca+desta*(1-srca);
                     
                      int endr=0,endb=0,endg=0;
                     
                     
                      System.out.println(enda);
                      if(enda!=0)
                      {
                       endb=(srcb*srca+destb*desta*(1-srca))/enda;
                       endg=(srcg*srca+destg*desta*(1-srca))/enda;
                       endr=(srcr*srca+destr*desta*(1-srca))/enda;
                      }
                     
                      int endcolor=0;
                      endcolor|= endb;
                      endcolor|= endg<<8;
                      endcolor|=endr<<16;
                      endcolor|=enda<<24;
                      dest.put(index, endcolor);
                     
                     
                   }
                   
                   
                }

             }
             cursorlock.unlock();
             
             
         
          }
         
          return true;
       }

       }
       return false;
    }


It's getting some strange results. for some odd reason it puts the cursor over the text field but under the button. if i switch the source and destination, it renders under the text field but over the button. why?



Mad Scientist
Offline deepthought
« Reply #12 - Posted 2015-09-07 02:59:01 »

never mind. got it working

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
  int AlphaBlend( int bg,  int src)
   {
       
       int bA=src&0xff;
       int gA=(src>>8)&0xff;
       int rA=(src>>16)&0xff;
       int aA=(src>>24)&0xff;
       
       int bB=bg&0xff;
       int gB=(bg>>8)&0xff;
       int rB=(bg>>16)&0xff;
       int aB=(bg>>24)&0xff;
       
       
       int rOut = (rA * aA / 255) + (rB * aB * (255 - aA) / (255*255));
             int gOut = (gA * aA / 255) + (gB * aB * (255 - aA) / (255*255));
             int bOut = (bA * aA / 255) + (bB * aB * (255 - aA) / (255*255));
             int aOut = aA + (aB * (255 - aA) / 255);
             
             
             return (aOut<<24)|(rOut<<16)|(gOut<<8)|(bOut);
   }


I've updated the pastebin code for cursor support.

Mad Scientist
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (187 views)
2019-09-04 15:33:17

hadezbladez (4874 views)
2018-11-16 13:46:03

hadezbladez (1785 views)
2018-11-16 13:41:33

hadezbladez (5147 views)
2018-11-16 13:35:35

hadezbladez (1016 views)
2018-11-16 13:32:03

EgonOlsen (4367 views)
2018-06-10 19:43:48

EgonOlsen (5216 views)
2018-06-10 19:43:44

EgonOlsen (2946 views)
2018-06-10 19:43:20

DesertCoockie (3867 views)
2018-05-13 18:23:11

nelsongames (4293 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!