glDrawPixles

I am trying to get a BufferedImage and extract the pixel data to feed into glDrawPixels(), but it keeps giving me an exception. Here is the StackTrace:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Number of remaining buffer elements is 502865, must be at least 1508598
	at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:177)
	at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:187)
	at org.lwjgl.opengl.GL11.glDrawPixels(GL11.java:2026)
	at Canvas.paintGL(Canvas.java:123)
	at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:256)
	at sun.awt.RepaintArea.paintComponent(Unknown Source)
	at sun.awt.RepaintArea.paint(Unknown Source)
	at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

and the relevant code:

GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        Image img = viewport.CreateImage(null);
        BufferedImage bufImg = gc.createCompatibleImage(img.getWidth(null), img.getHeight(null), Transparency.OPAQUE);

        System.out.println(bufImg);
        
        DataBuffer dataBuffer = bufImg.getData().getDataBuffer();
        
        IntBuffer image = IntBuffer.allocate(dataBuffer.getSize());
        image.put(dataBuffer.getOffsets());
        
        System.out.println("db.size: " + dataBuffer.getSize() + "\nib.rem: " + image.remaining());
        
        GL11.glDrawPixels(img.getWidth(null), img.getHeight(null), GL11.GL_RGB, GL11.GL_INT, image);

Can anyone help me figure this out? I really have no idea how this works!

(no need to reply, this was xposted from lwjgl.org)

Cas :slight_smile:

Sorry, I didn’t mean to cross post, but I guess that most of you do read both boards. I’ll keep that in mind for the future! :wink: