processing.opengl.PGL Java Examples

The following examples show how to use processing.opengl.PGL. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Skylight_BasicGUI.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphicsOpenGL canvas){
  if(canvas == skylight.renderer.pg_render){
    canvas.background(BACKGROUND);
    displaySamples(canvas);
  }
  
  if(canvas == geombuffer.pg_geom){
    canvas.pgl.clearDepth(1.0f);
    canvas.pgl.clearColor(1, 1, 1, clip_z_far);
    canvas.pgl.clear(PGL.COLOR_BUFFER_BIT | PGL.DEPTH_BUFFER_BIT);
  }
  
  canvas.pushMatrix();
  canvas.applyMatrix(mat_scene_view);
  canvas.shape(shp_group);
  canvas.popMatrix();
}
 
Example #2
Source File: Skylight_BulletPhysics_Cubes.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #3
Source File: Skylight_BulletPhysics_CellFracture.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #4
Source File: Skylight_BulletPhysics_MengerSponge.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(180);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #5
Source File: Skylight_BulletPhysics_Breakable.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #6
Source File: Skylight_BulletPhysics_Breakable_VideoExport.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #7
Source File: Skylight_BulletPhysics_Breakable3.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.shape(group_collisions);
  pg.popMatrix();
}
 
Example #8
Source File: Skylight_BulletPhysics_TowerDemolition.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #9
Source File: Skylight_BulletPhysics_Basic.java    From PixelFlow with MIT License 6 votes vote down vote up
public void displayScene(PGraphics3D pg){
  if(pg == skylight.renderer.pg_render){
    pg.background(16);
  }
  
  if(pg == geombuffer.pg_geom){
    pg.background(255, 255);
    pg.pgl.clearColor(1, 1, 1, 6000);
    pg.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  
  pg.pushMatrix();
  pg.applyMatrix(mat_scene_view);
  pg.shape(group_bulletbodies);
  pg.popMatrix();
}
 
Example #10
Source File: DwUtils.java    From PixelFlow with MIT License 6 votes vote down vote up
static public void changeTextureFormat(PGraphicsOpenGL pg, int internal_format, int format, int type, int filter, int wrap){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureFormat: PGraphicsOpenGL texture not available.");
    return;
  }
  
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MIN_FILTER, filter); // GL_NEAREST, GL_LINEAR
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MAG_FILTER, filter); 
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_WRAP_S, wrap);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_WRAP_T, wrap);
  pgl.texImage2D   (tex.glTarget, 0, internal_format, tex.glWidth, tex.glHeight, 0, format, type, null);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
  
  pg.beginDraw();
  pg.clear();
  pg.endDraw();
}
 
Example #11
Source File: PShaderCompiler.java    From haxademic with MIT License 6 votes vote down vote up
/**
 * @param shaderSource a string containing the shader's code
 */
protected boolean compileFragmentShader() {
	pgl.shaderSource(glFragment, PApplet.join(fragmentShaderSource, "\n"));
	pgl.compileShader(glFragment);

	pgl.getShaderiv(glFragment, PGL.COMPILE_STATUS, intBuffer);
	boolean compiled = intBuffer.get(0) == 0 ? false : true;
	if (!compiled) {
		this.valid = false;
		setCompileMessage("Cannot compile fragment shader:\n" +
				pgl.getShaderInfoLog(glFragment));
		return false;
	} else {
		return true;
	}
}
 
Example #12
Source File: PShaderCompiler.java    From haxademic with MIT License 6 votes vote down vote up
/**
 * @param shaderSource a string containing the shader's code
 */
protected boolean compileVertexShader() {
	pgl.shaderSource(glVertex, PApplet.join(vertexShaderSource, "\n"));
	pgl.compileShader(glVertex);

	pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, intBuffer);
	boolean compiled = intBuffer.get(0) == 0 ? false : true;
	if (!compiled) {
		this.valid = false;
		setCompileMessage("Cannot compile vertex shader:\n" +
				pgl.getShaderInfoLog(glVertex));
		return false;
	} else {
		return true;
	}
}
 
Example #13
Source File: PShaderCompiler.java    From haxademic with MIT License 6 votes vote down vote up
protected void validate() {
	pgl.getProgramiv(glProgram, PGL.LINK_STATUS, intBuffer);
	boolean linked = intBuffer.get(0) == 0 ? false : true;
	if (!linked) {
		this.valid = false;
		setCompileMessage("Cannot link shader program:\n" +
				pgl.getProgramInfoLog(glProgram));
	}

	pgl.validateProgram(glProgram);
	pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, intBuffer);
	boolean validated = intBuffer.get(0) == 0 ? false : true;
	if (!validated) {
		this.valid = false;
		setCompileMessage("Cannot validate shader program:\n" +
				pgl.getProgramInfoLog(glProgram));
	} 
}
 
