Questions about PBuffers
Posted by Martin Hegedus on Dec 13, 2011; 4:48am
URL: https://forum.jogamp.org/Questions-about-PBuffers-tp3581441.html
My goal is to create a png image for printing. So, I've created an offscreen drawable, drawn to it, and then extracted a buffered image using Screenshot. I'm running under Linux. Haven't tried windows yet.
I've got two questions.
First, does the memory required for pbuffer come from the video card or mother board? If it is from the video card I'm concerned that some may not have enough memory especially when driving several monitors from a laptop. From the internet I gather it is video card memory. Therefore, if allocating a pbuffer fails I would like to use a regular pixel map.
Second, when using a pbuffer my code works, but when using a pixel map, I just get the black background (even though I've set the clear color to white.) So I gather no drawing, or clearing, is being done. Is setting the pbuffer to 'false' a valid option? Or is this possibly a bug?
Thanks.
Here is a snip-it of my code so one can get an idea of what I'm doing. I can provide more if required.
GLCapabilities glCaps = new GLCapabilities(null);
glCaps.setRedBits(8);
glCaps.setBlueBits(8);
glCaps.setGreenBits(8);
glCaps.setAlphaBits(8);
glCaps.setDoubleBuffered(false);
glCaps.setOnscreen(false);
glCaps.setPBuffer(true); // this code fails to draw if this is set to false.
glCaps.setHardwareAccelerated(false);
GLDrawableFactory fac = GLDrawableFactory.getDesktopFactory();
GLDrawable buf = fac.createOffscreenDrawable(null, glCaps, null, width, height);
GLContext context = buf.createContext(null);
context.makeCurrent();
GL2 gl = context.getGL().getGL2();
gl.glClearColor(1.0f,1.0f,1.0f,1.0f); // set clear color to white
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );
Draw(gl);
BufferedImage img = Screenshot.readToBufferedImage(width,height);
context.release();