Rendering to texture ussing processing 2.+

edited May 2014 in GLSL / Shaders

All the examples for framebuffers uses opengl... Are there any examples available on how to use Framebuffer or any other way to render to texture using the current version of processing or compatible libraries. Thanks in advance processing gurus!

Answers

  • PGraphics  graphicsFrameBuffer;
    graphicsFrameBuffer = createGraphics( iScreenWidth, iScreenHeight, P3D );
    
    graphicsFrameBuffer.beginDraw();
    
          graphicsFrameBuffer.shader( shaderBackbufferStep );
          graphicsFrameBuffer.background(255);
    
          shape( shapeSphere );
    
    graphicsFrameBuffer.endDraw();  
    
  • Just mebe u should place shape( shapeSphere ); after the endDraw()? :-/

  • edited May 2014

    @GoToLoop - Thanks for your input... Explain your rationale, if I put the shape out then it wont be rendered to the buffer... The code sorta works however i have the following unrelated gripes: 1) Is the performance good to be called per frame ?(Ok while tested... however only one shpere is rendered) 2) Rendering is becomes funny when switching from different types of shaders eg Light, Texlight and so on even if you declare a shader texlight and dont use the light... light gets somewhat calculated.... however if you use an unlit type of shaders Processing AUTOMAGICALLY forces to the default shader...!!!buffer_glow_ buffer_glow

  • edited May 2014

    Notice that I have to reverse the background color as a hack to try to get the desired effect... Because of the directional light of the scene is located on the center of the sun the light iluminates the BACK of the faces hence rendering them as shadows EVEN THOUGH I DONT USE LIGHT TO RENDER THE SUN...

    #define PROCESSING_LIGHT_SHADER
    
    uniform mat4 transform;
    uniform vec4 lightPosition;
    
    attribute vec4 vertex;
    
    
    void main()
    {
      gl_Position = transform * vertex;
    
    
    }
    
    #ifdef GL_ES
    precision mediump float;
    precision mediump int;
    #endif
    
    
    varying vec4 vertColor;
    
    void main()
    {
      gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );
    }
    
  • Explain your rationale, if I put the shape out then it wont be rendered to the buffer...

    I confess I dunno much about PShape! What I know is that we gotta specify which PGraphics to issue a drawing command.
    So, shape(shapeSphere); renders in the Processing's own canvas rather than a specific PGraphics!

  • @GoToLoop - Rendering the geometry between the PGraphics.beginDraw()/EndDraw only renders to the PGraphics and not to processing own canvas...

Sign In or Register to comment.