What is the "OpenGL way" of resolving the perspective (in)correctness problem?

edited March 2017 in GLSL / Shaders

Hello!

The problem I'm having is already stated by someone else here: https://forum.processing.org/two/discussion/1842/opengl-mapping-texture-and-perspective

One of the suggested solutions is to divide the surface into triangle strips to reduce the effect. I tried that solution, it works and it is not what I am interested in, so I'm writing this post. What I'm interested in is the other suggested solution - to get OpenGL to use QUADS, how do I do that exactly?

I'm using Processing 3 and I know I have to do this:

import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;

and something like this somewhere:

PJOGL pgl = (PJOGL) beginPGL();  
GL2ES2 gl = pgl.gl.getGL2ES2();

but I'm not sure how to use that to achieve what I want.

Cheers,

Paolo

Answers

  • are you using processing 3?

    the use of shaders seems to have fixed the texturing issue, at least based on the example i just tried (3.1.1):

    PImage tex;
    
    void setup() {
      size(640, 640, P3D);
      tex = loadImage("texture.jpg"); // 256x256 b&w stripes
    }
    
    void draw() {
      background(128);
      noStroke();
      translate(width / 2, height / 2);
      rotateX(map(mouseY, 0, height, 0, 2 * TWO_PI));
      rotateY(map(mouseX, 0, width, 0, 2 * TWO_PI));
      textureMode(NORMAL);
    
      // draw quad
      float A = -300.0;
      float B = 300.0;
      float a = 0.0;
      float b = 1.0;
      beginShape();
      texture(tex);
      vertex(A, A, 0, a, a); // excuse this laziness...
      vertex(A, B, 0, a, b);
      vertex(B, B, 0, b, b);
      vertex(B, A, 0, b, a);
      endShape();
    }
    
  • even the textureCube example looks ok (despite the comment about P3D)

  • Thanks, but what about this? The problem persists.

    PImage tex;
    
    void setup() {
      size(640, 640, P2D);
      tex = loadImage("texture.png"); // 256x256 b&w stripes
    }
    
    void draw() {
      background(128);
      noStroke();
      translate(width / 2, height / 2);
      // rotateX(map(mouseY, 0, height, 0, 2 * TWO_PI));
      // rotateY(map(mouseX, 0, width, 0, 2 * TWO_PI));
      textureMode(NORMAL);
    
      // draw quad
      float A = -300.0;
      float B = 300.0;
      float a = 0.0;
      float b = 1.0;
      beginShape();
      texture(tex);
      vertex(A*mouseX/width, A, a, a); // excuse this laziness...
      vertex(A, B, a, b);
      vertex(B, B, b, b);
      vertex(B*mouseX/width, A, b, a);
      endShape();
    }
    
  • Answer ✓

    ha, i initially didn't see a problem in that code because i was using horizontal stripes...

    i've not tried the new opengl way but i can't see how it could possibly be any different because of how it's all triangle-based now. (previous versions of opengl had real quads). and using raw opengl is only going to get you the same as using processing vertexes.

    ( you've read this, yes? https://en.wikipedia.org/wiki/Texture_mapping#Affine_texture_mapping )

    i think the only was around this would be subdividing the shape.

  • edited March 2017

    previous versions of opengl had real quads

    Okay, I get it. I thought there's a good opengl way of removing the effect of affine mapping (as suggested in the old thread), but I guess I'll stick to subdividing the shape.

  • a quick google turns up

    https://bitlush.com/blog/arbitrary-quadrilaterals-in-opengl-es-2-0

    not sure how useful this is.

Sign In or Register to comment.