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 › [FIXED] Unexpected texture behaviour
Page Index Toggle Pages: 1
[FIXED] Unexpected texture behaviour (Read 537 times)
[FIXED] Unexpected texture behaviour
Dec 5th, 2008, 11:39pm
 
Hello,

I was wondering if someone might be able to help me figure out what's going on here.

I'm just making a quad and texturing it - very simple.  Works fine until I rotate the quad then everything goes awry.

Try the following code (just replace the jpg with something else - anything will work but a grid gives you a clearer idea that bad things are happening).  See what happens when you comment out the rotation and then put it back again.

Ideas anyone?

Quote:
float cx, cy, wd, ht;

PGraphics pg;
PImage img;

void setup()
{
  size( 500, 500, P3D );
  pg = createGraphics( width, height, P3D );
  img = loadImage( "uvtemplate001-lg.jpg" );
  
  cx = width/2;
  cy = height/2;
  wd = 120.0f;
  ht = 120.0f;
}

void draw()
{
  pg.beginDraw();
  pg.background( 128, 32 );

  pg.translate( cx, cy, 0.0f );
  pg.rotateX( 45 );
      
  pg.textureMode( NORMALIZED );

  pg.beginShape(QUADS);
    pg.texture( img );
    pg.vertex( - wd, - ht, 0.0f, 0, 0 );
    pg.vertex(   wd, - ht, 0.0f, 1, 0 );
    pg.vertex(   wd,   ht, 0.0f, 1, 1 );
    pg.vertex( - wd,   ht, 0.0f, 0, 1 );
  pg.endShape();
    
  pg.endDraw();

  image( pg, 0, 0 );
}



NOTE: the graphics context makes no difference - if you did this without the pg. it still doesn't work...
Re: Unexpected texture behaviour
Reply #1 - Dec 6th, 2008, 12:56am
 
Actually, I'm pretty sure it's a bug in P3D - if I get more certain I'll add it to the bug tracker.  If you change P3D to OpenGL the problem goes away.
Re: Unexpected texture behaviour
Reply #2 - Dec 6th, 2008, 5:43pm
 
haven't tried your code but this sounds familiar

have you tried adding the hint ENABLE_ACCURATE_TEXTURES as mentioned in http://dev.processing.org/bugs/show_bug.cgi?id=103 ?

it's also visible in the cube rotate example:

http://processing.org/learning/3d/texture1.html
http://processing.org/learning/3d/texturecube.html
Re: Unexpected texture behaviour
Reply #3 - Dec 7th, 2008, 7:24am
 
Yeah, I saw that bug post - thanks for making me look at it harder.  I tried ENABLE_ACCURATE_TEXTURES, which broke the texturing, then found this:

http://dev.processing.org/bugs/show_bug.cgi?id=985

So ENABLE_ACCURATE_TEXTURES is deprecated, and is now handled by smooth().

Turns out that smooth fixes the bug with the texture rendering, too.

eg:

Quote:
void draw()
{
  pg.beginDraw();
  pg.background( 128, 32 );

  pg.translate( cx, cy, 0.0f );
  pg.rotateX( 45 );
      
  //float rot = (float)(millis() % 3600) / 10.0f;
  //pg.rotateZ( -radians(rot) );
  pg.textureMode( NORMALIZED );
  //pg.smooth();  // uncomment this line to fix the texture mapping

  pg.beginShape(QUADS);
    //pg.hint( ENABLE_ACCURATE_TEXTURES );
    pg.texture( img );
    pg.vertex( - wd, - ht, 0.0f, 0, 0 );
    pg.vertex(   wd, - ht, 0.0f, 1, 0 );
    pg.vertex(   wd,   ht, 0.0f, 1, 1 );
    pg.vertex( - wd,   ht, 0.0f, 0, 1 );
  pg.endShape();
  
  pg.endDraw();

  image( pg, 0, 0 );
}



I'll add a bug to the tracker.
Page Index Toggle Pages: 1