Difference between revisions of "FSOSS 2010/processing.js/texture1"
(Created page with '<source lang="JavaScript"> import processing.opengl.*; →@pjs preload="crate1.jpg;: PImage crate; void setup() { size(400, 400, OPENGL); crate = loadImage("crate1.jpg");…') |
|||
Line 1: | Line 1: | ||
<source lang="JavaScript"> | <source lang="JavaScript"> | ||
+ | /* | ||
+ | FSOSS 2010 | ||
+ | Andor Salga | ||
+ | */ | ||
import processing.opengl.*; | import processing.opengl.*; | ||
/* @pjs preload="crate1.jpg; */ | /* @pjs preload="crate1.jpg; */ |
Revision as of 08:31, 27 October 2010
/*
FSOSS 2010
Andor Salga
*/
import processing.opengl.*;
/* @pjs preload="crate1.jpg; */
PImage crate;
void setup()
{
size(400, 400, OPENGL);
crate = loadImage("crate1.jpg");
textureMode(NORMALIZED);
}
void drawBox(PImage i){
beginShape(QUADS);
texture(i);
// -Z "back" face
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);
// +Y "bottom" face
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);
// -Y "top" face
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);
// +X "right" face
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);
// -X "left" face
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();
}
void draw()
{
background(0);
// center in the canvas
translate(width/2, height/2, 150);
rotateY(radians(45));
rotateX( frameCount/250.0f );
scale(50);
drawBox(crate);
}