We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Lots of images
Page Index Toggle Pages: 1
Lots of images (Read 1204 times)
Lots of images
Apr 13th, 2009, 12:57pm
 
I'm trying to create an application that loads lots of big wallpaper-sized images (1024x768).  You can see a quick video of what I currently have here:

http://www.chrisharrison.net/temp/viz2.mov

Basically a big grid of pictures... and the app zooms around highlighting each one for a few seconds.

For testing purposes, I use four images repeated in a big grid.  I can make that grid huge (like 15x15 images) and it runs fine.  But if I load in 36 *different* images, for a 6x6 grid, it's very very slow.

So it seems it's not so much actually drawing that many pixels, but more of some memory issue, or caching on graphics card issue(??)

I need to get up to maybe 100-200 images in total.

Any ideas how I can speed this up?  

Right now I'm using regular image() draws and movement with translate/scale/rotate. This is silky smooth with four images repeated in huge grids (esp in OpenGL mode), but not lots of images repeated in medium to large grids.

Any help much appreciated,
Chris
Re: Lots of images
Reply #1 - Apr 13th, 2009, 1:49pm
 
there was a thread about this topic a while ago... couldnt find it. but im sure somebody knows where it is.
Re: Lots of images
Reply #2 - Apr 16th, 2009, 8:45am
 
Hoping someone still might have some input on this....

Basically looking to load one hundred 1024x768 images into a program and draw them with any degree of performance.

Chris
Re: Lots of images
Reply #3 - Apr 16th, 2009, 8:50am
 
example code?
Re: Lots of images
Reply #4 - Apr 16th, 2009, 9:01am
 
Here is my draw function.  The most important lines are the for loop at the bottom.  That is drawing a big grid of images.  The other code is mostly for setting which picture it is moving/zooming towards.

The end result looks like: http://www.chrisharrison.net/temp/viz2.mov

Code:
void draw()
{
 if (System.currentTimeMillis() - lastMovement > DELAYTIME)
 {
   lastx = -activex * widthInc;
   lasty = -activey * heightInc;

   activex = random.nextInt(gridsize);
   activey = random.nextInt(gridsize);

   lastMovement = System.currentTimeMillis();
 }

 int destx = -activex * widthInc;
 int desty = -activey * heightInc;
 float totaldist = sqrt((destx - lastx) * (destx - lastx) + (desty - lasty) * (desty - lasty)) + 1;

 if (movement.getDistanceTo(destx, desty) / totaldist > 0.5f)
 {
   zoomdest = constrain(zoomdest-0.05f, MAXZOOMOUT,1.00f);
   movement.setConstant(40);
 }
 if (movement.getDistanceTo(destx, desty) / totaldist < 0.007f)
 {
   zoomdest = constrain(zoomdest+0.02f, 0, 1.00f);
   movement.setConstant(15);
 }

 movement.followTo(destx, desty);
 movement.move();

 zoomer.followTo(zoomdest, zoomdest);
 zoomer.move();

 translate(width / 2, height / 2);
 rotate((float) (radians(movement.getDistanceTo(destx, desty) / totaldist)*360.0f));
 scale(zoomer.getX());
 translate(movement.getX() - width / 2, movement.getY() - height / 2);

 background(0);

 for (int i = 0; i < items.size(); i++)
 {
   GridItem g = (GridItem) items.get(i);
   image(g.img, (i % gridsize) * widthInc, (i / gridsize) * heightInc);
 }
}

Re: Lots of images
Reply #5 - Apr 27th, 2009, 8:37am
 
Slightly different question then...

Can anyone post simple code on how to load and draw textures in OpenGL.  

Or pose some other method for image loading?

Chris
Re: Lots of images
Reply #6 - Apr 27th, 2009, 9:16am
 
I don't know if you done the research suggested by Cedric, but anyway there were no hard and fast solution.
A 1024x768 image uses theoretically 3MB, so 100 to 200 images should fit in memory, if you tweak the memory settings (you have to tell Java to use more memory, as it won't take all usable memory by default).
In practice, some people noticed the memory usage is much bigger, perhaps with temp buffers or such.
A possible solution in your case can be to load images when needed, when the movement will need to display them, and to drop images going out of view, but that would be trading memory vs. loading time, which might not be better.
Page Index Toggle Pages: 1