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 › bindTexture(PImage) error: method not visible
Page Index Toggle Pages: 1
bindTexture(PImage) error: method not visible (Read 6343 times)
bindTexture(PImage) error: method not visible
Nov 27th, 2008, 3:00am
 
Hello.
Im converting a sketch from version 0.148 to 1.0

I keep having this error:
The method bindTexture(PImage) from the type PGraphicsOpenGL is not visible.

In particular this relate to the openGL call bindTexture().

Does anyone know how to fix it?
Could someone in addition explain what's changed in how Processing deals with openGL methods (from v 0.148 to 1.0).


THANKS
Re: bindTexture(PImage) error: method not visible
Reply #1 - Nov 27th, 2008, 11:14am
 
Could you show your code? You really shouldn't be calling bindTexture yourself.

If you're trying to do pure GL stuff, then it should be gl.glBindTexture at the very least that you're calling.
Re: bindTexture(PImage) error: method not visible
Reply #2 - Nov 27th, 2008, 11:22am
 
The code is too long to post...
But there's nothing fancy around the bindTexture call.

Basically I initiate an openGl obejct:
    PGraphicsOpenGL pgl;
and a PImage object:
   PImage textureImg;
and then:
   pgl.bindTexture( textureImg );

I tried to replace it as you suggested:
   pgl.glBindTexture( textureImg );

In this way it doesn't find any glBindTexture function:
   The function glBindTexture ( PImage ) does not exist


I think the problem is with a new way Processing handles the openGL class... as the error with pgl.binTexture ( textureImg) is that the method is no longer visible.
The method was visible in Processing 0.148 but it is not in Processing 1.0

THANKS
Re: bindTexture(PImage) error: method not visible
Reply #3 - Nov 27th, 2008, 1:42pm
 
If it was visible, I think it might have only been that way by accident.

If you're not doing pure OpenGL calls, you don't need to do texture binding, just doing pgl.texture(myPImage); will cause the behind the scenes stuff to do what it needs to with the texture, including binding etc.
Re: bindTexture(PImage) error: method not visible
Reply #4 - Nov 27th, 2008, 1:50pm
 
Im using openGL display lists and shaders.
Googling I founf that Robert at flight404 used the same code I'm using.

citing from his website:

Code:

/*
The emitter is just an object that follows the cursor and
can spawn new particle objects. It would be easier to just make
the location vector match the cursor position but I have opted
to use a velocity vector because later I will be allowing for
multiple emitters.
*/

class Emitter{
 Vec3D loc;
 Vec3D vel;
 Vec3D velToMouse;

 color myColor;

 ArrayList particles;

 Emitter(  ){
   loc        = new Vec3D();
   vel        = new Vec3D();
   velToMouse = new Vec3D();

   myColor    = color( 1, 1, 1 );

   particles  = new ArrayList();
 }

 void exist(){
   setVelToMouse();
   findVelocity();
   setPosition();
   pgl.beginGL();

   if( ALLOWTRAILS ){
     gl.glBegin(gl.GL_QUADS);
     renderTrails();
     gl.glEnd();
   }

/*********************************************/
   pgl.bindTexture( particleImg );
/*********************************************/

   shader.startShader();
   gl.glBegin(gl.GL_QUADS);
   iterateList();
   gl.glEnd();
   shader.endShader();

/*********************************************/
   pgl.bindTexture( emitterImg );
/*********************************************/

   shader.startShader();
   gl.glBegin(gl.GL_QUADS);
   render();
   gl.glEnd();
   shader.endShader();

   pgl.endGL();

 }

 void setVelToMouse(){
   velToMouse.set( mouseX - loc.x, mouseY - loc.y, 0 );
 }

 void findVelocity(){
   vel.interpolateToSelf( velToMouse, .35 );
 }

 void setPosition(){
   loc.addSelf( vel );

   if( ALLOWFLOOR ){
     if( loc.y > floorLevel ){
       loc.y = floorLevel;
       vel.y = 0;
     }
   }
 }

