public void draw() {
    // Clear GL state
    gl.glDisable(GL_LIGHTING);
    gl.glDisable(GL_DEPTH);
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f);

    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glPointSize(1.0f);

    // Set the viewport
    glu.gluOrtho2D(xMin, xMax, yMin, yMax);

    gl.glBegin(GL_POINTS);

    for (int x = (int) (xMin); x < xMax; x++)
      for (int y = (int) (yMin); y < yMax; y++) {
        gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b);
        gl.glVertex2d(x + 0.5, y + 0.5);
      }

    gl.glEnd();

    // Restore state
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glPopMatrix();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glPopMatrix();

    gl.glEnable(GL_LIGHTING);
    gl.glEnable(GL_DEPTH);
  }
Esempio n. 2
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);
      }
    }
  }