1
오프 스크린 드로어 블에 쓰고 이미지에 쓰는 자바 OpenGL (JOGL) 메서드를 작성하려고합니다. 화면 상 drawable과 GLP 버퍼를 사용할 때 이것이 작동하는지 확인했지만, 현재 상태의 출력 이미지는 단색 검정색입니다. 코드는 다음과 같습니다.Java OpenGL이 이미지에 오프 스크린 버퍼를 그립니다.
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"));
Github 프로젝트 jogl-demos와 단위 테스트를 살펴 보셨습니까? 내가 아는 한 GLP 버퍼는 더 이상 사용되지 않습니다. JOGL의 어떤 버전을 사용합니까? 오히려 공식 포럼에서 질문을하고 우리가 실행할 수있는 완전한 소스 코드를 제공하십시오 : http://forum.jogamp.org 어쩌면 결여 된 바인딩이나 아주 사소한 것이있을 것입니다, 나는 몇 달 전에 비슷한 실수를했습니다. – gouessej
감사합니다. GLPBuffer는 더 이상 사용되지 않지만 createOffscreenDrawable과 함께 작동하는 데 문제가 있습니다. 조깅 포럼에 예제를 게시 할 것입니다. 감사. –
비슷한 실수를하는 사람이 해결책을 찾을 수 있도록 작업 소스 코드를 포럼에 게시하면 매우 기쁩니다. http://forum.jogamp.org/Render-offscreen-buffer-to-image-td4032144 .html – gouessej