 void iterateList(){
   for( Iterator it = particles.iterator(); it.hasNext(); ){
     Particle p = (Particle) it.next();
     if( !p.ISDEAD ){
       p.exist();
     }
     else {
       it.remove();
     }
   }
 }


 void renderTrails(){
   for( Iterator it = particles.iterator(); it.hasNext(); ){
     Particle p = (Particle) it.next();
     p.renderTrails();
   }
 }

 void render(){
   gl.glColor3f(red(myColor), green(myColor), blue(myColor));
   gl.glTexCoord4f( loc.x, loc.y, loc.z,  75 );
   gl.glCallList( squareList );
 }

 void addParticles( int _amt ){
   for( int i=0; i<_amt; i++ ){
     particles.add( new Particle( loc, vel ) );
   }
 }
}



If I apply the pgl.texture() method there are no errors, but the display is empty.
Re: bindTexture(PImage) error: method not visible
Reply #5 - Nov 28th, 2008, 8:20pm
 
That breaks all of my OpenGL code as well.  I was relying on bindTexture() to avoid dealing with converting PImages to OpenGL textures by hand.

All the work to generate the texture is done really well inside the ImageCash class (subclass of PGraphicsOpenGL).

Unfortunately that class is also protected. It seems silly to have to redo it!  

Any chance we can get bindTexture() back, or some way to access a PImage's ImageCash object?
Re: bindTexture(PImage) error: method not visible
Reply #6 - Nov 28th, 2008, 10:04pm
 
I've just been working through this exact thing, and have (I think) got to a solution... Bear in mind that I am pretty much a complete Processing/Java/OpenGL newbie so this is probably doing something horrible Smiley

Instead of
Code:

pgl.bindTexture( images.particle );


I used this:

Code:

glParticle.bind();
glParticle.enable();
// rendering goes here
glParticle.disable();


where images.glParticle is
Code:

Texture glParticle;

glParticle = TextureIO.newTexture(new File(dataPath("particle.png")),
true);
Re: bindTexture(PImage) error: method not visible
Reply #7 - Nov 28th, 2008, 10:47pm
 
Thanks! That's a good solution.

I preferred relying on the Processing code rather than JOGL (for simplicity) but for the time being that'll do just fine.
Re: bindTexture(PImage) error: method not visible
Reply #8 - Nov 28th, 2008, 11:25pm
 
namke wrote on Nov 28th, 2008, 10:04pm:
I've just been working through this exact thing, and have (I think) got to a solution...


could you explain it better

thanks Smiley
Re: bindTexture(PImage) error: method not visible
Reply #9 - Nov 29th, 2008, 12:13am
 
I can give it a shot:

The Texture object he refers to is part of JOGL's utilities.

Here's a full example (just add a "texture.png" or whatever to the data folder...)

Quote:
import processing.opengl.*;
import javax.media.opengl.*;
import com.sun.opengl.util.texture.*; // <--- you need this now

Texture tex;

void setup() {
 size(100, 100, OPENGL);
 
 try {
   tex = TextureIO.newTexture(new File(dataPath("texture.png")), true);
 }
 catch (IOException e) {    
   println("Texture file is missing");
   exit();  // or handle it some other way
 }  
}

void draw() {
 PGraphicsOpenGL pgl = (PGraphicsOpenGL)g;
 GL gl = pgl.beginGL();  
 gl.glEnable(GL.GL_TEXTURE_2D);
 
 tex.enable();
 
 // draw stuff
 gl.glTranslatef(25, 25, 0);
 gl.glBegin(GL.GL_TRIANGLE_STRIP);
 gl.glTexCoord2f(1, 1);    gl.glVertex2f( 0, 0);
 gl.glTexCoord2f(0, 1);    gl.glVertex2f(50, 0);
 gl.glTexCoord2f(1, 0);    gl.glVertex2f( 0, 50);
 gl.glTexCoord2f(0, 0);    gl.glVertex2f(50, 50);
 gl.glEnd();
 
 tex.disable();
 
 pgl.endGL();
}

