public static final GL2 getCurrentGL2() throws GLException {
   GLContext curContext = GLContext.getCurrent();
   if (curContext == null) {
     throw new GLException("No OpenGL context current on this thread");
   }
   return curContext.getGL().getGL2();
 }
Esempio n. 2
0
  @Override
  protected final GLDrawableImpl createOffscreenDrawableImpl(final NativeSurface target) {
    if (target == null) {
      throw new IllegalArgumentException("Null target");
    }
    final AbstractGraphicsConfiguration config = target.getGraphicsConfiguration();
    final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
    if (!caps.isPBuffer()) {
      return new X11PixmapGLXDrawable(this, target);
    }

    // PBuffer GLDrawable Creation
    GLDrawableImpl pbufferDrawable;
    final AbstractGraphicsDevice device = config.getScreen().getDevice();

    /**
     * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, we need to have a
     * context current on the same Display to create a PBuffer. The dummy context shall also use the
     * same Display, since switching Display in this regard is another ATI bug.
     */
    final SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device);
    if (null != sr && sr.isGLXVendorATI() && null == GLContext.getCurrent()) {
      sr.getContext().makeCurrent();
      try {
        pbufferDrawable = new X11PbufferGLXDrawable(this, target);
      } finally {
        sr.getContext().release();
      }
    } else {
      pbufferDrawable = new X11PbufferGLXDrawable(this, target);
    }
    return pbufferDrawable;
  }
Esempio n. 3
0
  /**
   * //! Draw a pretty arrow on the z-axis using a cone and a cylinder (using GLUT)
   *
   * @param aArrowStart
   * @param aArrowTip
   * @param aWidth
   */
  public static void jDrawArrow(
      final JVector3d aArrowStart, final JVector3d aArrowTip, final double aWidth) {

    GL2 gl = GLContext.getCurrent().getGL().getGL2();

    gl.glPushMatrix();

    // We don't really care about the up vector, but it can't
    // be parallel to the arrow...
    JVector3d up = new JVector3d(0, 1, 0);
    // JVector3d arrow = aArrowTip-aArrowStart;
    JVector3d arrow = new JVector3d(0, 0, 0);
    arrow.normalize();
    double d = Math.abs(JMaths.jDot(up, arrow));
    if (d > .9) {
      up = new JVector3d(1, 0, 0);
    }

    JMatrixGL.jLookAt(gl, aArrowStart, aArrowTip, up);

    double distance = JMaths.jDistance(aArrowTip, aArrowStart);

    // This flips the z axis around
    gl.glRotatef(180, 1, 0, 0);

    // create a new OpenGL quadratic object
    GLUquadric quadObj;
    quadObj = glu.gluNewQuadric();

    // set rendering style
    glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL);

    // set normal-rendering mode
    glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH);

    // render a cylinder and a cone
    gl.glRotatef(180, 1, 0, 0);
    glu.gluDisk(quadObj, 0, aWidth, 10, 10);
    gl.glRotatef(180, 1, 0, 0);

    glu.gluCylinder(quadObj, aWidth, aWidth, distance * ARROW_CYLINDER_PORTION, 10, 10);
    gl.glTranslated(0, 0, ARROW_CYLINDER_PORTION * distance);

    gl.glRotatef(180, 1, 0, 0);
    glu.gluDisk(quadObj, 0, aWidth * 2.0, 10, 10);
    gl.glRotatef(180, 1, 0, 0);

    glu.gluCylinder(quadObj, aWidth * 2.0, 0.0, distance * ARRROW_CONE_PORTION, 10, 10);

    // delete our quadric object
    glu.gluDeleteQuadric(quadObj);

    gl.glPopMatrix();
  }
 private static final GLUgl2ProcAddressTable getGLUProcAddressTable() {
   if (gluProcAddressTable == null) {
     GLContext curContext = GLContext.getCurrent();
     if (curContext == null) {
       throw new GLException("No OpenGL context current on this thread");
     }
     GLDynamicLookupHelper glLookupHelper =
         ((GLContextImpl) curContext).getGLDynamicLookupHelper();
     glLookupHelper.loadGLULibrary();
     GLUgl2ProcAddressTable tmp = new GLUgl2ProcAddressTable(new GLProcAddressResolver());
     tmp.reset(glLookupHelper);
     gluProcAddressTable = tmp;
   }
   return gluProcAddressTable;
 }
