Difference between revisions of "FSOSS 2010/processing.js/texture1"

From CDOT Wiki
Jump to: navigation, search
Line 5: Line 5:
 
*/
 
*/
 
import processing.opengl.*;
 
import processing.opengl.*;
/* @pjs preload="crate1.jpg; */
 
 
PImage crate;
 
  
 +
/* @pjs preload="processing.png"; */
 +
 +
PImage crateImage;
 +
 
void setup()
 
void setup()
 
{
 
{
 
   size(400, 400, OPENGL);
 
   size(400, 400, OPENGL);
   crate = loadImage("crate1.jpg");
+
   crateImage = loadImage("processing.png");
 
   textureMode(NORMALIZED);
 
   textureMode(NORMALIZED);
 
}
 
}
 +
 +
 +
void drawBox(PImage img){
 +
  background(200);
  
 
void drawBox(PImage i){
 
 
   beginShape(QUADS);
 
   beginShape(QUADS);
 
+
   texture(i);
+
   texture(img);
 
+
 
   // -Z "back" face
 
   // -Z "back" face
 
   vertex( 1, -1, -1, 0, 0);
 
   vertex( 1, -1, -1, 0, 0);
Line 27: Line 30:
 
   vertex(-1,  1, -1, 1, 1);
 
   vertex(-1,  1, -1, 1, 1);
 
   vertex( 1,  1, -1, 0, 1);
 
   vertex( 1,  1, -1, 0, 1);
 
+
 
   vertex(-1, -1,  1, 0, 0);
 
   vertex(-1, -1,  1, 0, 0);
 
   vertex( 1, -1,  1, 1, 0);
 
   vertex( 1, -1,  1, 1, 0);
 
   vertex( 1,  1,  1, 1, 1);
 
   vertex( 1,  1,  1, 1, 1);
 
   vertex(-1,  1,  1, 0, 1);
 
   vertex(-1,  1,  1, 0, 1);
 
+
 
   // +Y "bottom" face
 
   // +Y "bottom" face
 
   vertex(-1,  1,  1, 0, 0);
 
   vertex(-1,  1,  1, 0, 0);
Line 38: Line 41:
 
   vertex( 1,  1, -1, 1, 1);
 
   vertex( 1,  1, -1, 1, 1);
 
   vertex(-1,  1, -1, 0, 1);
 
   vertex(-1,  1, -1, 0, 1);
 
+
 
   // -Y "top" face
 
   // -Y "top" face
 
   vertex(-1, -1, -1, 0, 0);
 
   vertex(-1, -1, -1, 0, 0);
Line 44: Line 47:
 
   vertex( 1, -1,  1, 1, 1);
 
   vertex( 1, -1,  1, 1, 1);
 
   vertex(-1, -1,  1, 0, 1);
 
   vertex(-1, -1,  1, 0, 1);
 
+
 
   // +X "right" face
 
   // +X "right" face
 
   vertex( 1, -1,  1, 0, 0);
 
   vertex( 1, -1,  1, 0, 0);
Line 50: Line 53:
 
   vertex( 1,  1, -1, 1, 1);
 
   vertex( 1,  1, -1, 1, 1);
 
   vertex( 1,  1,  1, 0, 1);
 
   vertex( 1,  1,  1, 0, 1);
 
+
 
   // -X "left" face
 
   // -X "left" face
 
   vertex(-1, -1, -1, 0, 0);
 
   vertex(-1, -1, -1, 0, 0);
Line 56: Line 59:
 
   vertex(-1,  1,  1, 1, 1);
 
   vertex(-1,  1,  1, 1, 1);
 
   vertex(-1,  1, -1, 0, 1);
 
   vertex(-1,  1, -1, 0, 1);
 
+
 
   endShape();
 
   endShape();
 
}
 
}
 
+
 
+
 
void draw()
 
void draw()
 
{
 
{
 
   background(0);
 
   background(0);
 +
  stroke(255);
  
 
   // center in the canvas
 
   // center in the canvas
Line 69: Line 73:
 
   
 
   
 
   rotateY(radians(45));
 
   rotateY(radians(45));
 
+
 
   rotateX( frameCount/250.0f );
 
   rotateX( frameCount/250.0f );
 
+
 
   scale(50);
 
   scale(50);
 
+
   drawBox(crate);
+
   drawBox(crateImage);
 
}
 
}
 
</source>
 
</source>
 +
[http://matrix.senecac.on.ca/~asalga/pjswebide/index.php?sketchID=34 Run me]

Revision as of 14:08, 27 October 2010

/*
  FSOSS 2010
  Andor Salga
*/
import processing.opengl.*;

/* @pjs preload="processing.png"; */
 
PImage crateImage;
 
void setup()
{
  size(400, 400, OPENGL);
  crateImage = loadImage("processing.png");
  textureMode(NORMALIZED);
}
 
 
void drawBox(PImage img){
  background(200);

  beginShape(QUADS);
 
  texture(img);
 
  // -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);
  stroke(255);

  // center in the canvas
  translate(width/2, height/2, 150);
 
  rotateY(radians(45));
 
  rotateX( frameCount/250.0f );
 
  scale(50);
 
  drawBox(crateImage);
}

Run me