Author Topic: Re: Blox Builder  (Read 11323 times)

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« on: November 20, 2009, 02:46:22 pm »
This thread is a split from here: http://www.jpct.net/forum2/index.php/topic,1462.0.html


- ATM I called getpixels in the main thead, aka:

Code: [Select]
public void init()
    {
    

        ........        
        new Thread(this).start();
    }

public void paint(Graphics g)
    {        
        super.paint(g);
        
        .....

       // render the world onto the buffer:
       world.renderScene(buffer);
       world.draw(buffer);
       buffer.update();
        ......

        buffer.getPixels();
        buffer.displayGLOnly();

        //output
        rendercanvas.repaint();
}

public void run()
    {
     while (loop)
        {
     if (mouseoverleftturn && mousedown)
         {    
         turnLeft();
         }
         else if (mouseoverrightturn && mousedown)
         {
         turnRight();
         }
    
            this.repaint();
            try
            {
                Thread.sleep(16);
            }
            catch(Exception e)
            {
                //Don't care...
            }
        }
    }

I assume I should move the getPixels() call out of the paint method and into another thread? If I do that, would it be synchronized with the update method of the buffer?

- It was more a general question, atm I load the 3DS file directly from the server, however the 3DS contains references to textures which don't seem to work. But the textures have to be bumpmapped anyway, so I guess I can't just use the loadobject method and expect it to work :). Will have to put some work in that one :D
« Last Edit: November 20, 2009, 08:58:41 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #1 on: November 20, 2009, 02:56:27 pm »
Yes, move it out of the paint-method. The paint-method is called in the awt event dispatch thread too, which means that calling getPixels() in paint cause jPCT to wait for paint() to complete, which is a bad idea while being inside of paint itself... ;)

If you are calling it from another thread, the call will wait for the next painting and return with the result. Something like this should work:

Code: [Select]
public void paint(Graphics g)
  {        
      super.paint(g);
      
      world.renderScene(buffer);
      world.draw(buffer);
      buffer.update();

      if (hasToGetPixels) {
        new Thread() {
          public void run() {
            pixels=buffer.getPixels();
          }
        }.start();
        hasToGetPixels=false;
      }
      if (pixels!=null) {
        writePixels(pixels);
        pixels=null;
      }
      
      buffer.displayGLOnly();

      rendercanvas.repaint();
  }

Remember to not call getPixels() on each frame. It will cripple performance.

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #2 on: November 20, 2009, 02:59:33 pm »
Thanks, that's great! Very helpful :)

And no, I don't call it every frame, just copied the relevant parts of the code which made it look that way ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #3 on: November 20, 2009, 03:00:06 pm »
- It was more a general question, atm I load the 3DS file directly from the server, however the 3DS contains references to textures which don't seem to work. But the textures have to be bumpmapped anyway, so I guess I can't just use the loadobject method and expect it to work :). Will have to put some work in that one :D
I'm still not sure if i got the question right, but the model loaders don't load any textures at all. More information can be found in the wiki: http://www.jpct.net/wiki/index.php/Loading_models

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #4 on: November 20, 2009, 03:02:33 pm »
Got it now, the loader only loads the name of the texture and I have to make sure the texture is available in the texturemanager. Sounds simple enough, now I only have to write the pixelshader for bumpmapping.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #5 on: November 20, 2009, 03:44:57 pm »
There's a simple bump mapping shader in the wiki as an example. The "problem" is, that jPCT doesn't provide the tangent vectors, which is why the example in the wiki approximates them: http://www.jpct.net/wiki/index.php/Shaders

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #6 on: November 20, 2009, 05:06:27 pm »
One last question, on intel graphics chips i receive following error:

[ Sun Sep 27 23:38:17 CEST 2009 ] - ERROR: No support for WGL_ARB_multisample

Any idea which parameter causes this?

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #7 on: November 20, 2009, 05:22:43 pm »
al right, has to do with the sampling mode, how do I find out which sampling modes a card supports?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #8 on: November 20, 2009, 08:48:20 pm »
al right, has to do with the sampling mode, how do I find out which sampling modes a card supports?
You can query the driver via LWJGL directly...the problem is, that you can do this only if you already have a valid GL context. For my game Robombs, i'm creating a small native GL window at startup, query the driver and close the window afterwards. But that's not really an option for an applet. To be honest, i would simply ignore the fact that intel's crapsets can't do any proper multi-sampling and ignore the error. In case you can't/don't want to, the actual call to get the information is

Code: [Select]
boolean canDoAA=GLContext.getCapabilities().GL_ARB_multisample;

