Author Topic: Fenggui with jpct in OpenGL mode  (Read 5007 times)

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
Fenggui with jpct in OpenGL mode
« on: May 21, 2008, 10:11:40 pm »
Hello. It's been a long time since I last wrote here.

I'm trying to integrate fenggui in my warehouse application created some time ago, but I'm having some difficulties.

initialization part
Code: [Select]
         setDefaultEnvironement();
         new Vis3DConfig(this);
         ModelLoader.loadTextures();
         ModelLoader.cacheModels();
         warehouses = WarehouseXMLLoader.load(doc);
         //set first warehouse as default
         warehouse = (WareHouse)warehouses.get(0);
         warehouse.startControllers();
         doc = null;
         warehouse.setDefaultThread(Thread.currentThread());
         buffer = new FrameBuffer(resWidth, resHeight, FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
         buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
         buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
for some reason if i dont put sleep here i get an exception
java.lang.IllegalStateException: Mouse must be created.
   at org.lwjgl.input.Cursor.getMaxCursorSize(Cursor.java:136)
        ...

Code: [Select]
         --------ADDED FROM HERE-------
         try
         {
            Thread.sleep(2000);
         }
         catch (InterruptedException ie)
         {}
         LWJGLBinding binding = new LWJGLBinding();
         desk = new org.fenggui.Display(binding);
         buildGUI();
         --------ADDED UNTIL HERE-------
         render();


adding test gui widget
Code: [Select]
      Window mw = new Window();
      desk.addWidget(mw);
      mw.setTitle("TEST EMPTY WINDOW");
      mw.setSize(300, 100);
      mw.setX(100);
      mw.setY(100);
      desk.layout();


rendering part
Code: [Select]
      while (running)
      {
         poll();
         synchronized(warehouse)
         {
             warehouse.doMovement();
             buffer.clear();
             warehouse.renderScene(buffer);
             warehouse.draw(buffer);
         }
         buffer.update();
here i get an exception

java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glPushAttrib(GL11.java:2495)
   at org.fenggui.render.lwjgl.LWJGLOpenGL.pushAllAttribs(Unknown Source)
   at org.fenggui.Display.display(Unknown Source)
        ...

Code: [Select]
         --------ADDED FROM HERE-------
         desk.display();
         --------ADDED UNTIL HERE-------
         addBliting(buffer);
         buffer.displayGLOnly();
         second = System.nanoTime();
         actualSleepTime = sleepTime - (second - first);
         if (actualSleepTime < 0)
         {
            actualSleepTime = 0;
         }
         long actualMilsec = (long)((float)actualSleepTime/1000000f);
         int actualnanoSec = (int)(actualSleepTime%1000000);
         try
         {
            Thread.sleep(actualMilsec, actualnanoSec);
         }
         catch (InterruptedException ie)
         {}
         first = second;
      }



I checked in fenggui source and it is thrown here

Code: [Select]
    public void pushAllAttribs() {
    GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
    }

Anyone know what I'm doing wrong?
« Last Edit: May 21, 2008, 10:24:22 pm by eye1 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Fenggui with jpct in OpenGL mode
« Reply #1 on: May 21, 2008, 10:31:09 pm »
No idea. Raft did some tests with FengGUI: Maybe he can help. About the first exception: This somehow looks as if some thread in the background takes some time to create the mouse, which it doesn't have without the sleep. But that makes not much sense to me. Which thread should that be? At least none from jPCT...there is none that does this...unless you are using Config.useMultipleThreads...are you?

Offline eye1

  • int
  • **
  • Posts: 68
    • View Profile
Re: Fenggui with jpct in OpenGL mode
« Reply #2 on: May 21, 2008, 11:57:51 pm »
OMG Egon....

Yes I changed useMultipleThreads property to false and it solved both exceptions.


Thank you very much.... I was banging my head over that for the whole day :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Fenggui with jpct in OpenGL mode
« Reply #3 on: May 22, 2008, 07:23:22 am »
When using multiple threads, the actual rendering (as well as the initialization) happens in a thread of its own. Which also means that this thread has the OpenGL context. To combine FengGUI with this, you'll have to attach an IPaintListener to the buffer and do the GUI setup and rendering in the call back methods. That should work (I've never tried it)...or you don't use multiple thread any longer when using FengGUI.