launching problem

Started by manumoi, July 20, 2005, 10:56:14 PM

Previous topic - Next topic

manumoi

Hello folks,

I have a problem that i can t fix....

My app run correctly when i launch it with all necessary arguments (i.e. name, name of the server, port of the server, position at the beginning)  in the command line.
Here are some screenshots

What appears just after launching the app


a upper view of the same map

The code of my main function in my Test class is the following:

 public static void main(String [] args){
   Test t =new Test(args);   
         t.panel3D.start();
   }
 
and an example of command line would be

java  -Xmx128m multi.world.Test Bob pamela 9000 520 520


I decided to add a form in a graphic menu (inside a JFrame) to make it easier for a client to enter new values... When I click on a button, the Test class will be launched.


The code is very basic

   public void actionPerformed(ActionEvent e){
          String [] args = new String [5];
          args[0] = loginText.getText(); // JTextField containing the login
          args[1] = serverIDText.getText(); // JTextField containing the server name
          args[2] = serverPortText.getText(); // // JTextField containing the lserver port
          args[3] = ""+520;
          args[4] = ""+520;
          myMocas.closeMocas(); // i tried to close my frame either with calling dispose() or with using setVisible(false)
          Test t = new Test(args);
          t.panel3D.start();
      }

When I launch my app using this JFrame, there are many problems.  Only the panel containing the JPCT view is started (the black one on the left and the white one on the down aren't... The keymapper seems not to be loaded so i have no control on my avatar... And my system is slow down drastically.
I put some "System.out..." in my code to see where the application had problems... But the code seems to be read correctly... the client is correctly connected to the server and my game loop is running.
I checked if the args value that were passed to the Test class were corrects... and they are...

I tried with software or hardware rendering. Here are some config information for the buffer of my jpct Panel

//   buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
//buffer.enableGLCanvasRenderer(IRenderer.RENDERER_OPENGL);
buffer.enableGLCanvasRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.setBoundingBoxMode(FrameBuffer.BOUNDINGBOX_NOT_USED);
buffer.optimizeBufferAccess();


I tried 2 different configs by inverting red and green lines. blue lines remained in both configs. I don t know if it can be related to that but in fact, there was no runtime difference.

So I m lost. Is there a problem launching a JPCT app from another JFrame? If so, is there a way to bypass it?

Thanks you,

Manu

EgonOlsen

Seems like you are lauching your app from inside the AWT event dispatch thread...not a good idea, because that will block this thread forever, i.e. you'll get no more key events or repaints of other components. Try something like


new Thread() {
  public void run() {
       Test t = new Test(args);
       t.panel3D.start();
  }
}.start();


in the actionPerformed(...) method instead and see if it helps.

Edit: And by the way: buffer.enableGLCanvasRenderer(IRenderer.RENDERER_SOFTWARE);
is not correct. You are supposed to give a mode there, not a renderer. I.e. IRenderer.MODE_OPENGL or (possible, but not advised...don't do it) IRenderer.MODE_LEGACY. But that's not the reason for your problem, as the values of both constants are the same anyway... :wink:

manumoi

I m back.
As you can see on my previous screenshots, my app is composed of 3 panels.  Except the problem I described in my previous post, my app works fine. But i just remarked that when I had a swing JButton to one of my two others panels (the white or the black).... the button appears but the KeyMapper is no more functional. I used
new KeyMapper(myFrame);
to init it (here myFrame refers to the JFrame of my application... I don t know why but it has never worked when i tried with the JPanel of my JPCT view)

I suspect both my problems are linked... :cry:

EgonOlsen

Quote from: "manumoi"
new KeyMapper(myFrame);
Try to init it with jPCT's canvas instead of the frame or panel.

manumoi

Damn Egon, you are good.... and fast   :P

So the first problem is no more

Concerning the KeyMapper,
What do you mean by "JPCT's canvas" and how can I access to it?

A really big thanks for all...

Manu

EgonOlsen

Are you actually using the Canvas that enableGLCanvasRenderer(<int>) returns you? Maybe you are just using the legacy software renderer for output. A small introduction to the different renderers:

When creating a new FrameBuffer, it is in legacy software mode. Legacy mode stinks. Don't use it. To switch to another one, you can do:

buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);

This will give you a software renderer in OpenGL lighting mode. This is what you want, if you have no hardware support for OpenGL.
To see the results, you usually paint the rendered image into a component using buffer.display(<Graphics>).

To get OpenGL support via hardware, you first have to disable software rendering (or it will continue to be used together with hardware...possible but senseless in almost every case):

buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

You'll get a native LWJGL window (if sizes and color depth are fine). Considering your app, this is most likely not what you want.

And then there is the AWTGLCanvas support. To use it, do:

buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
Canvas c=buffer.enableGLCanvasRenderer(IRenderer.MODE_OPENGL);
<Component>.add(c);
// your gameloop:
//...do your rendering here...
buffer.display(null);
c.repaint();

Edit: If you want to use the AWTGLCanvas, download the latest jar as it fixes some bugs in it: http://www.jpct.net/download/jpct107a2.jar

manumoi

I understand. I was doing it in the wrong way...
I must not be so far now from the solution but currently, my canvas shows a dark square...

here is my code :


// constructor of my JPanel

 public WorldInterface(String [] args, JFrame theFrame){
   this.playerName = args[0];
   connectToServer(args[1], Integer.parseInt(args[2]));
   //   receiveUpdatesFromServer();
   this.setSize(width, height);
   World.setDefaultThread(Thread.currentThread());   
[\color]          buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
   buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
   myCanvas=buffer.enableGLCanvasRenderer(IRenderer.MODE_OPENGL);
   this.add(myCanvas);
[\color]   Config.maxPolysVisible = 10000;
   processArguments(args);
[\color]
   keyMapper = new KeyMapper(myCanvas);
[\color]
   theWorld = new World();
   texMan = TextureManager.getInstance();
   setupLighting();
   setupFog();
   loadingTextures();
   loadingTerrain();
   mainPlayer = this.initPlayer(this,"alita", "alita2.jpg", this.playerName, Float.parseFloat(args[3]),-13f, Float.parseFloat(args[4]));
   mainPlayer.setMainPlayer(true);
   playersMap.put(playerName, mainPlayer);
   setupCamera();
   // optimization stuff
   Config.tuneForOutdoor();
   this.addMouseListener(new WorldInterfaceMouseListener(this));
   }   [\color]


// and here is my game loop

private void startWorldLoop(){      
   while (!exit){
       if(!isIdle){   [\color]
      buffer.clear();[\color]
      receiveUpdatesFromServer();
      Set playersList = playersMap.keySet();
      Iterator it = playersList.iterator();
      while (it.hasNext()){      
          ((Player)playersMap.get(it.next())).updateModel();
      }
      setupCamera();[\color]
      theWorld.renderScene(buffer);
      theWorld.draw(buffer);
      buffer.update();
      buffer.display(null);
      myCanvas.repaint();[\color]
      Thread.yield();
       }
       else{
      try{
          Thread.sleep(500);
      }
      catch (InterruptedException e){
          System.err.println("World loop error: "+e);
      }
       }
     }
}
[\color]

do you see what is missing?

And just another small question. At the end of the messages in my console, i have this:

OpenGL (AWTGLCanvas) renderer initialized
Expanding command queue to 2000 entries!
Expanding command queue to 2000 entries!


What "Expanding command queue to 2000 entries! " means?

Thanks

EgonOlsen

Looks fine to me at first glance. Maybe your scene is simply dark now. OpenGL's lighting mode is multiplicative, i.e. an ambient lighting of (0,0,0) will make everything dark. Try to draw a wireframe using world.drawWireframe(...) and see if something happens.
The command queue is a queue that the renderer uses internally because it has to do some tricks to get jPCT rendering into a canvas. Set Config.glVertexArrays=true to minimize the size of that queue.

manumoi

Once again, you found the correct answer... I modified the lights and I just had also to correct my picking method and now, everything is working fine (and faster thanks to openGL rendering). Thanks for all.

Manu