Re: bindTexture(PImage) error: method not visible
Reply #10 - Nov 29th, 2008, 12:25am
 
Actually, I have this slightly wrong.. The example will work, but I should be using tex.bind() too (lets say if I had more than one texture).

Here are the OpenGL equivalents of these calls:

Quote:
tex.enable() -->  gl.glEnable( <target> );
tex.disable() --> gl.glDisable( <target> );
tex.bind() --> gl.glBindTexture( <target>, <textureId>);


See this for more details:
http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/texture/Texture.html
Re: bindTexture(PImage) error: method not visible
Reply #11 - Dec 29th, 2008, 3:14pm
 
Hello, thanks for the help.

I've tryed to "update" the flight404 code but I'm sure there are wrong things. Or is it correct?

I'm also wondering how to get transparency of a png. I've tryed without success the method discussed in these topics:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1229176394

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1211845881

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1199399046;start=15

any tips?


Code:


Texture particleImg;
Texture emitterImg;

try {
 particleImg = TextureIO.newTexture(new File(dataPath("particle.png")), true);
 emitterImg = TextureIO.newTexture(new File(dataPath("emitter.png")), true);
}
catch (IOException e) {    
 println("Texture file is missing");
 exit();  // or handle it some other way
}  


..


   //pgl.bindTexture( particleImg );

   particleImg.enable();
   particleImg.bind();


   shader.startShader();
   gl.glBegin(gl.GL_QUADS);
gl.glEnable(GL.GL_TEXTURE_2D);
   iterateList();
   gl.glEnd();
   shader.endShader();


   particleImg.disable();



   emitterImg.enable();
   emitterImg.bind();


   shader.startShader();
   gl.glBegin(gl.GL_QUADS);
gl.glEnable(GL.GL_TEXTURE_2D);
   render();
   gl.glEnd();
   shader.endShader();


   emitterImg.disable();

   pgl.endGL();
Re: bindTexture(PImage) error: method not visible
Reply #12 - Apr 23rd, 2009, 2:33am
 
I've managed to get this working.

Here is the revised code for the entire 'emitter.pde' file:
Code:

import com.sun.opengl.util.texture.*;

class Emitter{
 Vec3D loc;
 Vec3D vel;
 Vec3D velToMouse;
 float radius;

 Texture coronaTex;
 Texture emitterTex;
 Texture particleTex;
 Texture reflectionTex;

 color myColor;

 ArrayList particles;
 ArrayList nebulae;

 Emitter(  ){

   try {
     coronaTex = TextureIO.newTexture(new File(dataPath("corona.png")), true);
     emitterTex = TextureIO.newTexture(new File(dataPath("emitter.png")), true);
     particleTex = TextureIO.newTexture(new File(dataPath("particle.png")), true);
     reflectionTex = TextureIO.newTexture(new File(dataPath("reflection.png")), true);
   }
   catch (IOException e) {    
     println("Texture file is missing");
     exit();  // or handle it some other way
   }  

   loc        = new Vec3D();
   vel        = new Vec3D();
   velToMouse = new Vec3D();

   radius     = 100;

   myColor    = color( 1, 1, 1 );

   particles  = new ArrayList();
   nebulae    = new ArrayList();
 }

 void exist(){
   findVelocity();
   setPosition();
   iterateListExist();
   render();

   gl.glDisable( GL.GL_TEXTURE_2D );

   if( ALLOWTRAILS )
     iterateListRenderTrails();
 }

 void findVelocity(){
   Vec3D dirToMouse = new Vec3D( mouse.loc.sub( loc ).scale( .15 ) );
   vel.set( dirToMouse );
 }

