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 & HelpPrograms › texture perspective
Page Index Toggle Pages: 1
texture perspective (Read 1444 times)
texture perspective
Jun 1st, 2010, 6:25am
 
Hi,

I'm actuallly learning how 2D textures works within P3D.
I've tried something really simple, create a texture and map over a square. The result is kinda weird, got some perspective distortion.

After read a bit of opengl tutorials, this doesn't seems to be that weird.
I think i've to use glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST) in opengl to get ride of it but what for P3D ?

Does Processing have any core functions to handle that ?

Here's the source code:
Quote:
PGraphics b;
int l = 24;

void setup()
{
  size(200, 200, P3D);
  b = createGraphics(l*2, l*2, P3D);
  textureMode(NORMALIZED);
}

void draw()
{
  //generate the texture
  b.beginDraw();
  b.noStroke();
  b.fill(0);
  b.rect(0, 0, l, l);
  b.rect(l, l, l, l);
  b.fill(255);
  b.rect(l, 0, l, l);
  b.rect(0, l, l, l);
  b.endDraw();

  //basic tranformations
  pushMatrix();
  translate(width/2, height/2);
  rotateX(-PI/4);
  rotateY(-PI/4);

  beginShape(QUADS);
  texture(b);
  vertex(l, -l, -l, 0, 0);
  vertex(-l, -l, -l, 0, 1);
  vertex(-l, -l, l, 1, 1);
  vertex(l, -l, l, 1, 0);
  endShape();
  
  popMatrix();
  image(b, 0 ,0);
}





Re: texture perspective
Reply #1 - Jun 1st, 2010, 2:57pm
 
did you see the texture examples? it mentions the problem there.

the way around it is to split the quad up into smaller pieces, that way the distortion is minimised. it's barely noticeable on the third example.

http://processing.org/learning/3d/texture3.html
Re: texture perspective
Reply #2 - Jun 1st, 2010, 4:06pm
 
its the same with lightning. you can see the difference by changing the mousepos. you get much better results when you subdivide the shape


Code:
 

void setup(){
size(500, 500, P3D);
background(255);
noStroke();
sphereDetail(35);
}

void draw(){

//lights();
pointLight(151, 202, 226, 235, 440, 80);
pointLight(251, 22, 226, 205, 240, 80);
pointLight( 151, 222, 6, 305, 140, 80);

fill(215,220,210 );
translate(100,100);
int res = 1+mouseX/50;

for(int i = 0; i<res; i++){
beginShape(QUAD_STRIP);
for(int j = 0; j<=res; j++){

vertex(i*300/res,j*300/res);
vertex((i+1)*300/res,(j)*300/res);

}endShape();
}}
Page Index Toggle Pages: 1