Example #14
Source File: ImageUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static int getPixelColorFast( PApplet p, PGraphics image, int x, int y ) {
    PGL pgl = image.beginPGL();
    ByteBuffer buffer = ByteBuffer.allocateDirect(1 * 1 * Integer.SIZE / 8);

    pgl.readPixels(x, y, 1, 1, PGL.RGBA, PGL.UNSIGNED_BYTE, buffer); 

    // get the first three bytes
    int r = buffer.get() & 0xFF;
    int g = buffer.get() & 0xFF;
    int b = buffer.get() & 0xFF;
    buffer.clear();
    image.endPGL();
    return p.color(r, g, b);
}
 
Example #15
Source File: DepthOfField_Demo.java    From PixelFlow with MIT License 5 votes vote down vote up
public void displayScene(PGraphics3D canvas){
  // lights
  canvas.directionalLight(255, 255, 255, 200,600,400);
  canvas.directionalLight(255, 255, 255, -200,-600,-400);
  canvas.ambientLight(64, 64, 64);
  
  if(canvas == geombuffer.pg_geom){
    canvas.background(255, 255);
    canvas.pgl.clearColor(1, 1, 1, 6000);
    canvas.pgl.clear(PGL.COLOR_BUFFER_BIT);
  }
  

  sceneShape(canvas);
}
 
Example #16
Source File: PointCloud.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initPointCloud() {
        PGL pgl = ((PGraphicsOpenGL) parentApplet.g).pgl;

        // TODO: lookt at the shaders... 
        myShader = parentApplet.loadShader(PointCloud.class.getResource("points.frag").toString(),
                PointCloud.class.getResource("points.vert").toString());

        myShader.bind();
        shaderProgram = myShader.glProgram;
        vertLoc = pgl.getAttribLocation(shaderProgram, "vertex");
        colorsLoc = pgl.getAttribLocation(shaderProgram, "color");
        transformLoc = pgl.getUniformLocation(shaderProgram, "transform");

        myShader.unbind();

//         System.out.println("Shader program " + shaderProgram + " vertex loc " + vertLoc + " transform loc " + transformLoc + " colors " + colorsLoc);
        // Allocate the buffer in central memory (native),  then java, then OpenGL 
        // Native memory         
        int byteSize = nbPoints * 4 * 4; // 4 : SizeOf Float   -> ? SIZEOF_FLOAT
        verticesNative = ByteBuffer.allocateDirect(byteSize).order(ByteOrder.nativeOrder()).
                asFloatBuffer();
        colorsNative = ByteBuffer.allocateDirect(byteSize).order(ByteOrder.nativeOrder()).asIntBuffer();

        // Java memory 
        verticesJava = new float[nbPoints * 4];
        colorsJava = new int[nbPoints];

//        System.out.println("Buffer vertex object: " + glVertBuff);
        // unbind the buffer.
        pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
        
        // Generate a buffer color data and color. 
        IntBuffer intBuffer = IntBuffer.allocate(2);
        pgl.genBuffers(2, intBuffer);
        vertexBuffer = intBuffer.get(0);
        colorBuffer = intBuffer.get(1);
        
    }
 
Example #17
Source File: DwShadowMap.java    From PixelFlow with MIT License 5 votes vote down vote up
public void update(){
    pg_shadowmap.beginDraw();
    // saves quite some time compared to background(0xFFFFFFFF);
    pg_shadowmap.pgl.clearColor(1, 1, 1, 1);
    pg_shadowmap.pgl.clearDepth(1);
    pg_shadowmap.pgl.clear(PGL.COLOR_BUFFER_BIT | PGL.DEPTH_BUFFER_BIT);
    
//  pg_shadowmap.background(0xFFFFFFFF);
    pg_shadowmap.blendMode(PConstants.REPLACE);
    pg_shadowmap.noStroke();
    pg_shadowmap.applyMatrix(mat_scene_bounds);
    pg_shadowmap.shader(shader_shadow);
    scene_display.display(pg_shadowmap);
    pg_shadowmap.endDraw();
  }
 
