com.jogamp.opengl.GLDrawableFactory Java Examples

The following examples show how to use com.jogamp.opengl.GLDrawableFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JOGLOffscreenRenderer.java    From cineast with MIT License 6 votes vote down vote up
/**
 * Default constructor. Defines the width and the height of this JOGLOffscreenRenderer and
 * initializes all the required OpenGL bindings.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 */
public JOGLOffscreenRenderer(int width, int height) {
    /* Assign width and height. */
    this.width = width;
    this.height = height;
    this.aspect = (float) width / (float) height;

    /* Initialize GLOffscreenAutoDrawable. */
    GLDrawableFactory factory = GLDrawableFactory.getFactory(GL_PROFILE);
    this.drawable = factory.createOffscreenAutoDrawable(null, GL_CAPABILITIES,null,width,height);
    this.drawable.display();

    /* Initialize GLU and GL2. */
    this.glu = new GLU();
    this.gl = drawable.getGL().getGL2();

    /* Set default color. */
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
 
Example #2
Source File: SharedDrawable.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static void init() {
    if (isInitialised) {
        throw new RenderException("Can't initialise SharedDrawable more than once.");
    }

    // Use own display device.
    final boolean createNewDevice = true;
    sharedDrawable = GLDrawableFactory.getFactory(getGLProfile()).createDummyAutoDrawable(null, createNewDevice, getGLCapabilities(), null);

    // Trigger GLContext object creation and native realization.
    sharedDrawable.display();
    sharedDrawable.getContext().makeCurrent();
    try {
        sharedDrawable.setGL(new DebugGL3(sharedDrawable.getGL().getGL3()));

        // Create a shared texture object for the icon texture array.
        gl = sharedDrawable.getGL().getGL3();
        final int[] textureName = new int[1];
        gl.glGenTextures(1, textureName, 0);
        iconTextureName = textureName[0];

        // Create shared glyph coordinates and glyph image textures using a GlyphManager
        final boolean useMultiFonts = LabelFontsPreferenceKeys.useMultiFontLabels();
        if (useMultiFonts) {
            glyphManager = new GlyphManagerBI(LabelFontsPreferenceKeys.getFontInfo());
        } else {
            glyphManager = null;
        }

        glyphTextureController = new GlyphManagerOpenGLController(glyphManager);

        labelBackgroundGlyphPosition = glyphManager != null ? glyphManager.createBackgroundGlyph(0.5f) : 0;
        glyphTextureController.init(gl);
    } finally {
        sharedDrawable.getContext().release();
        isInitialised = true;
    }
}
 
Example #3
Source File: GLScene.java    From depan with Apache License 2.0 5 votes vote down vote up
private GLContext createGLContext() {

    try {
      GLLogger.LOG.info("Create context...");
      GLDrawableFactory drawableFactory = GLDrawableFactory.getFactory(DEFAULT_PROFILE);
      GLContext result = drawableFactory.createExternalGLContext();
      GLLogger.LOG.info("    Done.");

      return result;
    } catch (Throwable errGl) {
      GLLogger.LOG.error("Unable to create GL Context", errGl);
      errGl.printStackTrace();
      throw new RuntimeException(errGl);
    }
  }
 
Example #4
Source File: JoglVersionAction.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
    final GLProfile glProfile = SharedDrawable.getGLProfile();

    // Create GLContext and trigger GLContext object creation and native realization.
    final GLAutoDrawable drawable = GLDrawableFactory.getFactory(glProfile).createDummyAutoDrawable(null, true, new GLCapabilities(glProfile), null);
    drawable.display();
    drawable.getContext().makeCurrent();

    final GL gl = drawable.getGL().getGL3();

    final StringBuilder sb = new StringBuilder();
    sb.append(String.format("OpenGL version: %s\n", gl.glGetString(GL.GL_VERSION)));
    sb.append(String.format("Vendor: %s\n", gl.glGetString(GL.GL_VENDOR)));
    sb.append(String.format("Renderer: %s\n", gl.glGetString(GL.GL_RENDERER)));
    if (gl instanceof GL2ES2) {
        sb.append(String.format("Shading language version: %s\n", gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION)));
    }

    final JoglVersion jv = JoglVersion.getInstance();
    final Set<?> names = jv.getAttributeNames();
    final ArrayList<String> lines = new ArrayList<>();
    for (final Object name : names) {
        lines.add(String.format("%s: %s\n", name, jv.getAttribute((Attributes.Name) name)));
    }

    Collections.sort(lines);

    sb.append("\nJOGL Attributes\n");
    for (final String line : lines) {
        sb.append(line);
    }

    sb.append("\nGL Strings\n");
    JoglVersion.getGLStrings(gl, sb, true);
    sb.append("\n");

    final InfoTextPanel itp = new InfoTextPanel(sb.toString());
    final NotifyDescriptor.Message msg = new NotifyDescriptor.Message(itp);
    msg.setTitle(Bundle.CTL_JoglVersionAction());
    DialogDisplayer.getDefault().notify(msg);
}
 
