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 & HelpOpenGL and 3D Libraries › transparency problems, using gestalt-library
Page Index Toggle Pages: 1
transparency problems, using gestalt-library (Read 707 times)
transparency problems, using gestalt-library
Mar 15th, 2008, 12:08pm
 
hello out there.

I want to poject my processing sketch into a cupola. I'm using the "gestalt" library to map my sketch as a texture onto a mesh to do deformations. if I use background() in my draw() everything works fine. but to get a smoother image I want to use a rect filled with a transparent color instead of background.
that causes very strange things. i guess its a problem of the depth buffer.
older "layers" seem to rotate away? the objects of my sketch repeated themselfes a strange way depending on the deformations I aplied to the mesh.

any ideas?

here I give you an example patch.
you can select each point with your mouse and change positions with the keys UP,DOWN,LEFT,RIGHT. after that you will see the problem, a distortion like water color effects.

thanks, stefan
Re: transparency problems, using gestalt-library
Reply #1 - Mar 15th, 2008, 12:17pm
 
this is my code part 1



import gestalt.candidates.JoglFrameBufferCopy;
import gestalt.shape.Disk;
import gestalt.shape.Material;
import gestalt.p5.GestaltPlugIn;
import gestalt.shape.material.TexturePlugin;
import gestalt.texture.bitmap.IntegerBitmap;
import gestalt.util.CameraMover;
import processing.opengl.*;
import javax.media.opengl.GL;
import gestalt.context.GLContext;
import gestalt.impl.jogl.context.JoglGLContext;
import gestalt.shape.AbstractDrawable;
import processing.core.PApplet;


