draw image upside down

edited July 2014 in How To...

I have a problem where it draws the images upside down in OpenGL. What is a quick way to draw a image upside down to counter it?

I would think this: image(canvas, 0, height, width, -height);

But that doesn't work.

Answers

  • edited June 2014
    scale (1,-1);  // edited ......................
    image..........
    
  • edited June 2014

    NM.

  • I think it should be scale(1, -1) But even if i do that i see nothing :(

  • Answer ✓

    when you call scale(1,-1) the coordinate system goes in the other direction. this means that positive coordinates go "up", eg. line(10,10,110,110) won't be visible because now it starts outside of the window (above the window to be exact). to draw in the correct place you need bring your coordinates "down".

    here is some code that works:

    PGraphics img; 
    
    void setup(){
      size( 500, 500 ); 
    
      // prepare some dummy image 
      // with a line going from the top left 
      // to the bottom right corner
      img = createGraphics(100,100); 
      img.beginDraw(); 
      img.stroke( 255, 0, 0 ); 
      img.line( 0, 0, 100, 100 );
      img.endDraw(); 
    }
    
    
    void draw(){
      background( 255 ); 
      fill( 0 ); 
      text( "normal", 0, 20 ); 
      image( img, 0, 50 );
      text( "flipped vertically", 200, 20 );  
      imageFlipped( img, 200, 50 );  
    }
    
    void imageFlipped( PImage img, float x, float y ){
      pushMatrix(); 
      scale( 1, -1 );
      image( img, x, - y - img.height ); 
      popMatrix(); 
    } 
    

    hope the explanation helps.

  • ps. i've made you a little image, that's always better than text: coordinate flipping explained

    http://i.imgur.com/Ouw0HLE.png

  • Thanks, it really helped!

Sign In or Register to comment.