Rendering on Pbuffer without showing any window

Started by WiESi, January 08, 2005, 11:23:33

Previous topic - Next topic

WiESi

Hi!

Is it possible to render on a Pbuffer without creating any
OpenGL window? And how?

WiESi

princec

Apparently, just create a PBuffer, and use that instead of a Display :)

Cas :)

WiESi

Actually this is what I did, but it didn't seemed that anything was rendered. Do I have to swap the buffers or anything like that whan I'm finished with drawing?

WiESi

WiESi

OK, I think I should show some code:
Pbuffer buffer = new Pbuffer(320, 240, new PixelFormat(), null);
buffer.makeCurrent();
// ...
BufferedImage offscreen = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);

glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 320, 0, 240);
glMatrixMode(GL_MODELVIEW);

////////////////////////////////////////////////////////////////////
// Render method
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

glBegin(GL_TRIANGLES); {
  glColor3f(1, 0, 0); glVertex2i(10, 10);
  glColor3f(0, 1, 0); glVertex2i(310, 10);
  glColor3f(0, 0, 1); glVertex2i(150, 230);
}
glEnd();

glFinish();

// And then I copy the buffer into the BufferedImage...
BufferUtils.createBufferT(new byte[230400]);
glReadPixels(0, 0, 320, 240, GL_RGB, GL_UNSIGNED_BYTE, BufferUtils.tmpByteB);
int[] tmp = new int[76800];
for(int i = 0; i < 76800; i++) {
  tmp[i] = new Color(BufferUtils.tmpByteB.get(i * 3),
  BufferUtils.tmpByteB.get(i * 3 + 1),
  BufferUtils.tmpByteB.get(i * 3 + 2)).getRGB();
}
offscreen.setRGB(0, 0, 320, 240, tmp, 0, 320);


Here's the BufferUtils class if you shouldn't understand: http://lwjgl.org/forum/viewtopic.php?p=6070#6070

WiESi

princec

Shouldn't have to swap buffers as there's only one! I think you've just forgotten a call to glViewPort().

A much simpler way to test if anything is being drawn at all is to just clear the buffer to non-black.

Cas :)

WiESi