10-31-2005, 03:19 AM
OK, here's what I want to do. I want to draw some stuff on a back buffer (which never gets displayed on screen) which I can read pixels from at a later date, and then I want to draw my main stuff to the normal buffer and display it on screen as usual.
I'm trying to draw my background stuff onto the back right buffer, then all the rest goes on the back left one and swapped over for the double buffer as usual. Here's some simple code:
gl.glReadBuffer(GL_BACK_RIGHT);
gl.glDrawBuffer(GL_BACK_RIGHT);
gl.glClearColor(1.0f, 1.0f, 0.0f, 0.0f); // Set the clear color to yellow
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
gl.glReadBuffer(GL_BACK_LEFT);
gl.glDrawBuffer(GL_BACK_LEFT);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set the clear color to black
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
So if I now do the following with glReadPixels, should it be able to read the yellow color from the back right buffer?
gl.glReadBuffer(GL_BACK_RIGHT);
gl.glDrawBuffer(GL_BACK_RIGHT);
int viewport[] = new int[4];
byte pixel[] = new byte[3];
gl.glGetIntegerv(GL_VIEWPORT,viewport);
gl.glReadPixels(mouse_x,viewport[3]-mouse_y,1,1,GL_RGB,GL_BYTE,pixel);
System.out.println("color: " + pixel[0] + ", " + pixel[1] + ", " + pixel[2]);
Because it doesn't! It only gives me the black color from the left buffer instead. :(
Am I missing something simple?!
Many thanks!
Charles
I'm trying to draw my background stuff onto the back right buffer, then all the rest goes on the back left one and swapped over for the double buffer as usual. Here's some simple code:
gl.glReadBuffer(GL_BACK_RIGHT);
gl.glDrawBuffer(GL_BACK_RIGHT);
gl.glClearColor(1.0f, 1.0f, 0.0f, 0.0f); // Set the clear color to yellow
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
gl.glReadBuffer(GL_BACK_LEFT);
gl.glDrawBuffer(GL_BACK_LEFT);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set the clear color to black
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
So if I now do the following with glReadPixels, should it be able to read the yellow color from the back right buffer?
gl.glReadBuffer(GL_BACK_RIGHT);
gl.glDrawBuffer(GL_BACK_RIGHT);
int viewport[] = new int[4];
byte pixel[] = new byte[3];
gl.glGetIntegerv(GL_VIEWPORT,viewport);
gl.glReadPixels(mouse_x,viewport[3]-mouse_y,1,1,GL_RGB,GL_BYTE,pixel);
System.out.println("color: " + pixel[0] + ", " + pixel[1] + ", " + pixel[2]);
Because it doesn't! It only gives me the black color from the left buffer instead. :(
Am I missing something simple?!
Many thanks!
Charles