Example #18
Source File: DwUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public void generateMipMaps(PGraphicsOpenGL pg){
    Texture tex = pg.getTexture();
    if(!tex.available()){
      System.out.println("ERROR DwGLTextureUtils.generateMipMaps: PGraphicsOpenGL texture not available.");
      return;
    }

    PGL pgl = pg.beginPGL();
    pgl.bindTexture   (tex.glTarget, tex.glName);
    pgl.texParameteri (tex.glTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
//    pgl.texParameteri (tex.glTarget, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
    pgl.generateMipmap(tex.glTarget);
    pgl.bindTexture   (tex.glTarget, 0);
    pg.endPGL();
  }
 
Example #19
Source File: DwUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
/**
 * When chaning multiple parameters, its better to use this source-code directly.
 * 
 * @param pg
 * @param pname
 * @param param
 */
static public void changeTextureParam(PGraphicsOpenGL pg, int pname, int param){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureParam: PGraphicsOpenGL texture not available.");
    return;
  }
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName);
  pgl.texParameteri(tex.glTarget, pname, param);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
}
 
Example #20
Source File: DwUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public void changeTextureFilter(PGraphicsOpenGL pg, int min_filter, int mag_filter){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureFilter: PGraphicsOpenGL texture not available.");
    return;
  }
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MIN_FILTER, min_filter);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_MAG_FILTER, mag_filter);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
}
 
Example #21
Source File: DwUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public void changeTextureWrap(PGraphicsOpenGL pg, int wrap){
  Texture tex = pg.getTexture();
  if(!tex.available()){
    System.out.println("ERROR DwGLTextureUtils.changeTextureWrap: PGraphicsOpenGL texture not available.");
    return;
  }
  PGL pgl = pg.beginPGL();
  pgl.bindTexture  (tex.glTarget, tex.glName); 
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_WRAP_S, wrap);
  pgl.texParameteri(tex.glTarget, GL2ES2.GL_TEXTURE_WRAP_T, wrap);
  pgl.bindTexture  (tex.glTarget, 0);
  pg.endPGL();
}
 
Example #22
Source File: GBAA.java    From PixelFlow with MIT License 4 votes vote down vote up
public void apply(PGraphics3D src, PGraphics3D dst){
  
  int w = src.width;
  int h = src.height;
  
  resize(w, h);
  
  // 1) GeometryBuffer Pass
  pg_edges.beginDraw();
  DwUtils.copyMatrices(src, pg_edges);
  pg_edges.blendMode(PConstants.REPLACE);
  pg_edges.pgl.clearColor(0.5f, 0.5f, 0.5f, 0.5f);
  pg_edges.pgl.clear(PGL.COLOR_BUFFER_BIT);
  shader_edges.set("wh", (float)w, (float)h);
  pg_edges.shader(shader_edges);
  pg_edges.noStroke();
  scene_display.display(pg_edges);
  pg_edges.endDraw();
  

  
  // 2) AA Pass
  if(src == dst){
    System.out.println("GBAA error: read-write race");
    return;
  }
  
  Texture tex_src = src.getTexture(); if(!tex_src.available())  return;
  Texture tex_dst = dst.getTexture(); if(!tex_dst.available())  return;
  Texture tex_edges = pg_edges.getTexture(); if(!tex_edges.available())  return;

  context.begin();
  context.beginDraw(dst);
  shader_gbaa.begin();
  shader_gbaa.uniform2f     ("wh_rcp" , 1f/w, 1f/h);
  shader_gbaa.uniformTexture("tex_src", tex_src.glName);
  shader_gbaa.uniformTexture("tex_edges", tex_edges.glName);
  shader_gbaa.drawFullScreenQuad();
  shader_gbaa.end();
  context.endDraw();
  context.end("GBAA.apply");

}
 
Example #23
Source File: DelegatedGraphics.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PGL beginPGL() {
    return currentGraphics.beginPGL();
}
 
Example #24
Source File: PointCloudColorTest.java    From KinectPV2 with MIT License 4 votes vote down vote up
public void setup() {

		  kinect = new KinectPV2(this);

		  kinect.enableDepthImg(true);
		  kinect.enableColorImg(true);
		  kinect.enableColorPointCloud(true);
		
		  kinect.init();
		 
		  sh = loadShader("frag.glsl", "vert.glsl");
		  
		  PGL pgl = beginPGL();

		  // allocate buffer big enough to get all VBO ids back
		  IntBuffer intBuffer = IntBuffer.allocate(2);
		  pgl.genBuffers(2, intBuffer);

		  //memory location of the VBO
		  vertexVboId = intBuffer.get(0);
		  colorVboId = intBuffer.get(1);

		  endPGL();
	}
 
