Author Topic: How to blit components in 3D app based on jPCT  (Read 6276 times)

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
How to blit components in 3D app based on jPCT
« on: April 05, 2010, 12:49:24 pm »
HI ,I am back...

First I've to say thanks for this great 3D engine.

but after some tests i got a problem in jPCT Car demo

I want to know how could i add a JTextField or JTextArea in scene of Car demo to accept user's input?

e.g.
there have two textfield "input" and "show"
I input some text in "input" textfield,and when press "send" button,the message was display on "show" textfield

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to blit components in 3D app based on jPCT
« Reply #1 on: April 05, 2010, 09:09:59 pm »
Are you using the software or the hardware renderer?

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #2 on: April 06, 2010, 05:34:01 am »
use hardware accelerated rendering using OpenGL,maybe i need to use software?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to blit components in 3D app based on jPCT
« Reply #3 on: April 06, 2010, 07:07:28 am »
Well, you can't render Swing or AWT components on top of a native OpenGL output. You can try to use FrameBuffer.enableGLCanvasRenderer() (don't forget to disable the software renderer in addition), which will return a Canvas. This (heavyweight) Canvas can be combined with Swing/AWT components to a degree. You should find some information about this when searching the forums.

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #4 on: April 06, 2010, 11:29:52 am »
OK ,thanks

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #5 on: April 07, 2010, 11:23:06 am »
Well, you can't render Swing or AWT components on top of a native OpenGL output. You can try to use FrameBuffer.enableGLCanvasRenderer() (don't forget to disable the software renderer in addition), which will return a Canvas. This (heavyweight) Canvas can be combined with Swing/AWT components to a degree. You should find some information about this when searching the forums.

well,as you say ,I get a AWTGLCanvas which i can put this canvas into a JFrame,but the KeyMapper is wrong, i implements a KeyListener(java.awt.event.KeyListener;),but it seemes not work

my code such as
public class Test implements KeyListener {
        frame = new JFrame("test");
        panel = new JPanel();
        frame.setLayout(new GridLayout(1,1));
   frame.setSize(width, height);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.add(panel);
        frame.setVisible(true);
   buffer = new FrameBuffer(panel.getWidth(),panel.getHeight(),FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
   buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   //buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
   canvas = buffer.enableGLCanvasRenderer();
   panel.add(canvas,new GridLayout(1,1));
   canvas.addKeyListener(this);
   frame.addKeyListener(this);
}

public void keyTyped(KeyEvent e){
   System.out.println("ley d");
}
public void keyPressed(KeyEvent e){
   System.out.println("ley d");
}
public void keyReleased(KeyEvent e){
   System.out.println("ley d");
}

the game loop is
buffer.clear();
theWorld.renderScene(buffer);
theWorld.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();

Is there something I can change to allow the mapper to be correctly ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to blit components in 3D app based on jPCT
« Reply #6 on: April 08, 2010, 01:06:35 pm »
Looks fine to me at first glance. I can't remember exactly if it has to be added to the frame or the canvas...you are doing both. Maybe doing just one of them will make it work?

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #7 on: April 13, 2010, 06:44:26 am »
Looks fine to me at first glance. I can't remember exactly if it has to be added to the frame or the canvas...you are doing both. Maybe doing just one of them will make it work?

hi,
i did as you said,but keylisten still not work... :'(

now i am seeking other way...

i used the project powered by raft http://www.jpct.net/forum2/index.php/topic,1338.0.html,everything is run well,but JScrollPanel and JTextArea can't work
i don't konw what's wrong,so give it up

now,i find a GUI API (FengGUI),i will do some test with it later,could you give me more info about it,or other gui project like FengGui :P

this thread will update,if something run, i will let you know first ;D

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to blit components in 3D app based on jPCT
« Reply #8 on: April 13, 2010, 03:53:25 pm »
Quote from: me520
i used the project powered by raft http://www.jpct.net/forum2/index.php/topic,1338.0.html,everything is run well,but JScrollPanel and JTextArea can't work
swing-gl is not a completed project. for example keyboard events are not dispatched so it's normal that JTextArea doesn't work.

you may want to have a look at PureSwing. it's a mature project but a bit big in size and requires a fairly decent video card

Offline Achim

  • byte
  • *
  • Posts: 26
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #9 on: April 13, 2010, 10:51:37 pm »
is there a ready made code snippet and associated texture with numbers and letters which I could use to display simple strings when using the HW renderer?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to blit components in 3D app based on jPCT
« Reply #10 on: April 13, 2010, 11:28:25 pm »
You can use raft's GLFont for this: http://www.jpct.net/forum2/index.php/topic,1074.0.html

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #11 on: April 14, 2010, 08:41:34 am »
thanks

give me some time  ;D

Offline me520

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to blit components in 3D app based on jPCT
« Reply #12 on: April 14, 2010, 09:03:13 am »
swing-gl is not a completed project. for example keyboard events are not dispatched so it's normal that JTextArea doesn't work.

you may want to have a look at PureSwing. it's a mature project but a bit big in size and requires a fairly decent video card

Hi,raft,

I have in trouble and need your help

If i write my keyboard events,how could I do ,give tips please

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: How to blit components in 3D app based on jPCT
« Reply #13 on: April 14, 2010, 12:54:00 pm »
if you ask for swing-gl, i dont know :-\ my swing knowledge is not that good. that's why i shared the project and asked for help..