@Override
 public void init(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   //		java.nio.IntBuffer maxlights = Buffers.newDirectIntBuffer(1);
   int[] maxlights = new int[1];
   gl.glGetIntegerv(GL2.GL_MAX_LIGHTS, maxlights, 0);
   System.out.println(maxlights[0]);
   // 背景を白く塗りつぶす.
   gl.glClearColor(1f, 1f, 1f, 1.0f);
   gl.glEnable(GL_DEPTH_TEST);
   gl.glEnable(GL_CULL_FACE);
   gl.glCullFace(GL_FRONT);
   gl.glEnable(GL_LIGHTING);
   gl.glEnable(GL_LIGHT0);
   gl.glEnable(GL_LIGHT1);
   //		gl.glLightfv(GL_LIGHT1, GL_DIFFUSE, green, 0);
   //		gl.glLightfv(GL_LIGHT1, GL_SPECULAR, green, 0);
 }
示例#2
0
文件: MemLogger.java 项目: pnnl/svf
 @Override
 public void draw(final GL2 gl, final GLUgl2 glu, final Camera camera) {
   if (vendor == Vendor.ERROR) {
     return;
   }
   final int[] values = new int[] {NO_VALUE, NO_VALUE};
   // try nvidia first
   if (vendor == Vendor.NVIDIA || vendor == Vendor.NONE) {
     try {
       gl.glGetIntegerv(GL_TOTAL_AVAILABLE_MEM, values, 0);
       gl.glGetIntegerv(GL_CURRENT_AVAILABLE_MEM, values, 1);
       if (values[1] >= 0) {
         vendor = Vendor.NVIDIA;
       }
     } catch (final GLException ex) {
       // failed to get values
       DebugUtil.clearGLErrors(gl);
       // error will be logged when values are not assigned
       values[0] = ERROR_VALUE;
       values[1] = ERROR_VALUE;
     }
   }
   // try amd/ati
   if (vendor == Vendor.AMD || vendor == Vendor.NONE) {
     try {
       if (vendor == Vendor.NONE) {
         if (gl instanceof WGLExt) {
           final WGLExt wgl = (WGLExt) gl;
           final int gpuCount = wgl.wglGetGPUIDsAMD(0, null);
           final int[] gpuIds = new int[gpuCount];
           final IntBuffer totalMem = IntBuffer.allocate(1);
           for (int i = 0; i < gpuIds.length; i++) {
             wgl.wglGetGPUInfoAMD(
                 gpuIds[i], WGLExt.WGL_GPU_RAM_AMD, GL2.GL_UNSIGNED_INT, 1, totalMem);
             values[0] = Math.max(values[0], totalMem.get(0));
           }
         }
       } else {
         synchronized (this) {
           values[0] = totalAvailableMem;
         }
       }
       gl.glGetIntegerv(GL2.GL_TEXTURE_FREE_MEMORY_ATI, values, 1);
       if (values[1] >= 0) {
         vendor = Vendor.AMD;
       }
     } catch (final GLException ex) {
       // failed to get values
       DebugUtil.clearGLErrors(gl);
       // error will be logged when values are not assigned
       values[0] = ERROR_VALUE;
       values[1] = ERROR_VALUE;
     }
   }
   // catch errors
   if (vendor == Vendor.NONE && values[0] < 0 || values[1] < 0) {
     vendor = Vendor.ERROR;
   }
   synchronized (this) {
     totalAvailableMem = values[0];
     currentAvailableMem = values[1];
   }
 }
示例#3
0
  @Override
  public void draw(final GL2 gl, final boolean picking) {
    JOGLRenderer renderer = drawer.getRenderer();
    gl.glColor3d(1.0, 1.0, 1.0);
    if (picking) {
      if (renderer.colorPicking) {
        gl.glDisable(GL.GL_DITHER);
        gl.glDisable(GLLightingFunc.GL_LIGHTING);
        gl.glDisable(GL.GL_TEXTURE);

        int viewport[] = new int[4];
        gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);

        FloatBuffer pixels = FloatBuffer.allocate(4);
        gl.glReadPixels(
            renderer.camera.getLastMousePressedPosition().x,
            viewport[3] - renderer.camera.getLastMousePressedPosition().y,
            1,
            1,
            GL.GL_RGBA,
            GL.GL_FLOAT,
            pixels);

        gl.glEnable(GL.GL_DITHER);
        gl.glEnable(GLLightingFunc.GL_LIGHTING);
        gl.glEnable(GL.GL_TEXTURE);

        // Color index = new Color(pixels.get(0), pixels.get(1), pixels.get(2));
        // System.out.println("color picked " + index.toString());
      } else {
        gl.glPushMatrix();
        gl.glInitNames();
        gl.glPushName(0);
        double alpha = 0d;
        int size = objects.size();
        double delta = size == 0 ? 0 : 1d / size;
        for (final List<T> list : objects) {
          alpha = alpha + delta;
          for (T object : list) {
            if (isFading) {
              double originalAlpha = object.getAlpha();
              object.setAlpha(originalAlpha * alpha);
              object.draw(gl, drawer, picking);
              object.setAlpha(originalAlpha);
            } else {
              object.draw(gl, drawer, picking);
            }
          }
        }

        gl.glPopName();
        gl.glPopMatrix();
      }
    } else if (drawAsList) {
      Integer index = openGLListIndex;
      if (index == null) {

        index = gl.glGenLists(1);
        gl.glNewList(index, GL2.GL_COMPILE);
        double alpha = 0d;
        int size = objects.size();
        double delta = size == 0 ? 0 : 1d / size;
        for (final List<T> list : objects) {
          alpha = alpha + delta;
          for (T object : list) {
            if (isFading) {
              double originalAlpha = object.getAlpha();
              object.setAlpha(originalAlpha * alpha);
              object.draw(gl, drawer, picking);
              object.setAlpha(originalAlpha);
            } else {
              object.draw(gl, drawer, picking);
            }
          }
        }
        gl.glEndList();
      }
      gl.glCallList(index);
      openGLListIndex = index;
    } else if (drawAsVBO) {
      if (vah == null) {
        GLU glu = renderer.getGlu();
        vah = new VertexArrayHandler(gl, glu, renderer);
        vah.buildVertexArray(getObjects());
      } else {
        // vah.loadCollada(null);
      }

    } else {
      for (final T object : getObjects()) {
        object.draw(gl, drawer, picking);
      }
    }
  }