Hello Guest

Binding LWJGL and Swing/AWT (easily)

  • 27 Replies
  • 25532 Views
Re: Just about done....
« Reply #15 on: January 31, 2005, 09:28:27 »
Quote from: "gregorypierce"
I expect the next code update will be the final and we'll have something that will allow Swing and actually browser compatibility.


Any news on this?
I'd like to switch from JoGL to lwjgl, but without swing integration I can't...

Binding LWJGL and Swing/AWT (easily)
« Reply #16 on: January 31, 2005, 20:10:54 »
Its coming. Got distracted by a couple of OSX bugs that needed fixin. Done this week for certain :)

Binding LWJGL and Swing/AWT (easily)
« Reply #17 on: March 02, 2005, 12:00:28 »
Did this get finished?

I'd like to import aLWJGL windown into some swing components if possible?

Cheers

*

Offline princec

  • *****
  • 1933
    • Puppygames
Binding LWJGL and Swing/AWT (easily)
« Reply #18 on: March 02, 2005, 12:06:26 »
We've got AWT integration now if that'll do you. Should work perfectly well if you use it carefully.

Cas :)

Binding LWJGL and Swing/AWT (easily)
« Reply #19 on: March 02, 2005, 14:13:39 »
Hi cas

Is there a link somwhere mate?

*

Offline princec

  • *****
  • 1933
    • Puppygames
Binding LWJGL and Swing/AWT (easily)
« Reply #20 on: March 02, 2005, 18:47:44 »
It's currently just in the CVS, but a release is imminent.

Cas :)

Binding LWJGL and Swing/AWT (easily)
« Reply #21 on: March 03, 2005, 11:17:14 »
But i'm guessing not in the next week or so when i could do with it  :shock:

How do you get it out of the CVS?  (probable dumb question i know)

Thanks

Binding LWJGL and Swing/AWT (easily)
« Reply #22 on: March 03, 2005, 15:18:03 »
I would strongly advice not to use BufferedImage.setRGB(), instead
use MemoryImageSource.newPixels(...) backed by a int[].

Just check setRGB() and what an endless sequence of conversions
are done. It's just dead-slow.

Code: [Select]


// init

int width = 256;
int height = 512;
int pixels = width * height;
int bytesPerPixel = 3; // RGB

ByteBuffer frameData = BufferUtils.createByteBuffer(pixels*bytesPerPixel);
byte[] pixBytes = new byte[pixels*bytesPerPixel];
int[] pix = new int[pixels];
MemoryImageSource sourceImage = new MemoryImageSource(width, height, pix, 0, width);
sourceImage.setAnimated(true);
Image image = createImage(sourceImage);

// every frame

GL.read....(frameData);
frameData.rewind();
frameData.get(pixBytes, 0, pixBytes.length);

for(int i=0, j=0; i<pix.length; i++)
{
    int c = 0xFF << 24;
    c |= (pixBytes[j++] & 0xFF) << 16;
    c |= (pixBytes[j++] & 0xFF) << 8;
    c |= (pixBytes[j++] & 0xFF) << 0;
   pix[i] = c;
}

imageSouce.newPixels();

g.drawImage(image, 0, 0, null);


Cannot use the IntBuffer as we read only 24bits per pixel.

What are your opinions?

Binding LWJGL and Swing/AWT (easily)
« Reply #23 on: March 03, 2005, 16:11:45 »
Does anyone have some simple example like drawing a cube using the awt code coz i cant make head nor tails of it.....

Binding LWJGL and Swing/AWT (easily)
« Reply #24 on: March 15, 2005, 17:34:06 »
In jME we don't use setRGB either, we create our BufferedImage and then directly access the DataBuffer of the Raster...  which can be manipulated as an array of ints...

Code: [Select]
int[] ibuf = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();

Our data is grabbed from an IntBuffer that is populated from the GL thread (throttled though to only grab every X ms) using:
Code: [Select]
   public void grabScreenContents(IntBuffer buff, int x, int y, int w, int h) {
        GL11.glReadPixels(x, y, w, h, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE,
                        buff);
    }


Then it's a simple matter to copy from the IntBuffer to the int array backing the BufferedImage:
Code: [Select]
buf.clear(); // Note: clear() resets marks and positions,
//       but not data in buffer.
//Grab pixel information and set it to the BufferedImage info.
for (int x = height; --x >= 0; ) {
buf.get(ibuf, x * width, width);
}


You go on to draw the image as normal.

The copying portions of this code are extremely fast, the slow part is just glReadPixels, which we throttle to only happen a certain number of times per second...  There's no real reason to do it any faster than screen refresh rate for example.

That all said, I'm anxious to see .96 lwjgl with it's direct integration into AWT (or so I've heard.)

Update?
« Reply #25 on: May 19, 2005, 18:01:34 »
greg wrote:
Quote

I expect the next code update will be the final and we'll have something that will allow Swing and actually browser compatibility.


Did this ever go anywhere?
Jim

*

Offline princec

  • *****
  • 1933
    • Puppygames
Binding LWJGL and Swing/AWT (easily)
« Reply #26 on: May 19, 2005, 20:10:14 »
AWTGLCanvas does everything nicely now. Try it out. Just remember it's a heavyweight component.

Cas :)

*

Offline rainforest

  • *
  • 33
  • Enthusiast ambitious
AWTGLCanvas
« Reply #27 on: October 19, 2005, 19:00:31 »
Dear Cas

Please give me the location of the download.

rainforest.
.:: A journey of thousand miles starts with a single step ::.