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 & HelpSyntax Questions › offscreen rendering
Page Index Toggle Pages: 1
offscreen rendering (Read 1070 times)
offscreen rendering
Mar 10th, 2010, 8:27am
 
Hello everyone.
I would like to create an 'animated' texture (a PImage) offscreen and then use this image to texturize a cube.
What i really can't get is how you 'animate' things offscreen. Let's say i have line(x,y,x1,y1) wich constantly changes it's y location - that' an 'animation'. ok, now i want to use such 'loop' as a texture.
Any hint?

Thanks in advance.  Smiley
GC
Re: offscreen rendering
Reply #1 - Mar 10th, 2010, 9:09am
 
See the PGraphics documentation. It has a (very) simple example drawing a single line to an offscreen texture, then uses image() to paint that texture onto the screen.

-spxl
Re: offscreen rendering
Reply #2 - Mar 11th, 2010, 1:00am
 
thanks
Re: offscreen rendering
Reply #3 - Mar 11th, 2010, 1:26am
 
Re: offscreen rendering
Reply #4 - Mar 11th, 2010, 1:30am
 
subpixel wrote on Mar 11th, 2010, 1:26am:
See also:


It might also be convenient to call textureMode(NORMALIZED) so you can use just 0 and 1 for your (u,v) texture coordinates instead of having to worry about how big the texture is.

-spxl

Re: offscreen rendering
Reply #5 - Mar 11th, 2010, 1:55am
 
It works!
Mhhh ... gonna work on a sphere/cube with a texture made with particles animated by perlin noise.... will post back when finished.



Code:

import peasy.*;
import processing.opengl.*;
PGraphics tex;
PeasyCam pCamera;
int ty = 0;

void setup() {
size(300,300,OPENGL);
colorMode(HSB, 360, 100, 100);
tex = createGraphics(80, 80, P3D);
pCamera = new PeasyCam(this, 300);
}

void draw() {
background(0, 0, 0);
scale(60);
TexturedCube(tex);
tex.beginDraw();
tex.background(102);
tex.stroke(255);

tex.line(40, 40, 40, ty);
tex.endDraw();
ty += 1;
if(ty > 50) ty = 0;
}

void TexturedCube(PGraphics tex) {
noFill();
stroke(1, 100, 100);
strokeWeight(1.5);
beginShape(QUADS);
texture(tex);
textureMode(NORMALIZED);
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);

vertex( 1, 1, 1, 0, 0);
vertex( 1, 1, -1, 1, 0);
vertex( 1, -1, -1, 1, 1);
vertex( 1, -1, 1, 0, 1);

vertex( 1, 1, -1, 0, 0);
vertex(-1, 1, -1, 1, 0);
vertex(-1, -1, -1, 1, 1);
vertex( 1, -1, -1, 0, 1);

vertex(-1, 1, -1, 0, 0);
vertex(-1, 1, 1, 1, 0);
vertex(-1, -1, 1, 1, 1);
vertex(-1, -1, -1, 0, 1);

vertex(-1, 1, -1, 0, 0);
vertex( 1, 1, -1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);

vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);

endShape();
}
Re: offscreen rendering
Reply #6 - Mar 11th, 2010, 6:00am
 
Suggestion: do the tex.blah() calls for the offscreen render before you use tex for the cube!

Determining (vertex and texture) coordinates for a sphere is a lot more complicated than for a cube. Good luck!

-spxl
Re: offscreen rendering
Reply #7 - Mar 12th, 2010, 7:28am
 
subpixel wrote on Mar 11th, 2010, 6:00am:
Determining (vertex and texture) coordinates for a sphere is a lot more complicated than for a cube. Good luck!

-spxl


Shocked it's true.
For the moment i 'created' this
http://www.openprocessing.org/visuals/?visualID=8207
while experimenting with the off-screen buffer.

Ciao  Wink
GC
Re: offscreen rendering
Reply #8 - Mar 12th, 2010, 9:01am
 
i got a null pointer exception because in jogl. which is probably the reason openprocessing.org doesn't like you posting opengl sketches.

try putting the camera inside the shape looking outwards...
Re: offscreen rendering
Reply #9 - Mar 12th, 2010, 9:18am
 
Cool. Needs more cubes... Maybe separate textures on each face... don't clear the texture when starting a new rule.

Smiley
Page Index Toggle Pages: 1