Loading...
Logo
Processing Forum
hi,
i'd like to have a preview window popping up, showing some 3d stuff and closing afterwards (as soon as you click the X in the title bar). so far i am almost able to do so, my big problem is:
if i use opengl (or any other but the default renderer) as renderer for the child window, my parent window (opengl) freezes. basically i did this: http://www.sojamo.de/libraries/controlP5/examples/extra/ControlP5frame/ControlP5frame.pde and added a WindowListener() to the 2nd frame).

i know JOGL should be able to handle multiple windows (frames) , but how could i do the trick when using PApplet?

thanks for any hints in advance!

btw i unsuccessfully tried these line of code https://forum.processing.org/topic/second-monitor-window-and-optimizing-performance#25080000000721035 
this one does not work with opengl (p2d or p3d) too: https://forum.processing.org/#topic/25080000000074131

Replies(2)

Hi Matthias, I also had no luck running multiple windows with OpenGL context, nor was I successful to copy an OpenGL context to another window using a Java2D renderer (I am using processing 2.0b8, osx). 

The extra window in the controlP5 ControlFrame example you are linking to works fine with a non-OpenGL renderer but changing to P2D or P3D freezes the main window, I get the same results with g4p's WindowStarter example when changing the renderers to an OpenGL (P2D, P3D) renderer. I suspect that a PGraphicsOpenGL context cannot be shared amongst separate windows. 

Sharing context with the GLGraphics library and the GLTextureWindow worked great, sadly it didnt make it (yet?) into the default processing renderers. Being able to run multiple windows with OpenGL renderers would indeed be great.

In one of my projects I do use Syphon (osx only) to overcome this limitation. I am composing an OpenGL texture inside my gui window and then send the results to a second window which I only use for fullscreen rendering. Here both windows run inside their own processes which allows both to use OpenGL.

If you need more details / an example, let me know.


andreas schlegel, http://www.sojamo.de
Hi there,
I just wanted to mention that I found a way to render OpenGL to a second window, but only if you're using the current development version from github, because PGraphics.getTexture() isn't exposed in the current release (2.0.1)

Here's the code I use for it in Eclipse:

Copy code
  1. import java.awt.Frame;
  2. import javax.media.opengl.GL;
  3. import javax.media.opengl.GL2;
  4. import javax.media.opengl.GLAutoDrawable;
  5. import javax.media.opengl.GLCapabilities;
  6. import javax.media.opengl.GLContext;
  7. import javax.media.opengl.GLEventListener;
  8. import javax.media.opengl.GLProfile;
  9. import javax.media.opengl.awt.GLCanvas;
  10. import com.jogamp.opengl.util.FPSAnimator;
  11. import processing.core.PGraphics;
  12. import processing.opengl.PGL;
  13. import processing.opengl.PGraphicsOpenGL;
  14. import processing.opengl.Texture;
  15. public class OutputWindow  implements GLEventListener  {
  16.     PGraphics source;
  17.     Texture tex;
  18.     public OutputWindow(PGraphicsOpenGL source){
  19.         GLProfile glp = GLProfile.getDefault();
  20.         GLCapabilities caps = new GLCapabilities(glp);
  21.        
  22.         GLCanvas gc = (GLCanvas)PGL.canvas;
  23.         GLContext c = gc.getContext();
  24.         GLCanvas canvas = new GLCanvas(caps, c);
  25.         Frame frame = new Frame("Monitor Window");
  26.         frame.setSize(source.width, source.height);
  27.         frame.add(canvas);
  28.         frame.setVisible(true);
  29.        
  30.         tex = source.getTexture();
  31.        
  32.         canvas.addGLEventListener(this);
  33.         FPSAnimator animator = new FPSAnimator(canvas, 60);
  34.         animator.start();
  35.        
  36.     }
  37.     @Override
  38.     public void display(GLAutoDrawable drawable) {
  39.         GL2 gl = drawable.getGL().getGL2();
  40.         gl.glEnable( GL.GL_TEXTURE_2D );
  41.         gl.glBindTexture(tex.glTarget, tex.glName);
  42.         gl.glBegin(GL.GL_TRIANGLES);
  43.         gl.glColor3f(1, 1, 1);
  44.         gl.glTexCoord2d(0, 0);
  45.         gl.glVertex2f(-1, -1);
  46.         gl.glTexCoord2d(1, 0);
  47.         gl.glVertex2f(1, -1);
  48.         gl.glTexCoord2d(1, 1);
  49.         gl.glVertex2f(1, 1);
  50.        
  51.         gl.glTexCoord2d(1, 1);
  52.         gl.glVertex2f(1, 1);
  53.         gl.glTexCoord2d(0, 1);
  54.         gl.glVertex2f(-1, 1);
  55.         gl.glTexCoord2d(0, 0);
  56.         gl.glVertex2f(-1, -1);
  57.         gl.glEnd();   
  58.         gl.glDisable( GL.GL_TEXTURE_2D );
  59.     }
  60.     @Override
  61.     public void dispose(GLAutoDrawable drawable) {
  62.         // TODO Auto-generated method stub
  63.        
  64.     }
  65.     @Override
  66.     public void init(GLAutoDrawable drawable) {
  67.         // TODO Auto-generated method stub
  68.        
  69.     }
  70.     @Override
  71.     public void reshape(GLAutoDrawable drawable, int arg1, int arg2, int arg3,
  72.             int arg4) {
  73.         // TODO Auto-generated method stub
  74.        
  75.     }
  76. }
To use it, you just create a new OutputWindow with the PGraphics that you want to show in a new window.

The crucial bit for making it work with P3D is this:

Copy code
  1. GLCanvas gc = (GLCanvas)PGL.canvas;
  2. GLContext c = gc.getContext();
  3. GLCanvas canvas = new GLCanvas(caps, c);

The second argument to GLCanvas specifies an OpenGL context that the new window will be sharing, thus letting them both use the same texture data!

I hope this helps people.