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 › Using transform matrix with PImages
Page Index Toggle Pages: 1
Using transform matrix with PImages? (Read 646 times)
Using transform matrix with PImages?
Aug 20th, 2007, 11:49am
 
Hi all, I am currently rendering sprites to the screen with a specific position, rotation and scale factor:

   pushMatrix();
   translate(posX, posY);
   scale(scaleX, scaleY);
   rotate(rotation);

   imageMode(CORNER);
   image(imgSprite, -halfSpriteWidth, -halfSpriteHeight);
   popMatrix();

Now I would like to render everything to a back buffer, i.e. instead of using image() to copy the sprites to the screen directly, I want to render them to a PImage the size of the screen, with the same transformations applied. Is this possible at all?


Re: Using transform matrix with PImages?
Reply #1 - Aug 20th, 2007, 12:14pm
 
Re: Using transform matrix with PImages?
Reply #2 - Aug 20th, 2007, 1:05pm
 
Great thanks, that's exactly what I meant.

I have a renderer problem though: Since I need to use OPENGL for performance reasons (I'm only using 2D rendering though), and you cannot create a secondary PGraphics object using OPENGL, I create a PGraphics object "pg" using the P2D renderer. When I use pg.image(), all I get is a transparent box in within pg, the size of the image I try to copy. When I use JAVA2D for both the main renderer and pg, everything works (but is slow). When I use OPENGL as primary and JAVA2D for pg, I get an exception:

java.lang.RuntimeException: java.lang.ClassCastException: processing.opengl.PGraphicsOpenGL$ImageCache

Is there any way to cross the gap between the different renderers?
Re: Using transform matrix with PImages?
Reply #3 - Aug 20th, 2007, 1:30pm
 
try P3D for the created PGraphics
Re: Using transform matrix with PImages?
Reply #4 - Aug 20th, 2007, 1:46pm
 
there's currently a problem (bug?) where you cannot draw an image object with more than one type of renderer. that is, if you use createGraphics() or loadImage(), and draw the result with an OpenGL surface you cannot later draw it using Java2D, and vice versa. that will give you the ImageCache error.

the solution is to make a copy of the image, do loadImage() twice, or just avoid drawing the same image into both drawing areas. see reply #6 from this thread:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1181635522
Re: Using transform matrix with PImages?
Reply #5 - Aug 20th, 2007, 4:23pm
 
Thanks fry, that completely solved the problem.

I was also wondering about some other internals of the image handling: With the code I posted above, are images scaled+rotated on each redraw, or does Processing cache transformed versions in memory, or is this delegated to the graphics hardware via OPENGL altogether? If not, could I improve the already excellent performance if I cached the transformed images?
Page Index Toggle Pages: 1