Example #25
Source File: PointCloudColorTest.java    From KinectPV2 with MIT License 4 votes vote down vote up
public void draw() {

		  background(0);

		  image(kinect.getColorImage(), 0, 0, 320, 240);


		  // The geometric transformations will be automatically passed to the shader
		  pushMatrix();
		  translate(width / 2, height / 2, zval);
		  scale(scaleVal, -1 * scaleVal, scaleVal);
		  rotate(a, 0.0f, 1.0f, 0.0f);

		  //render to the openGL object
		  pgl = beginPGL();
		  sh.bind();


		  //obtain the point cloud positions
		  FloatBuffer pointCloudBuffer = kinect.getPointCloudColorPos();

		  //get the color for each point of the cloud Points
		  FloatBuffer colorBuffer      = kinect.getColorChannelBuffer();

		  //send the the vertex positions (point cloud) and color down the render pipeline
		  //positions are render in the vertex shader, and color in the fragment shader
		  vertLoc = pgl.getAttribLocation(sh.glProgram, "vertex");
		  pgl.enableVertexAttribArray(vertLoc);
		  
		  
		  //enable drawing to the vertex and color buffer
		  colorLoc = pgl.getAttribLocation(sh.glProgram, "color");
		  pgl.enableVertexAttribArray(colorLoc);

		  int vertData = kinect.WIDTHColor * kinect.HEIGHTColor * 3;

		  //vertex
		  {
		    pgl.bindBuffer(PGL.ARRAY_BUFFER, vertexVboId);
		    // fill VBO with data
		    pgl.bufferData(PGL.ARRAY_BUFFER, Float.BYTES * vertData, pointCloudBuffer, PGL.DYNAMIC_DRAW);
		    // associate currently bound VBO with shader attribute
		    pgl.vertexAttribPointer(vertLoc, 3, PGL.FLOAT, false, Float.BYTES * 3, 0);
		  }

		  // color
		  {
		    pgl.bindBuffer(PGL.ARRAY_BUFFER, colorVboId);
		    // fill VBO with data
		    pgl.bufferData(PGL.ARRAY_BUFFER, Float.BYTES * vertData, colorBuffer, PGL.DYNAMIC_DRAW);
		    // associate currently bound VBO with shader attribute
		    pgl.vertexAttribPointer(colorLoc, 3, PGL.FLOAT, false, Float.BYTES * 3, 0);
		  }

		  // unbind VBOs
		  pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);

		  //draw the point cloud as a set of points
		  pgl.drawArrays(PGL.POINTS, 0, vertData);

		  //disable drawing
		  pgl.disableVertexAttribArray(vertLoc);
		  pgl.disableVertexAttribArray(colorLoc);

		  //close the shader
		  sh.unbind();
		  //close the openGL object
		  endPGL();

		  popMatrix();

		  stroke(255, 0, 0);
		  text(frameRate, 50, height- 50);
	}
 
Example #26
Source File: Demo_KinectV2_ParticleDepth.java    From haxademic with MIT License 4 votes vote down vote up
protected void firstFrame() {
	  kinect = new KinectPV2(this);

	  kinect.enableDepthImg(true);

	  kinect.enablePointCloud(true);

	  kinect.setLowThresholdPC(minD);
	  kinect.setHighThresholdPC(maxD);

	  kinect.init();

	  sh = loadShader(FileUtil.getPath("haxademic/shaders/vertex/kinect-points-frag.glsl"), FileUtil.getPath("haxademic/shaders/vertex/kinect-points-vert.glsl"));

	  PGL pgl = beginPGL();

	  IntBuffer intBuffer = IntBuffer.allocate(1);
	  pgl.genBuffers(1, intBuffer);

	  //memory location of the VBO
	  vertexVboId = intBuffer.get(0);

	  endPGL();
}
 
