How to point to the display surface

edited October 2014 in How To...

This might be thinking about it wrong, but I was wondering if the main display has an identifier?

I have a function that first draws to the screen and then reflects the drawn stuff into an offscreen buffer. Can't do it first in buffer and then smack it to the screen because of performance.

So now, my function does the drawing twice, which is kind of odd:

smooth(); 
line(0, 0, 10, 10); 

surface.smooth(); 
surface.line(0, 0, 10, 10);

Crude example on what's happening, but I would like the function to just have the draw commands only once and just send them the drawing surface, first main screen and then the offscreen surface. Is this possible or am I going about this the wrong way? 8-}

Answers

  • edited October 2014

    What you describe doesn't match what I understand a PGraphics behavior is:
    http://processing.org/reference/PGraphics.html

    When we do something like this: line(0, 0, 10, 10); it goes to the canvas, which is a PGraphics too.
    When draw() is finished, the current content of that PGraphics canvas is rendered on the screen.

    When we use our own PGraphics, we still gotta stamp that in the main canvas in order for it to be rendered:
    Since a PGraphics is also a PImage, we can use image() or set() to put it in the main PGraphics canvas.
    http://processing.org/reference/image_.html
    http://processing.org/reference/set_.html

  • edited October 2015

    Thanks GoToLoop! I had the same problem ;) + Thank you for articles in your post! especially first link ;) Best Regards!


    hill climb racing cheats <- my signature ...

  • Yup, that's what I was looking for - I was looking for the name of the PGraphics of the canvas. I don't need to render the offscreen buffer, I just need to sync it 1:1 with the stuff I see on the screen. ^.^

  • edited October 2014 Answer ✓

    PGraphics main canvas' reference is held by undocumented "system" variable g.

  • edited October 2014

    The function I'm trying to do would be like:

    void DrawStuffOnTheBufferAndScreen (PGraphics surface) {
    
            beginDraw(); 
            surface.line(0, 0, 10, 10); 
            endDraw(); 
    }
    

    And I want to feed it the main screen and then the offscreen buffer.

    I know, I'm weird. >.<

    EDIT: and now I realize that if I do it like that, I would have to call beginDraw() / endDraw() everyframe. Yikes. That won't work.

    Still, would be nice to know if the main canvas has a pointer like getCanvas(0) etc.

  • Thank you thank you @GoToLoop! ^.^

Sign In or Register to comment.