FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   beginShape on BImage
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: beginShape on BImage  (Read 336 times)
setpixel

WWW
beginShape on BImage
« on: Sep 12th, 2004, 10:30am »

Hi. Is there a way to draw a shape onto a BImage? Ideally, I would like to do something like:
 
buffer=new BImage(100,80);
buffer.beginShape(TRIANGLES);  
vertex(0,0);  
vertex(100,20);  
vertex(50,70);  
buffer.endShape();  
 
Obviously, that wont work currently. Does anyone know any way to do this? Ive searched the boards... the only thing Ive found is a method of drawing to the screen, then copying the screen to the buffer. I imagine that there isnt much speed difference for what Im trying to do, however I was curious if there is a more proper way to do it.
 
Also is there any reference to textureMode()? I saw it in one of toxi's sketches: "textureMode(NORMAL_SPACE);" - Just curious.
 
-chuck
 
mKoser

WWW Email
Re: beginShape on BImage
« Reply #1 on: Sep 12th, 2004, 1:14pm »

hi chuck,
 
yep, there's a way to do this... say, if you have a bitmap and want to draw onto it, you can do something like this:
 
Code:

BImage img = loadImage("img.jpg");
BGraphics buffer = new BGraphics(img.width, img.height);
buffer.format = RGBA;
 
buffer.background(img);
buffer.beginShape(TRIANGLES);
buffer.vertex(0, 0);
buffer.vertex(100, 20);
buffer.vertex(50, 70);
buffer.endShape();

 
Haven't tested this in processing, but it should work. Basically BGraphics behvaes exactly like your normal canvas, you can set rectModes, fill, stroke, etc.. and do all your fancy drawing stuff onto it.
 
Hope that helped
 
+ mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
setpixel

WWW
Re: beginShape on BImage
« Reply #2 on: Sep 12th, 2004, 5:42pm »

hi mikkel!
 
youre my new best friend. haha. it worked just fine. neat! heres a working example for quick pasting in case anyone else has a similar question.  
 
hehe - when will these things be documented?
 
-chuck
 
Code:

BImage gTexture;
BGraphics gBuffer;
BImage gAlpha;
 
int gStep = 0;
 
void setup()
{
  size(320,240);
  noStroke();
  background(0, 0, 0);
  // some image to be drawn - 200,200
  gTexture = loadImage("clouds.gif");
  gTexture.alpha(loadImage("mask.gif"));
  // alpha - 320,240
  gAlpha = loadImage("bigmaskg.gif");
  gBuffer = new BGraphics(320,240);
  gBuffer.format = RGBA;
  gBuffer.noStroke();
}
 
void loop()
{
  gStep++;
  int yOffset = int(sin(gStep/20.0)*30+120);
 
  background(255);
 
  // Draw a textured quad onto the buffer.
  gBuffer.background(0);
  gBuffer.beginShape(QUADS);
  gBuffer.texture(gTexture);
  gBuffer.vertex(0,   0+yOffset,   0,    0, 0);
  gBuffer.vertex(100, 0+yOffset,   0,  200, 0);
  gBuffer.vertex(100, 100+yOffset, 0,  200, 200);
  gBuffer.vertex(0,   100+yOffset, 0,  0,   200);
  gBuffer.endShape();
 
  //// ! Large alpha blitting and smooth on quad drawing seems to really slow things down!
  //
  //gBuffer.alpha(gAlpha);
  //smooth();
 
  // Draw the buffer onto the screen with offset.
  beginShape(QUADS);
  texture(gBuffer);
  vertex(0+yOffset,0,0,    0,0);
  vertex(320+yOffset,0,0,  320,0);
  vertex(320+yOffset,240,0,320,240);
  vertex(0+yOffset,240,0,  0,240);
  endShape();
}

 
Pages: 1 

« Previous topic | Next topic »