1

オフスクリーン ドローアブルに書き込み、それを画像に書き込む Java opengl (JOGL) メソッドを作成しようとしています。オンスクリーン ドローアブルと GLP バッファを使用している場合にこれが機能することを確認しましたが、現在の状態の出力画像は真っ黒です。コードは以下です。

GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
caps.setOnscreen(false);

// create the offscreen drawable
GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
GLOffscreenAutoDrawable drawable = factory.createOffscreenAutoDrawable(null,caps,null,width,height);
drawable.display();
drawable.getContext().makeCurrent();

// a series of x/y coordinates
FloatBuffer buffer = generateData();

GL2 gl = drawable.getGL().getGL2();

// use pixel coordinates
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();    
gl.glOrtho(0d, width, height, 0d, -1d, 1d);

// draw some points to the drawable
gl.glPointSize(4f);
gl.glColor3f(1f,0f,0f);    
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glVertexPointer(2, GL2.GL_FLOAT, 0, buffer);
gl.glDrawArrays(GL2.GL_POINTS, 0, numPoints);

BufferedImage im = new AWTGLReadBufferUtil(drawable.getGLProfile(), false).readPixelsToBufferedImage(drawable.getGL(), 0, 0, width, height, true /* awtOrientation */);
ImageIO.write(im,"png",new File("im.png"));
4

2 に答える 2