I need a way to store the pixels values currently on the screen and compare them to the values on the first frame. Right now I'm using glreadpixels as follows:
currentBuffer= BufferTools.reserveByteData(mapSize);
glReadPixels(mapStartX, mapStartY, mapWidth, mapHeight, GL_BLUE, GL_UNSIGNED_BYTE, currentBuffer);
for (int i = 0; i < mapSize; i++) {
if (currentBuffer.get(i) != baseBuffer.get(i)) {
//Do nothing
continue;
}
//Do something
}
This works perfectly fine but turns out to be a real bottleneck, dropping the fps to a third of what it was. Is there any quicker way? All I'm after is speed, I don't even need to show it on the screen if the comparison is made "behind the scene". I believe binding to texture is the way to go but I'm not really sure how to approach it. How do I get pixel values from a bound texture?
Read up on some tutorials about FBO's and offscreen rendering.
Basically it allows you to render to a texture, then you can read image data from a texture which can be a lot faster on certain hardware.
Here is a tutorial on FBOs: http://lwjgl.org/wiki/index.php?title=Using_Frame_Buffer_Objects_(FBO) (http://lwjgl.org/wiki/index.php?title=Using_Frame_Buffer_Objects_(FBO))
And glGetTexImage() reads the contents of a texture into a CPU side buffer: http://www.opengl.org/sdk/docs/man4/html/glGetTexImage.xhtml (http://www.opengl.org/sdk/docs/man4/html/glGetTexImage.xhtml)