OPENGL mapping texture and perspective

edited December 2013 in GLSL / Shaders

Hi all, I'm trying to mapping a texture to a polygon (4 vertices). I want to simulate perspective, but as you can see, the texture result deformed and not follow the perspective. Any idea? I suppose I have to write some JOGL direct calls. Can you help me?

perspective

The code I use for mapping the texture is now quite simple:

void draw()
{
    beginShape();
    texture(myImage);
    vertex(920, 120, 0, 0);
    vertex(1180, 120, image.width, 0);
    vertex(1200, 400, image.width, image.height);
    vertex(900, 400, 0, image.height);
    endShape();
}

The coordinates into vertex command are purely for example.

Thanks so much.

paolofuse

Answers

  • Answer ✓

    processing maps everything to triangles and there's a problem with applying textures to triangles which means they get skewed slightly (someone once posted a link to an explanation but i don't have it)

    you can use low-level opengl (real QUADS) to get around it or, i'm told, cut the texture up into smaller blocks (like your middle diagram) which reduces the effects.

  • Thanks koogs. I thought to cut the texture up into smaller blocks, but now I prefer to use low-level opengl. The WIKI reports this:

    GL2 gl = ((PGraphicsOpenGL)g).beginPGL().gl.getGL2();

    but with Processing 2.1 doesn't work. Any idea how to call GL2?

    Thanks in advance. paolofuse

  • sorry, i don't use P2

    did you remember the import?

    import javax.media.opengl.GL2;

    http://wiki.processing.org/w/Advanced_OpenGL#Processing_2.x

  • edited December 2013

    Of course.

    However the WIKI is wrong, the correct way to call GL2 is:

    PGL pgl = beginPGL();
     GL2 gl2 = ((PJOGL)pgl).gl.getGL2();
    
Sign In or Register to comment.