Example #5
Source File: OpenGLGFXCMD.java    From sagetv with Apache License 2.0 4 votes vote down vote up
private void initpbuffer()
{
  GL2 gl;
  System.out.println("initpbuffer");
  osdwidth=newosdwidth;
  osdheight=newosdheight;
  GLCapabilities caps = new GLCapabilities(null);
  caps.setHardwareAccelerated(true);
  caps.setDoubleBuffered(false);
  caps.setAlphaBits(8);
  caps.setRedBits(8);
  caps.setGreenBits(8);
  caps.setBlueBits(8);
  caps.setDepthBits(0);
  caps.setFBO(false);
  System.out.println("initpbuffer2");
  if (!GLDrawableFactory.getFactory(caps.getGLProfile()).canCreateGLPbuffer(null, caps.getGLProfile()))
  {
    throw new GLException("pbuffers unsupported");
  }
  if(pbuffer!=null) pbuffer.destroy();
  System.out.println("initpbuffer3");
  pbuffer = GLDrawableFactory.getFactory(caps.getGLProfile()).createOffscreenAutoDrawable(null,
      caps,
      null,
      osdwidth,
      osdheight
      );
  pbuffer.setContext(pbuffer.createContext(c.getContext()), true);
  //pbuffer.setContext(c.getContext(), false);
  System.out.println("initpbuffer4: pbuffers is null? " + (pbuffer==null));
  if(pbuffer.getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT)
  {
    System.out.println("Couldn't make pbuffer current?");
    return;
  }
  System.out.println("initpbuffer5");
  gl = pbuffer.getGL().getGL2();

  gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);

  gl.glClear( gl.GL_COLOR_BUFFER_BIT);

  gl.glViewport(0, 0, osdwidth, osdheight);
  gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
  gl.glLoadIdentity();
  gl.glOrtho(0,osdwidth,0,osdheight,-1.0,1.0);
  gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
  gl.glLoadIdentity();

  // TODO: look into reusing same texture like OSX version...
  if(osdt!=null) gl.glDeleteTextures(1, osdt, 0);
  osdt = new int[1];
  byte img[] = new byte[osdwidth*osdheight*4];
  gl.glGenTextures(1, osdt, 0);
  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,osdt[0]);
  gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
  gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
  gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 4, osdwidth, osdheight, 0,
      gl.GL_BGRA, bigendian ? gl.GL_UNSIGNED_INT_8_8_8_8_REV : gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img));

  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, osdt[0]);
  gl.glCopyTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, 0, 0, osdwidth, osdheight);
  gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  System.out.println("initpbuffer6");
  pbuffer.getContext().release();
  System.out.println("initpbuffer7");
}
 
Example #6
Source File: GLEventListenerButton.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
public void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final int[] sampleCount) {
    if( null == fboGLAD ) {
        final ImageSequence imgSeq = (ImageSequence)texSeq;

        final GLContext ctx = gl.getContext();
        final GLDrawable drawable = ctx.getGLDrawable();
        final GLCapabilitiesImmutable reqCaps = drawable.getRequestedGLCapabilities();
        final GLCapabilities caps = (GLCapabilities) reqCaps.cloneMutable();
        caps.setFBO(true);
        caps.setDoubleBuffered(false);
        if( !useAlpha ) {
            caps.setAlphaBits(0);
        }
        final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());

        fboGLAD = (GLOffscreenAutoDrawable.FBO) factory.createOffscreenAutoDrawable(
                        drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(),
                        caps, null, fboWidth, fboHeight);
        fboWidth = 0;
        fboHeight = 0;
        fboGLAD.setSharedContext(ctx);
        fboGLAD.setTextureUnit(imgSeq.getTextureUnit());
        fboGLAD.addGLEventListener(glel);
        fboGLAD.display(); // 1st init!

        final FBObject.TextureAttachment texA01 = fboGLAD.getColorbuffer(GL.GL_FRONT).getTextureAttachment();
        final Texture tex = new Texture(texA01.getName(), imgSeq.getTextureTarget(),
                                fboGLAD.getSurfaceWidth(), fboGLAD.getSurfaceHeight(), fboGLAD.getSurfaceWidth(), fboGLAD.getSurfaceHeight(),
                                false /* mustFlipVertically */);
        imgSeq.addFrame(gl, tex);
        markStateDirty();
    } else if( 0 != fboWidth*fboHeight ) {
        fboGLAD.setSurfaceSize(fboWidth, fboHeight);
        fboWidth = 0;
        fboHeight = 0;
        markStateDirty();
    } else if( animateGLEL ) {
        fboGLAD.display();
    }

    super.drawShape(gl, renderer, sampleCount);

    if( animateGLEL ) {
        markStateDirty(); // keep on going
    }
}