Example #27
Source File: Demo_KinectV2_ParticleDepth.java    From haxademic with MIT License 4 votes vote down vote up
protected void drawApp() {
	p.background(0);
	
	  //draw the depth capture images
	  image(kinect.getDepthImage(), 0, 0, 320, 240);
	  image(kinect.getPointCloudDepthImage(), 320, 0, 320, 240);

	  //translate the scene to the center
	  translate(width / 2, height / 2, zval);
	  scale(scaleVal, -1 * scaleVal, scaleVal);
	  rotate(a, 0.0f, 1.0f, 0.0f);

	  // Threahold of the point Cloud.
	  kinect.setLowThresholdPC(minD);
	  kinect.setHighThresholdPC(maxD);

	  //get the points in 3d space
	  FloatBuffer pointCloudBuffer = kinect.getPointCloudDepthPos();

	  // obtain XYZ the values of the point cloud
	  /*
	  stroke(0, 0, 0);
	  for(int i = 0; i < kinect.WIDTHDepth * kinect.HEIGHTDepth; i+=3){
	      float x = pointCloudBuffer.get(i*3 + 0) * scaleDepthPoint;
	      float y = pointCloudBuffer.get(i*3 + 1) * scaleDepthPoint;
	      float z = pointCloudBuffer.get(i*3 + 2) * scaleDepthPoint;
	      
	   
	      point(x, y, z);
	   }
	   */

	  //begin openGL calls and bind the shader
	  pgl = beginPGL();
	  sh.bind();

	  //obtain the vertex location in the shaders.
	  //useful to know what shader to use when drawing the vertex positions
	  vertLoc = pgl.getAttribLocation(sh.glProgram, "vertex");

	  pgl.enableVertexAttribArray(vertLoc);

	  //data size times 3 for each XYZ coordinate
	  int vertData = KinectPV2.WIDTHDepth * KinectPV2.HEIGHTDepth * 3;

	  //bind vertex positions to the VBO
	  {
	    pgl.bindBuffer(PGL.ARRAY_BUFFER, vertexVboId);
	    // fill VBO with data
	    pgl.bufferData(PGL.ARRAY_BUFFER,   Float.BYTES * vertData, pointCloudBuffer, PGL.DYNAMIC_DRAW);
	    // associate currently bound VBO with shader attribute
	    pgl.vertexAttribPointer(vertLoc, 3, PGL.FLOAT, false,  Float.BYTES * 3, 0 );
	  }
	  
	   // unbind VBOs
	  pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);

	  //draw the point buffer as a set of POINTS
	  pgl.drawArrays(PGL.POINTS, 0, vertData);

	  //disable the vertex positions
	  pgl.disableVertexAttribArray(vertLoc);

	  //finish drawing
	  sh.unbind();
	  endPGL();


	  stroke(255, 0, 0);
	  text(frameRate, 50, height - 50);
}
 
Example #28
Source File: PGraphics32.java    From haxademic with MIT License 4 votes vote down vote up
protected PGL createPGL(PGraphicsOpenGL pg) {
	return new PJOGL32(pg);
}
 
Example #29
Source File: PointCloud.java    From PapARt with GNU Lesser General Public License v3.0 2 votes vote down vote up
private void drawPoints(PGraphicsOpenGL g) {

        // get cache object using g.
        PGL pgl = g.pgl;

        // Use the shader program
        myShader.bind();
        // load the transformation matrix
        pgl.uniformMatrix4fv(transformLoc, 1, false, toOpenGL(g.projmodelview));
        
   
        
        // load the buffer 
        pgl.bindBuffer(GL2.GL_ARRAY_BUFFER, vertexBuffer);
        // set the data 
        // TODO: not sure about the size... 
        verticesNative.position(0); // start at 0
        pgl.bufferData(ARRAY_BUFFER, nbPoints * 4 * SIZEOF_FLOAT, verticesNative, STREAM_DRAW);
        pgl.vertexAttribPointer(vertLoc, 4, PGL.FLOAT, false, 4 * SIZEOF_FLOAT, 0);
        
        // enable the vertice array
        pgl.enableVertexAttribArray(vertLoc);
        
        


        // Making sure that no VBO is bound at this point.
        pgl.bindBuffer(GL2.GL_ARRAY_BUFFER, colorBuffer);
        colorsNative.position(0); // start at 0
        pgl.bufferData(ARRAY_BUFFER, nbPoints * SIZEOF_BYTE * 4 , colorsNative, STREAM_DRAW);
        
        pgl.vertexAttribPointer(colorsLoc, 4, PGL.UNSIGNED_BYTE, false, 4 * SIZEOF_BYTE, 0);
//        pgl.vertexAttribPointer(colorsLoc, 4, PGL.UNSIGNED_INT, false, 4 * SIZEOF_INT, colorsNative);
        
        // enable the color array
        pgl.enableVertexAttribArray(colorsLoc);
        
        // Draw the array nbToDraw elements.
        pgl.drawArrays(vertexMode, 0, nbVertices);

        pgl.disableVertexAttribArray(vertLoc);
        pgl.disableVertexAttribArray(colorsLoc);

        myShader.unbind();

        // stop shader
        pgl.useProgram(0);

    }