 void setPosition(){
   loc.addSelf( vel );

   if( ALLOWFLOOR ){
     if( loc.y > floorLevel ){
       loc.y = floorLevel;
       vel.y = 0;
     }
   }
 }

 void iterateListExist(){
   gl.glEnable( GL.GL_TEXTURE_2D );


   int mylength = particles.size();
   for( int i=mylength-1; i>=0; i-- ){
     Particle p = ( Particle )particles.get(i);
     if( p.ISSPLIT )
       addParticles( p );

     if ( !p.ISDEAD ){
       //        pgl.bindTexture( images.particle );
       particleTex.bind();
       particleTex.enable();
       p.exist();
       particleTex.disable();

     }
     else {
       particles.set( i, particles.get( particles.size() - 1 ) );
       particles.remove( particles.size() - 1 );
     }
   }

   if( ALLOWFLOOR ){
     //      pgl.bindTexture( images.reflection );
     reflectionTex.bind();
     reflectionTex.enable();
     for( Iterator it = particles.iterator(); it.hasNext(); ){
       Particle p = (Particle) it.next();
       p.renderReflection();
     }
     reflectionTex.disable();
   }

   //    pgl.bindTexture( images.corona );
   coronaTex.bind();
   coronaTex.enable();
   for( Iterator it = nebulae.iterator(); it.hasNext(); ){
     Nebula n = (Nebula) it.next();
     if( !n.ISDEAD ){
       n.exist();
     }
     else {
       it.remove();
     }
   }
   coronaTex.disable();
 }


 void render(){
   //    pgl.bindTexture( images.emitter );
   emitterTex.bind();
   emitterTex.enable();
   renderImage( loc, radius, myColor, 1.0 );
   emitterTex.enable();

   if( ALLOWNEBULA ){
     nebulae.add( new Nebula( loc, 15.0, true ) );
     nebulae.add( new Nebula( loc, 45.0, true ) );
   }


   if( ALLOWFLOOR ){
     //      pgl.bindTexture( images.reflection );
     reflectionTex.bind();
     reflectionTex.enable();
     renderReflection();
     reflectionTex.disable();
   }
 }

 void renderReflection(){
   float altitude           = floorLevel - loc.y;
   float reflectMaxAltitude = 300.0;
   float yPer               = 1.0 - altitude/reflectMaxAltitude;

   if( yPer > .05 )
     renderImageOnFloor( new Vec3D( loc.x, floorLevel, loc.z ), radius * 10.0, color( 0.5, 1.0, yPer*.25 ), yPer );

   if( mousePressed )
     renderImageOnFloor( new Vec3D( loc.x, floorLevel, loc.z ), radius + ( yPer + 1.0 ) * radius * random( 2.0, 3.5 ), color( 1.0, 0, 0 ), yPer );
 }

 void iterateListRenderTrails(){
   for( Iterator it = particles.iterator(); it.hasNext(); ){
     Particle p = (Particle) it.next();
     p.renderTrails();
   }
 }

 void addParticles( int _amt ){
   for( int i=0; i<_amt; i++ ){
     particles.add( new Particle( 1, loc, vel ) );
   }

   if( ALLOWNEBULA ){
     nebulae.add( new Nebula( loc, 40.0, false ) );
     nebulae.add( new Nebula( loc, 100.0, false ) );
   }
 }

 void addParticles( Particle _p ){
   // play with amt if you want to control how many particles spawn when splitting
   int amt = (int)( _p.radius * .15 );
   for( int i=0; i<amt; i++ ){
     particles.add( new Particle( _p.gen + 1, _p.loc[0], _p.vel ) );
     if( ALLOWNEBULA )
       nebulae.add( new Nebula( _p.loc[0], random( 5.0, 50.0 ), true ) );
   }
 }
}



Re: bindTexture(PImage) error: method not visible
Reply #13 - Jan 25th, 2010, 11:01am
 
That revised code doesn't work?
Page Index Toggle Pages: 1