Esempio n. 5
0
  /**
   * Draw a line-based box with sides parallel to the x-y-z axes.
   *
   * @param aXMin
   * @param aXMax
   * @param aYMin
   * @param aYMax
   * @param aZMin
   * @param aZMax
   */
  public static void jDrawWireBox(
      final double aXMin,
      final double aXMax,
      final double aYMin,
      final double aYMax,
      final double aZMin,
      final double aZMax) {

    GL2 gl = GLContext.getCurrent().getGL().getGL2();
    // render lines for each edge of the box
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3d(aXMin, aYMin, aZMin);
    gl.glVertex3d(aXMax, aYMin, aZMin);
    gl.glVertex3d(aXMin, aYMax, aZMin);
    gl.glVertex3d(aXMax, aYMax, aZMin);
    gl.glVertex3d(aXMin, aYMin, aZMax);
    gl.glVertex3d(aXMax, aYMin, aZMax);
    gl.glVertex3d(aXMin, aYMax, aZMax);
    gl.glVertex3d(aXMax, aYMax, aZMax);

    gl.glVertex3d(aXMin, aYMin, aZMin);
    gl.glVertex3d(aXMin, aYMax, aZMin);
    gl.glVertex3d(aXMax, aYMin, aZMin);
    gl.glVertex3d(aXMax, aYMax, aZMin);
    gl.glVertex3d(aXMin, aYMin, aZMax);
    gl.glVertex3d(aXMin, aYMax, aZMax);
    gl.glVertex3d(aXMax, aYMin, aZMax);
    gl.glVertex3d(aXMax, aYMax, aZMax);

    gl.glVertex3d(aXMin, aYMin, aZMin);
    gl.glVertex3d(aXMin, aYMin, aZMax);
    gl.glVertex3d(aXMax, aYMin, aZMin);
    gl.glVertex3d(aXMax, aYMin, aZMax);
    gl.glVertex3d(aXMin, aYMax, aZMin);
    gl.glVertex3d(aXMin, aYMax, aZMax);
    gl.glVertex3d(aXMax, aYMax, aZMin);
    gl.glVertex3d(aXMax, aYMax, aZMax);
    gl.glEnd();
  }
Esempio n. 6
0
  /**
   * //! Draw an x-y-z frame.
   *
   * @param aAxisLengthScale
   * @param aAxisThicknessScale
   * @param aModifyMaterialState
   */
  public static void jDrawFrame(
      final double aAxisLengthScale,
      final double aAxisThicknessScale,
      final boolean aModifyMaterialState) {
    // Triangle vertices:
    int nTriangles = 8;

    // Quad vertices:
    int nQuads = 16;

    GL2 gl = GLContext.getCurrent().getGL().getGL2();
    // set material properties
    float[] fnull = {0, 0, 0, 0};
    gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, fnull, 0);
    gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, fnull, 0);
    gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);

    // enable vertex and normal arrays
    gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);

    if (aModifyMaterialState) {
      gl.glEnable(GL2.GL_COLOR_MATERIAL);
      gl.glColorMaterial(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE);
      gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL);
    }

    for (int k = 0; k < 3; k++) {
      gl.glPushMatrix();

      // Rotate to the appropriate axis
      if (k == 0) {
        gl.glRotatef(-90.0f, 0, 1, 0);
        gl.glColor3f(1.0f, 0.0f, 0.0f);
      } else if (k == 1) {
        gl.glRotatef(90.0f, 1, 0, 0);
        gl.glColor3f(0.0f, 1.0f, 0.0f);
      } else {
        gl.glRotatef(180.0f, 1, 0, 0);
        gl.glColor3f(0.0f, 0.0f, 1.0f);
      }

      // scaling
      gl.glScaled(aAxisThicknessScale, aAxisThicknessScale, aAxisLengthScale);

      // render frame object

      gl.glVertexPointer(3, GL2.GL_FLOAT, 0, triVerticesBuffer);
      gl.glNormalPointer(GL2.GL_FLOAT, 0, triNormalsBuffer);

      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, nTriangles * 3);

      gl.glVertexPointer(3, GL2.GL_FLOAT, 0, quadVerticesBuffer);
      gl.glNormalPointer(GL2.GL_FLOAT, 0, quadNormalsBuffer);

      gl.glDrawArrays(GL2.GL_QUADS, 0, nQuads * 4);

      gl.glPopMatrix();
    }

    // disable vertex and normal arrays
    gl.glDisableClientState(GL2.GL_NORMAL_ARRAY);
    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
  }