I'm messing around with the framebuffer with OpenGL and JOGL. I have a Graphics obje开发者_Python百科ct, in which I draw.
Everytime the Graphics changes, I extract the R,G,B and A information as bytes for each pixel and write it to a ByteBuffer in the A R G B order. I checked the conversion, it is alright.
If I call the drawPixels method using GL_RGB mode, it draws box at the given coordinates, it is drawn black no matter what colors I had in my graphics. If I use GL_RGBA mode, it draws nothing.
So my code for the framebuffer operations, ib1 is the byte buffer with the image data:
GL gl=canvas.getGL();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho (0, canvas.getWidth(), canvas.getHeight(),0, -1.0, 1.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glColor3f(1, 1, 1);
//
gl.glRasterPos2i(0, height);
//gl.glDrawPixels(width, height, GL.GL_RGB, GL.GL_BYTE, ib1);
gl.glDrawPixels(width, height, GL.GL_RGBA, GL.GL_BYTE, ib1);
Thanks in advance for your help
The Problem was the format of the pixel data OpenGL expects.
My output was an array of integers, wihich I could split in 4 single byte values for RGBA. However, OpenGL expects them to be in signed format, so 01111111 is the highest, 10000000 is the lowest value. my Java output from the Graphics2D object was unsigned, so values from 00000000 (lowest) to 11111111. A few bit operations later it is working now.
精彩评论