@Override public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { GL2 gl2 = arg0.getGL().getGL2(); gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); // coordinate system origin at lower left with width and height same as the window GLU glu = new GLU(); glu.gluOrtho2D(0.0f, getWidth(), 0.0f, getHeight()); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); gl2.glViewport(0, 0, getWidth(), getHeight()); controller.updateExtents(arg3 / 2, arg4 / 2); } }
/** * Moves the designated {@link GLEventListener} from {@link GLAutoDrawable} <code>src</code> to <code>dest</code>. * If <code>preserveInitState</code> is <code>true</code>, it's initialized state is preserved * and {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape(..)} issued w/ the next {@link GLAutoDrawable#display()} call. * <p> * Note that it is only legal to pass <code>preserveInitState := true</code>, * if the {@link GLContext} of both <code>src</code> and <code>dest</code> are shared, or has itself moved from <code>src</code> to <code>dest</code>. * </p> * <p> * Also note that the caller is encouraged to pause an attached {@link GLAnimatorControl}. * </p> * @param src * @param dest * @param listener * @param preserveInitState */ public static final void moveGLEventListener(final GLAutoDrawable src, final GLAutoDrawable dest, final GLEventListener listener, final boolean preserveInitState) { final boolean initialized = src.getGLEventListenerInitState(listener); if( preserveInitState ) { src.removeGLEventListener(listener); dest.addGLEventListener(listener); if( initialized ) { dest.setGLEventListenerInitState(listener, true); dest.invoke(false, new ReshapeGLEventListener(listener, true)); } } else { src.disposeGLEventListener(listener, true); dest.addGLEventListener(listener); } }
@Override public void widgetDisposed( DisposeEvent e ) { // dispose of resources associated with the canvas disposeAttached( ); // destroy the source of the shared glContext sharedContextSource.destroy( ); } } );
@Override public boolean run(final GLAutoDrawable drawable) { drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); return false; // issue re-display w/ new viewport! } };
/** * {@inheritDoc} * * @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable, * int, int, int, int) */ @Override public void reshape( final GLAutoDrawable drawable, final int arg1, final int arg2, final int arg3, final int arg4 ) { final GL2 gl = drawable.getGL().getGL2(); final float w = this.window.getDrawableSurface().getWidth(); final float h = this.window.getDrawableSurface().getHeight(); gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION ); gl.glLoadIdentity(); this.glu.gluPerspective( 50, (w / h), 0.01, 10 ); }
@Override public void init(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); System.err.println(JoglVersion.getGLInfo(gl, null)); System.err.println("Requested: "+drawable.getNativeSurface().getGraphicsConfiguration().getRequestedCapabilities()); System.err.println("Chosen : "+drawable.getChosenGLCapabilities()); System.err.println("GL impl. class "+gl.getClass().getName()); if( gl.isGL4ES3() ) { final GL4ES3 _gl = gl.getGL4ES3(); System.err.println("GL4ES3 retrieved, impl. class "+_gl.getClass().getName()); } if( gl.isGL3() ) { final GL3 _gl = gl.getGL3(); System.err.println("GL3 retrieved, impl. class "+_gl.getClass().getName()); } if( gl.isGLES3() ) { final GLES3 _gl = gl.getGLES3(); System.err.println("GLES3 retrieved, impl. class "+_gl.getClass().getName()); } if( gl.isGLES2() ) { final GLES2 _gl = gl.getGLES2(); System.err.println("GLES2 retrieved, impl. class "+_gl.getClass().getName()); } }
final public static String[] getGLInfos(GLAutoDrawable drawable) { GL gl = drawable.getGL(); GLCapabilitiesImmutable c = drawable.getChosenGLCapabilities(); String[] ret = { c + "", c.getDoubleBuffered() + "", c.getStereo() + "", c.getStencilBits() + "", gl.getClass().getName(), gl.glGetString(GL.GL_VENDOR), gl.glGetString(GL.GL_RENDERER), gl.glGetString(GL.GL_VERSION) }; return ret; }
@Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { if( !drawable.getAutoSwapBufferMode() ) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glViewport(0, 0, width, height); } } }
final int aSz = glad.getGLEventListenerCount(); listeners = new GLEventListener[aSz]; listenersInit = new boolean[aSz]; for(int i=0; i<aSz; i++) { final GLEventListener l = glad.getGLEventListener(0); listenersInit[i] = glad.getGLEventListenerInitState(l); listeners[i] = glad.removeGLEventListener( l ); final boolean trn; if( listeners[i] instanceof TileRendererListener ) { glad.addGLEventListener(tiledGLEL); gladAutoSwapBufferMode = glad.getAutoSwapBufferMode(); gladRequiresPreSwap = this.reqPreSwapBuffers(glad.getChosenGLCapabilities()); glad.setAutoSwapBufferMode(false); if( DEBUG ) { System.err.println("TileRenderer: attached: "+glad); System.err.println("TileRenderer: preSwap "+gladRequiresPreSwap+", "+glad.getChosenGLCapabilities()+", cached "+listeners.length+" listener");
final GLAnimatorControl aAnim = a.getAnimator(); final GLAnimatorControl bAnim = b.getAnimator(); final boolean aIsPaused = isAnimatorAnimatingOnOtherThread(aAnim) && aAnim.pause(); final boolean bIsPaused = isAnimatorAnimatingOnOtherThread(bAnim) && bAnim.pause(); final RecursiveLock aUpstreamLock = a.getUpstreamLock(); final RecursiveLock bUpstreamLock = b.getUpstreamLock(); aUpstreamLock.lock(); bUpstreamLock.lock(); try { final NativeSurface aSurface = a.getNativeSurface(); final boolean aSurfaceLocked = NativeSurface.LOCK_SURFACE_NOT_READY < aSurface.lockSurface(); if( a.isRealized() && !aSurfaceLocked ) { throw new GLException("Could not lock realized a surface "+a); final NativeSurface bSurface = b.getNativeSurface(); final boolean bSurfaceLocked = NativeSurface.LOCK_SURFACE_NOT_READY < bSurface.lockSurface(); if( b.isRealized() && !bSurfaceLocked ) { throw new GLException("Could not lock realized b surface "+b); for(int i = a.getGLEventListenerCount() - 1; 0 <= i; i--) { a.disposeGLEventListener(a.getGLEventListener(i), false); for(int i = b.getGLEventListenerCount() - 1; 0 <= i; i--) { b.disposeGLEventListener(b.getGLEventListener(i), false); b.setContext( a.setContext( b.getContext(), false ), false ); a.invoke(true, setViewport);
final GLAnimatorControl destAnim = dest.getAnimator(); final boolean destAnimPaused; if( null != destAnim ) { final RecursiveLock destUpstreamLock = dest.getUpstreamLock(); destUpstreamLock.lock(); final boolean destIsRealized; try { final NativeSurface destSurface = dest.getNativeSurface(); final boolean destSurfaceLocked = NativeSurface.LOCK_SURFACE_NOT_READY < destSurface.lockSurface(); if( dest.isRealized() && !destSurfaceLocked ) { throw new GLException("Could not lock realized surface "+dest); dest.setContext( null, true ); destIsRealized = dest.isRealized(); if( destIsRealized && null != aUpSurface ) { dest.getDelegatedDrawable().setRealized(false); dest.getDelegatedDrawable().setRealized(true); dest.setContext( context, false ); } finally { if( destSurfaceLocked ) { dest.invoke(destIsRealized, aGLCmds); // only wait if already realized dest.addGLEventListener( l ); dest.setGLEventListenerInitState(l, listenersInit[i]);
/** * Detaches the given {@link GLAutoDrawable} from this tile renderer. * @see #attachAutoDrawable(GLAutoDrawable) * @see #getAttachedDrawable() */ public final void detachAutoDrawable() { if( null != glad ) { glad.removeGLEventListener(tiledGLEL); final int aSz = listenersInit.length; for(int i=0; i<aSz; i++) { final GLEventListener l = listeners[i]; if( l instanceof TileRendererListener ) { ((TileRendererListener)l).removeTileRendererNotify(this); } glad.addGLEventListener(l); glad.setGLEventListenerInitState(l, listenersInit[i]); } glad.setAutoSwapBufferMode(gladAutoSwapBufferMode); if( DEBUG ) { System.err.println("TileRenderer: detached: "+glad); System.err.println("TileRenderer: "+glad.getChosenGLCapabilities()); } listeners = null; listenersInit = null; glad = null; } }
wait && ( !drawable.isRealized() || null==drawable.getContext() ) ) { return false; boolean deferredHere; synchronized(glRunnablesLock) { final boolean isGLThread = drawable.isThreadGLCapable(); deferredHere = isAnimatorAnimatingOnOtherThread(); if( deferredHere ) { drawable.display(); } else if( wait ) { try {
@Override public void disposePainter( final GlimpsePainter painter ) { this.getGLDrawable( ).invoke( false, new GLRunnable( ) { @Override public boolean run( GLAutoDrawable drawable ) { painter.dispose( getGlimpseContext( ) ); return true; } } ); }
/** * Rendering one tile, by simply calling {@link GLAutoDrawable#display()}. * * @throws IllegalStateException if no {@link GLAutoDrawable} is {@link #attachAutoDrawable(GLAutoDrawable) attached} * or imageSize is not set */ public final void display() throws IllegalStateException { if( null == glad ) { throw new IllegalStateException("No GLAutoDrawable attached"); } glad.display(); }
public static void main( String[] args ) throws Exception { Example example = Example.showWithSwing( new PointShaderExample( ) ); // add a GLEventListener to the GlimpseCanvas which will print some information // about GLCapabilities upon initialization example.getCanvas( ).getGLDrawable( ).addGLEventListener( new GLCapabilityEventListener( ) ); }
@Override public boolean run(final GLAutoDrawable drawable) { drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); return true; } };
@Override public void init( final GLAutoDrawable drawable ) { final GL2 gl = drawable.getGL().getGL2(); gl.setSwapInterval( 1 ); gl.glEnable( GL.GL_DEPTH_TEST ); gl.glDepthFunc( GL.GL_LEQUAL ); gl.glShadeModel( GLLightingFunc.GL_SMOOTH ); gl.glHint( GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST ); // gl.glEnable( GL.GL_BLEND ); // gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ); gl.glEnable( GL2GL3.GL_POLYGON_SMOOTH ); final float w = this.window.getDrawableSurface().getWidth(); final float h = this.window.getDrawableSurface().getHeight(); // Set the projection matrix (only done once - just here) gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION ); gl.glLoadIdentity(); this.glu.gluPerspective( 50, (w / h), 0.01, 10 ); // Set the initial model matrix gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW ); gl.glLoadIdentity(); gl.glViewport( 0, 0, (int) w, (int) h ); /* viewport size in pixels */ }