This has to be executed in the awt event dispatch thread when using the GLCanvas, i.e. you have to put it into one of the methods that the IPaintListener interface offers. You may try what actually happens when calling this before creating the frame buffer directly in the main thread. Maybe that information is already available then, but i heavily doubt it.
« Last Edit: November 20, 2009, 08:50:12 pm by EgonOlsen »

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #9 on: November 21, 2009, 12:05:29 am »
I would happily ignore the error if those forementioned crapsets would render anything, however they don't fall back to normal mode.

I'll try to start in normal mode, do one repaint, ask for the capabilities in the paintstarted method and reinitialize the buffer according to the result. Should work i guess?

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #10 on: November 21, 2009, 12:12:06 am »
Code: [Select]
@Override
public void startPainting()
{
        if (GLContext.getCapabilities().GL_ARB_multisample)
        {
        System.out.println("Reinit for multisample");
        buffer.dispose();
       
        // create a new buffer to draw on:
            buffer = new FrameBuffer(RENDERWIDTH, RENDERHEIGHT, FrameBuffer.SAMPLINGMODE_GL_AA_4X);
            buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
            buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
           
            rendercanvas = buffer.enableGLCanvasRenderer();
            rendercanvas.setBackground(new Color(34,34,34));
            rendercanvas.setSize(RENDERWIDTH, RENDERHEIGHT);
        }

buffer.setPaintListener(null);

        new Thread(this).start();
}


something like this i guess, but it doesn't work yet. No errors, but also no rendering to be seen :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #11 on: November 21, 2009, 10:13:22 am »
When using the native gl renderer, this fallback works fine. Maybe there's a problem with GLCanvas when trying the same thing. I'll have a look at that and report back...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #12 on: November 21, 2009, 02:17:56 pm »
Looking at the code, i remember the actual problem here. It's this: Before creating the AWTGLCanvas, you can't query the driver for features because you have no context. The context itself is created inside of the canvas' paint method by LWJGL. If the hardware doesn't support the sampling mode, this fails and the canvas calls a method named exceptionOccured, which is the method that prints out the error message you are seeing.
The problem is, that you actually can't change the pixel format afterwards. It's feeded into the constructor of the canvas and goes into a private field. So you end up with a canvas that can't initialize itself properly (but tries again in each iteration...), you are aware of this...but you can't change anything.
I've uploaded a new jpct.jar here: http://www.jpct.net/download/beta/jpct.jar. In case of this error, it tries to inject a new pixel format into the canvas via reflection, modifies some other fields of the canvas so that it thinks that it's new and makes the canvas reinit itself this way with a proper pixel format in the next paint-call. This is very hacky...and it only works as long as the behaviour of the canvas doesn't change.
Anyway, just give it a try and tell me if it helps.
« Last Edit: November 21, 2009, 02:22:17 pm by EgonOlsen »

Offline trisco

  • byte
  • *
  • Posts: 23
    • View Profile
Re: Blox Builder
« Reply #13 on: November 21, 2009, 04:54:36 pm »
hmmmm, another error:

Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Using LWJGL's AWTGLCanvas
Software renderer disposed
Loading Texture...textures/floor_select.jpg
Loading Texture...textures/floor.jpg
Loading Texture...icons/turn_right_over.png
Loading Texture...icons/turn_left_over.png
Loading Texture...icons/turn_right_over.png
Loading Texture...icons/turn_left_over.png
Loading Texture...icons/lookdown.png
Loading Texture...icons/lookup.png
Building octree for 8192 triangles!
Octree constructed with 1 nodes / 1 leafs.
Adding Lightsource: 0
Adding Lightsource: 1
[ Sat Nov 21 16:49:44 CET 2009 ] - ERROR: Unable to recover: No support for WGL_ARB_multisample
Loading Texture...from Image
[ Sat Nov 21 16:49:52 CET 2009 ] - ERROR: Unable to recover: No support for WGL_ARB_multisample
[ Sat Nov 21 16:49:52 CET 2009 ] - ERROR: Unable to recover: No support for WGL_ARB_multisample
[ Sat Nov 21 16:49:52 CET 2009 ] - ERROR: Unable to recover: No support for WGL_ARB_multisample
[ Sat Nov 21 16:49:52 CET 2009 ] - ERROR: Unable to recover: No support for WGL_ARB_multisample
....

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blox Builder
« Reply #14 on: November 21, 2009, 06:20:27 pm »
I've updated the jar with a version that prints out the actual exception message ("No support for WGL_ARB_multisample" isn't the one causing this print out). Judging from the log, i would guess that your lwjgl-version doesn't have the field in AWTGLCanvas where i'm trying to inject the pixel format into. I've used version 2.2.1 (the latest). Maybe it works with that one? The news-section has a link to it.