Counting pixels

What is in your opinion the fastest way to count pixels? I know that i could calculate 640px X 480px and get 307200px but i want to count special pixel(color).

I had a look at TestRenderToMemory and i’m using the updateImageContents method. It works good but i’m asking myself as a beginner if there is a better/faster way?

Its possible to do this, and even hardware accelerated. It’s called occlusion queries and is not currently supported in any jME version.

May I know why you want to do this? Perhaps we can implement this feature in jME for that particular purpose.

I’m calculating the projected area of an object. I need that information for the drag force(buoyancy,water and that stuff). I’m already calculating the volume with the help of rays which leads me to this problem :wink:



What i’m doing is have a new camera with black background and the object in complete white. I’m also using the parallel projection. And than i’m counting the white pixels. And since i know the width and height of a pixel on the near plane i get a very accurate result. Depending on the resolution of course ;). Yes i could use the ray algorithm that i’m already using to calculate the volume but i thought that calculating the area could be done faster with this method. Instead of shooting a lot of rays.

Maybe you can just project the bounding volume, and calculate the surface area of that? Perhaps this will be of any help?

I guess not… I don’t think this kind of thing is general-purpose enough to be implemented in the engine core, so perhaps you can try learning a bit about OpenGL occlusion queries and see if you could get it done yourself?

Don’t get me wrong. It’s already working and it’s very fast and accurate. As a JME noob i wanted only to know if there isn’t some obvious much better solution ;). Anyway thanks for your help.