public class UsingCustomDrawables
extends PApplet {

 private GestaltPlugIn gestalt;
 private TexturePlugin myTexture;
 private MyDrawable _myModel;
 private JoglFrameBufferCopy myFrameBufferCopy;

 int gridSizeX=10;
 int gridSizeY=10;

 Punkt[] punkt = new Punkt[0];
 boolean POINT_ACTIVE = false;
 boolean LINKS=false;
 boolean RECHTS=false;
 boolean OBEN=false;
 boolean UNTEN=false;

 public void setup() {
   size(600, 600, OPENGL);
   hint(DISABLE_DEPTH_TEST);

   for(int row=0; row<gridSizeY; row++){
     for(int col=0; col<gridSizeX; col++){
       float stepX=width/(gridSizeX);
       float stepY=height/(gridSizeY);
       float x=stepX*col-width/2;
       float y=stepY*row-height/2;
       float z=0;
       float u=col*0.1;
       float v=(gridSizeY-row)*0.1;
       punkt = (Punkt[]) append (punkt, new Punkt(row,col,x,y,z,u,v));
     }
   }

   gestalt = new GestaltPlugIn(this,false);
   gestalt.framesetup().depthbufferclearing = false;
   gestalt.framesetup().colorbufferclearing = false;
   /* create an empty dummy bitmap */
   myTexture = gestalt.drawablefactory().texture();
   myTexture.load(IntegerBitmap.getDefaultImageBitmap(width, height));

   /* create drawable */
   _myModel = new MyDrawable();
   _myModel.material.addPlugin(myTexture);
   gestalt.bin(Gestalt.BIN_2D_FOREGROUND).add(_myModel);

   /* camera */
   gestalt.camera().setMode(Gestalt.CAMERA_MODE_LOOK_AT);
   gestalt.camera().position().set(150, 100, 450);

   /* light */
   gestalt.light().enable = true;
   gestalt.light().position = gestalt.camera().position();

   /* create a screengrabber */
   myFrameBufferCopy = new JoglFrameBufferCopy(myTexture);
   myFrameBufferCopy.backgroundcolor.set(1f);
   myFrameBufferCopy.width = width;
   myFrameBufferCopy.height = height;
   gestalt.bin(Gestalt.BIN_3D_SETUP).add(myFrameBufferCopy);
 }

 public void draw() {
     
   for(int i=0;i<punkt.length;i++) punkt[i].draw();
   LINKS=false;RECHTS=false;OBEN=false;UNTEN=false;
   
   /* clear screen */
   //background(255);    

   /*my transparent background*/
   fill(255,10);
   noStroke();
   rect(0,0,width,height);

   /* draw processing stuff */    
   fill(255,0,0);
   stroke(0, 255);
   strokeWeight(1);
   ellipse(mouseX, mouseY, 10,10);
   noFill();
   strokeWeight(5);
   stroke(255,0,0);
   ellipse(width/2,height/2,400,400);


   // change wrap mode //
   if (gestalt.event().mouseDown) {
     if (gestalt.event().mouseButton == Gestalt.MOUSEBUTTON_LEFT) {
       gestalt.enable();
     } else gestalt.disable();      
   }
 }

 void mouseReleased(){
   POINT_ACTIVE=true;
 }

 void keyReleased(){
   switch(keyCode) {
   case LEFT:
     LINKS=true;
     break;
   case RIGHT:
     RECHTS=true;
     break;
   case UP:
     OBEN=true;
     break;
   case DOWN:
     UNTEN=true;
     break;
   case CONTROL:
    for(int i=0;i<punkt.length;i++) punkt[i].aktive=false;
    break;
   case ALT:
    for(int i=0;i<punkt.length;i++) {punkt[i].x=punkt[i].xAlt; punkt[i].y=punkt[i].yAlt;}
    break;
   }    
 }
Re: transparency problems, using gestalt-library
Reply #2 - Mar 15th, 2008, 12:18pm
 
this is my code part 2



 class Punkt{  
   int row, col;
   float x,y,z,u,v,xAlt,yAlt;  
   boolean aktive=false;
   Punkt(int row, int col, float x, float y, float z, float u, float v){
     this.row = row;
     this.col = col;
     this.x = x;
     this.y = y;
     this.z = z;
     this.u = u;
     this.v = v;
     xAlt=x;
     yAlt=y;
   }
   void draw(){
     noStroke();
     fill(0);
     ellipse(x+width/2,y+height/2,3,3);

     if (POINT_ACTIVE && mouseX > x+width/2-10 && mouseX < x+width/2+10 && mouseY > y+height/2-10 && mouseY < y+height/2+10){
       aktive=!aktive;
       POINT_ACTIVE=false;
     }
     noStroke();
     fill(0);
     if (aktive) {
       if (LINKS) x-=1;
       if (RECHTS) x+=1;
       if (OBEN) y+=1;
       if (UNTEN) y-=1;
       ellipse(x+width/2,y+height/2,10,10);
     }
   }
 }

 import java.io.Serializable;
 import java.util.ArrayList;
 import gestalt.Gestalt;
 import gestalt.context.GLContext;
 import gestalt.render.Drawable;
 import gestalt.impl.jogl.shape.JoglMaterial;
 import mathematik.TransformMatrix4f;
 import mathematik.Vector3f;

 import gestalt.shape.material.TexturePlugin;

 private class MyDrawable

   extends AbstractDrawable {

   public JoglMaterial material;

   public MyDrawable() {
     material = new JoglMaterial();        
   }

   public void draw(GLContext theRenderContext) {
     final GL gl = ( (JoglGLContext) theRenderContext).gl;

     material.begin(theRenderContext);


     for(int i=0; i < punkt.length; i++) {
       if (punkt[i].row != gridSizeY-1 && punkt[i].col != gridSizeX-1){

         gl.glBegin(GL.GL_QUADS);

         gl.glColor4f(1f,1f,1f,1f);

         gl.glTexCoord2f(punkt[i].u, punkt[i].v);          
         gl.glVertex3f(punkt[i].x,punkt[i].y,punkt[i].z);

         gl.glTexCoord2f(punkt[i+1].u, punkt[i+1].v);
         gl.glVertex3f(punkt[i+1].x,punkt[i+1].y,punkt[i+1].z);

         gl.glTexCoord2f(punkt[i+gridSizeX+1].u, punkt[i+gridSizeX+1].v);
         gl.glVertex3f(punkt[i+gridSizeX+1].x,punkt[i+gridSizeX+1].y,punkt[i+gridSizeX+1].z);

         gl.glTexCoord2f(punkt[i+gridSizeX].u, punkt[i+gridSizeX].v);
         gl.glVertex3f(punkt[i+gridSizeX].x,punkt[i+gridSizeX].y,punkt[i+gridSizeX].z);

         gl.glEnd();
       }

     }

     material.end(theRenderContext);  
   }
 }


 public static void main(String[] args) {
   new UsingCustomDrawables().init();
 }
}
Page Index Toggle Pages: 1