Example #1
0
  /** paint the portal using gl. */
  public void paint(GL gl, GLDrawable glc) {

    if (fill != null) {
      setColor(gl, fill);
      gl.glDisable(GL.GL_TEXTURE_2D);
    }
    gl.glLineWidth(lineWidth());
    gl.glBegin(GL.GL_LINES); // draw each wall
    for (int i = 0; i < pts2d.size(); i++) {
      Point2D p = (Point2D) (pts2d.get(i));
      gl.glVertex2d(p.x, p.y);
    }
    gl.glEnd();

    if (pts2d.size() == 4) {
      /* Connect mid point of the two line segments with dotted line*/
      gl.glLineStipple(1, (short) 0x0F0F);
      gl.glEnable(GL.GL_LINE_STIPPLE);
      gl.glLineWidth(1);
      gl.glBegin(GL.GL_LINES);
      Point2D mid = pts2d.get(0).interp(pts2d.get(1), 0.5);
      gl.glVertex2d(mid.x, mid.y);
      mid = pts2d.get(2).interp(pts2d.get(3), 0.5);
      gl.glVertex2d(mid.x, mid.y);
      gl.glEnd();
      gl.glDisable(GL.GL_LINE_STIPPLE);
    }
  }
Example #2
0
  private void renderPin(GL gl, Coordinates position, float[] color, float size) {
    float height = heightmap.getHeight(projection.getGeoCoordinates(position));
    gl.glPushMatrix();
    double[] model = new double[16];
    gl.glGetDoublev(GL_MODELVIEW_MATRIX, model, 0);
    double zoomH =
        0.1 / Math.sqrt((model[0] * model[0]) + (model[1] * model[1]) + (model[2] * model[2]));
    double zoomZ =
        0.1 / Math.sqrt((model[8] * model[8]) + (model[9] * model[9]) + (model[10] * model[10]));
    gl.glTranslatef(position.getLongitude(), position.getLatitude(), height);
    gl.glScaled(zoomH * size, zoomH * size, zoomZ * size);
    gl.glDisable(GL_TEXTURE_2D);

    gl.glRotatef(20, 0.3f, 1, 0);

    GLU glu = new GLU();
    GLUquadric quadric = glu.gluNewQuadric();
    // glu.gluQuadricNormals(quadric, GLU.GLU_FLAT);
    gl.glColor3f(0.5f, 0.5f, 0.5f);
    gl.glEnable(GL_LIGHTING);
    glu.gluCylinder(quadric, 0.03, 0.03, 0.6f, 5, 1);
    gl.glTranslatef(0, 0, 0.6f);

    gl.glColor3f(color[0], color[1], color[2]);
    gl.glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glu.gluSphere(quadric, 0.12, 8, 8);
    // glu.gluCylinder(quadric, 0.2, 0.1, 0.5, 8, 1);
    gl.glDisable(GL_LIGHTING);
    glu.gluDeleteQuadric(quadric);
    gl.glPopMatrix();
  }
  /** Applies fixed function bindings from the context to OpenGL */
  private void applyFixedFuncBindings(boolean forLighting) {
    GL gl = GLContext.getCurrentGL();
    if (forLighting) {
      gl.getGL2().glMaterialf(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_SHININESS, context.shininess);
      setMaterialColor(GLLightingFunc.GL_AMBIENT, context.ambient, ColorRGBA.DarkGray);
      setMaterialColor(GLLightingFunc.GL_DIFFUSE, context.diffuse, ColorRGBA.White);
      setMaterialColor(GLLightingFunc.GL_SPECULAR, context.specular, ColorRGBA.Black);

      if (context.useVertexColor) {
        gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL);
      } else {
        gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL);
      }
    } else {
      // Ignore other values as they have no effect when
      // GL_LIGHTING is disabled.
      ColorRGBA color = context.color;
      if (color != null) {
        gl.getGL2().glColor4f(color.r, color.g, color.b, color.a);
      } else {
        gl.getGL2().glColor4f(1, 1, 1, 1);
      }
    }
    if (context.alphaTestFallOff > 0f) {
      gl.glEnable(GL2ES1.GL_ALPHA_TEST);
      gl.getGL2ES1().glAlphaFunc(GL.GL_GREATER, context.alphaTestFallOff);
    } else {
      gl.glDisable(GL2ES1.GL_ALPHA_TEST);
    }
  }
Example #4
0
File: Mesa.java Project: Gubetti/N4
  public void desenhar(GL gl, GLUT glut) {
    gl.glShadeModel(GL.GL_FLAT);
    gl.glNormal3f(0.0f, 0.0f, 1.0f);
    gl.glColor3f(1f, 1f, 1f);

    float corWhite[] = {1.0f, 1.0f, 1.0f, 1.0f};

    // base
    setTexture(Util.loadImage("texture/textureBrick.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, corWhite, 0);
    gl.glEnable(GL.GL_LIGHTING);
    gl.glPushMatrix();
    gl.glTranslatef(0f, -dif, 0f);
    gl.glScalef(getxEscala(), getyEscala(), getzEscala());
    glut.glutSolidCube(1f);
    gl.glPopMatrix();

    // esquerda
    setTexture(Util.loadImage("texture/tijolos/medio2.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glPushMatrix();
    gl.glTranslatef(-(getxEscala() / 2), (getAltura() / 2) - dif, 0f);
    gl.glScalef(0.1f, getAltura(), getzEscala());
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
    gl.glDisable(GL.GL_LIGHTING);

    // direita
    setTexture(Util.loadImage("texture/tijolos/medio2.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glPushMatrix();
    gl.glTranslatef(getxEscala() / 2, (getAltura() / 2) - dif, 0f);
    gl.glScalef(0.1f, getAltura(), getzEscala());
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
    gl.glDisable(GL.GL_LIGHTING);

    // fundo
    setTexture(Util.loadImage("texture/tijolos/fraco.png"));
    getTexture().enable();
    getTexture().bind();
    gl.glPushMatrix();
    gl.glTranslatef(0f, (getAltura() / 2) - dif, -(getzEscala() / 2));
    gl.glScalef(getxEscala(), getAltura(), 0.1f);
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
    gl.glDisable(GL.GL_LIGHTING);
  }
  /**
   * Establish the OpenGL state needed to draw text.
   *
   * @param dc the current draw context.
   */
  protected void beginDrawing(DrawContext dc) {
    GL gl = dc.getGL();

    int attrMask =
        GL.GL_DEPTH_BUFFER_BIT // for depth test, depth mask and depth func
            | GL.GL_TRANSFORM_BIT // for modelview and perspective
            | GL.GL_VIEWPORT_BIT // for depth range
            | GL.GL_CURRENT_BIT // for current color
            | GL.GL_COLOR_BUFFER_BIT // for alpha test func and ref, and blend
            | GL.GL_DEPTH_BUFFER_BIT // for depth func
            | GL.GL_ENABLE_BIT; // for enable/disable changes

    this.BEogsh.pushAttrib(gl, attrMask);

    if (!dc.isPickingMode()) {
      gl.glEnable(GL.GL_BLEND);
      OGLUtil.applyBlending(gl, false);
    }

    // Do not depth buffer the label. (Labels beyond the horizon are culled above.)
    gl.glDisable(GL.GL_DEPTH_TEST);
    gl.glDepthMask(false);

    // The image is drawn using a parallel projection.
    this.BEogsh.pushProjectionIdentity(gl);
    gl.glOrtho(
        0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);

    this.BEogsh.pushModelviewIdentity(gl);
  }
  public void updateSelectedOctant(GL gl, GLU glu, float[] mousePosition, float[] pickRectangle) {
    // Start Picking mode
    int capacity =
        1 * 4 * visibleLeaves.size(); // Each object take in maximium : 4 * name stack depth
    IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity);

    gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
    gl.glRenderMode(GL.GL_SELECT);
    gl.glDisable(GL.GL_CULL_FACE); // Disable flags

    gl.glInitNames();
    gl.glPushName(0);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    glu.gluPickMatrix(
        mousePosition[0],
        mousePosition[1],
        pickRectangle[0],
        pickRectangle[1],
        drawable.getViewport());
    gl.glMultMatrixd(drawable.getProjectionMatrix());

    gl.glMatrixMode(GL.GL_MODELVIEW);

    // Draw the nodes' cube int the select buffer
    int hitName = 1;
    for (int i = 0; i < visibleLeaves.size(); i++) {
      Octant node = visibleLeaves.get(i);
      gl.glLoadName(hitName);
      node.displayOctant(gl);
      hitName++;
    }

    // Restoring the original projection matrix
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glFlush();

    // Returning to normal rendering mode
    int nbRecords = gl.glRenderMode(GL.GL_RENDER);
    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }

    // Clean previous selection
    selectedLeaves.clear();

    // Get the hits and put the node under selection in the selectionArray
    for (int i = 0; i < nbRecords; i++) {
      int hit = hitsBuffer.get(i * 4 + 3) - 1; // -1 Because of the glPushName(0)

      Octant nodeHit = visibleLeaves.get(hit);
      selectedLeaves.add(nodeHit);
    }
  }
  @Override
  public void display(GLContext context) {
    initializeNewMembers(context, true);
    validateLayout(context);
    validateListenerShapes(context);

    Rectangle b = getBounds();
    if (b.width == 0 || b.height == 0) return;

    GL gl = context.getGL();
    try {
      gl.glEnable(GL.GL_SCISSOR_TEST);

      // TODO: scissor so as not to overrun the parent viewport
      // TODO: reconcile viewport with GLGlimpseListener viewport call
      gl.glViewport(b.x, b.y, b.width, b.height);
      gl.glScissor(b.x, b.y, b.width, b.height);

      for (Member m : members) {
        if (m.callback != null) m.callback.preDisplay(m.listener, context, isHovered());

        m.listener.display(context);

        if (m.callback != null) m.callback.postDisplay(m.listener, context, isHovered());
      }
    } finally {
      gl.glDisable(GL.GL_SCISSOR_TEST);
    }
  }
Example #8
0
  public void render3D(GL gl, GLDrawable glc) {
    if (pts2d.size() < 4) return;
    if (fill != null || texture != null) {
      if (texture == null) {
        setColor(gl, fill);
        gl.glDisable(GL.GL_TEXTURE_2D);
      } else {
        setColor(gl, Color.white);
        Texture gltexture = texture.getTexture(glc);
        gltexture.enable();
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
        gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
        gltexture.bind();
      }
      gl.glPushMatrix();

      // get 4 control points of portal
      Point2D p0 = pts2d.get(0);
      Point2D p1 = pts2d.get(1);
      Point2D p2 = pts2d.get(2);
      Point2D p3 = pts2d.get(3);

      // render 1st side of portal with height extra[0]
      renderOneside(p0, p1, gl, extra[0]);

      // render 1st side of portal with height extra[1]
      renderOneside(p2, p3, gl, extra[1]);

      gl.glPopMatrix();
    }
  }
Example #9
0
  public void renderBox(GL gl) {
    gl.glDisable(GL_TEXTURE_2D);
    int c1 = Math.abs(this.hashCode()) % 256;
    int c2 = Math.abs(getImage().hashCode()) % 256;
    gl.glColor4f(c1 / 256f, c2 / 256f, ((c1 + c2) * 34) % 256 / 256f, 0.3f);
    gl.glPushMatrix();
    gl.glTranslatef(bounds.getLeft(), bounds.getTop(), minHeight);
    gl.glScalef(bounds.getWidth(), bounds.getHeight(), maxHeight - minHeight);
    gl.glBegin(GL_QUADS);
    gl.glVertex3f(0, 0, 0);
    gl.glVertex3f(0, 1, 0);
    gl.glVertex3f(1, 1, 0);
    gl.glVertex3f(1, 0, 0);

    gl.glVertex3f(0, 0, 1);
    gl.glVertex3f(0, 1, 1);
    gl.glVertex3f(1, 1, 1);
    gl.glVertex3f(1, 0, 1);
    gl.glEnd();
    gl.glColor4f(1, 1, 0, 0.2f);
    gl.glBegin(GL_QUAD_STRIP);
    gl.glVertex3f(0, 0, 0);
    gl.glVertex3f(0, 0, 1);
    gl.glVertex3f(0, 1, 0);
    gl.glVertex3f(0, 1, 1);
    gl.glVertex3f(1, 1, 0);
    gl.glVertex3f(1, 1, 1);
    gl.glVertex3f(1, 0, 0);
    gl.glVertex3f(1, 0, 1);
    gl.glVertex3f(0, 0, 0);
    gl.glVertex3f(0, 0, 1);
    gl.glEnd();
    gl.glPopMatrix();
  }
 private void clearTextureUnits() {
   Image[] textures = context.boundTextures;
   if (textures[0] != null) {
     GL gl = GLContext.getCurrentGL();
     gl.glDisable(GL.GL_TEXTURE_2D);
     textures[0] = null;
   }
 }
Example #11
0
 void glow() {
   final PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
   final GL openGL = pgl.beginGL();
   openGL.glDisable(GL.GL_DEPTH_TEST);
   openGL.glEnable(GL.GL_BLEND);
   openGL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
   pgl.endGL();
 }
Example #12
0
  /**
   * Renders the tile to the given context, in the process building all needed resources.
   *
   * @param gl
   */
  public void render(GL gl) {
    projection = ProjectionFactory.getCurrentProjection();
    heightmap = State.getInstance().getLoadedHeightmap();

    // BUILD TEXTURES IF NECESSARY
    if (!gl.glIsTexture(textureID)) {
      textureID = createTexture(gl, getImage(), false);
      // prerenderToTexture(gl);
    }
    if (!gl.glIsTexture(grainTextureID)) {
      createGrainTexture(gl);
    }
    // RENDER TILE FROM DISPLAY LIST, OR ELSE BUILD DISPLAY LIST
    if (gl.glIsList(displaylistID)) {
      gl.glCallList(displaylistID);
    } else {
      displaylistID = gl.glGenLists(1);
      gl.glNewList(displaylistID, GL_COMPILE_AND_EXECUTE);
      gl.glActiveTexture(GL_TEXTURE0);
      gl.glEnable(GL_TEXTURE_2D);
      gl.glBindTexture(GL_TEXTURE_2D, grainTextureID);
      gl.glActiveTexture(GL_TEXTURE1);
      gl.glEnable(GL_TEXTURE_2D);
      gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
      gl.glBindTexture(GL_TEXTURE_2D, textureID);

      gl.glColor3f(1, 1, 1);
      float[] color = new float[3];
      float hRes = HEIGHT_RESOLUTION - 1;
      float stepSize = bounds.getWidth() / hRes;
      Coordinates pos = new Coordinates();
      for (int x = 0; x < hRes; x++) {
        gl.glBegin(GL_TRIANGLE_STRIP);
        for (int y = 0; y <= hRes; y++) {
          for (int i = 0; i < 2; i++) {
            pos.setLatitude(bounds.getTop() + y * stepSize);
            pos.setLongitude(bounds.getLeft() + (x + i) * stepSize);
            gl.glMultiTexCoord2f(
                GL_TEXTURE0, (x + i) / (float) GRAIN_RESOLUTION, y / (float) GRAIN_RESOLUTION);
            gl.glMultiTexCoord2f(GL_TEXTURE1, (x + i) / hRes, y / hRes);
            float height = heights[x + HEIGHT_BORDER + i][y + HEIGHT_BORDER];
            getHeightColor(color, height);
            float shade = getShade(x + i, y, stepSize);
            gl.glColor3f(color[0] * shade, color[1] * shade, color[2] * shade);
            gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), height);
          }
        }
        gl.glEnd();
      }
      gl.glDisable(GL_TEXTURE_2D);
      gl.glActiveTexture(GL_TEXTURE0);
      renderPOIs(gl);
      gl.glEndList();
    }
  }
  private void enableFog(boolean enable, FogStateRecord record) {
    final GL gl = GLU.getCurrentGL();

    if (record.isValid()) {
      if (enable && !record.enabled) {
        gl.glEnable(GL.GL_FOG);
        record.enabled = true;
      } else if (!enable && record.enabled) {
        gl.glDisable(GL.GL_FOG);
        record.enabled = false;
      }
    } else {
      if (enable) {
        gl.glEnable(GL.GL_FOG);
      } else {
        gl.glDisable(GL.GL_FOG);
      }
      record.enabled = enable;
    }
  }
  public void clearClipRect() {
    GL gl = GLContext.getCurrentGL();
    if (context.clipRectEnabled) {
      gl.glDisable(GL.GL_SCISSOR_TEST);
      context.clipRectEnabled = false;

      clipX = 0;
      clipY = 0;
      clipW = 0;
      clipH = 0;
    }
  }
Example #15
0
 void texsel(int id) {
   if (id != sh.curtex) {
     HavenPanel.texmiss++;
     if (id == -1) {
       gl.glDisable(GL.GL_TEXTURE_2D);
     } else {
       gl.glEnable(GL.GL_TEXTURE_2D);
       gl.glBindTexture(GL.GL_TEXTURE_2D, id);
     }
     sh.curtex = id;
   } else {
     HavenPanel.texhit++;
   }
 }
  public void updateVisibleOctant(GL gl) {
    // Limits
    refreshLimits();

    // Switch to OpenGL select mode
    int capacity = 1 * 4 * leaves.getCount(); // Each object take in maximium : 4 * name stack depth
    IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity);
    gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
    gl.glRenderMode(GL.GL_SELECT);
    gl.glInitNames();
    gl.glPushName(0);
    gl.glDisable(GL.GL_CULL_FACE); // Disable flags
    // Draw the nodes cube in the select buffer
    for (Octant n : leaves) {
      n
          .resetUpdatePositionFlag(); // Profit from the loop to do this, because this method is
                                      // always after updating position
      gl.glLoadName(n.getNumber());
      n.displayOctant(gl);
    }
    int nbRecords = gl.glRenderMode(GL.GL_RENDER);
    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }
    visibleLeaves.clear();

    // Get the hits and add the nodes' objects to the array
    int depth = Integer.MAX_VALUE;
    int minDepth = -1;
    for (int i = 0; i < nbRecords; i++) {
      int hit = hitsBuffer.get(i * 4 + 3); // -1 Because of the glPushName(0)
      int minZ = hitsBuffer.get(i * 4 + 1);
      if (minZ < depth) {
        depth = minZ;
        minDepth = hit;
      }

      Octant nodeHit = leaves.getItem(hit);
      visibleLeaves.add(nodeHit);
    }
    if (minDepth != -1) {
      Octant closestOctant = leaves.getItem(minDepth);
      Vec3f pos =
          new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ());
      limits.setClosestPoint(pos);
    }
    // System.out.println(minDepth);
  }
Example #17
0
  public void draw() {
    if (!isTiling) {
      psys.update(srcImage.getPixels(), dstImage.getPixels());
    }

    tiler.pre();

    background(0);

    srcImage.draw();
    //		dstImage.draw();

    // lights.
    if (isLightingEnabled) {
      gl.glEnable(GL.GL_LIGHTING);
      gl.glEnable(GL.GL_LIGHT1);
    } else {
      gl.glDisable(GL.GL_LIGHTING);
      gl.glDisable(GL.GL_LIGHT1);
    }

    // START DRAW.
    pgl.beginGL();
    gl.glPushMatrix();
    gl.glTranslatef(sceneCenterX, sceneCenterY, sceneCenterZ);
    drawSomething();
    gl.glPopMatrix();
    pgl.endGL();

    tiler.post();
    if (!tiler.checkStatus() && isTiling) {
      isTiling = false;
    }

    if (isRecording) save("export/image" + frameCount + ".png");
  }
  private void display(GL gl, GLU glu, final JoglFrameBufferObject theFBO) {
    final int w = theFBO.getPixelWidth();
    final int h = theFBO.getPixelHeight();

    /* bind position data */
    gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, _myVBO);
    gl.glVertexPointer(4, GL.GL_FLOAT, 0, 0);

    /* bind point size data */
    _myShaderManager.enable(_myPointSpriteShader);
    final int myPointSizeAttrib =
        gl.glGetAttribLocation(_myPointSpriteShader.getOpenGLID(), "vertexAttribute");
    gl.glEnableVertexAttribArray(myPointSizeAttrib);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, _myIBO);
    gl.glVertexAttribPointer(myPointSizeAttrib, 3, GL.GL_FLOAT, false, 0, 0);
    gl.glEnable(GL.GL_VERTEX_PROGRAM_POINT_SIZE_ARB);

    /* --- */
    final JoglFrameBufferObject READ_FBO = _myFBO;
    _myShaderManager.setUniform(
        _myPointSpriteShader,
        "textureVelocity",
        READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureUnit() - GL.GL_TEXTURE0);
    _myShaderManager.setUniform(_myPointSpriteShader, "velocityThreshold", velocity_threshold);
    _myShaderManager.setUniform(_myPointSpriteShader, "sizeThreshold", size_threshold);
    _myShaderManager.setUniform(_myPointSpriteShader, "pointSize", point_size);
    _myShaderManager.setUniform(_myPointSpriteShader, "flowdirection", flow_direction);
    _myShaderManager.setUniform(_myPointSpriteShader, "collisionratio", collision_ratio);

    gl.glActiveTexture(READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureUnit());
    gl.glBindTexture(
        READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureTarget(),
        READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureID());

    JoglUtil.printGLError(gl, glu, "binding texture", true);

    gl.glDrawArrays(GL.GL_POINTS, 0, w * h);

    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
    gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
    gl.glDisableVertexAttribArray(myPointSizeAttrib);
    _myShaderManager.disable();
    gl.glDisable(GL.GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
    gl.glBindTexture(READ_FBO.additional_texture(BufferInfo.SECONDARY).getTextureTarget(), 0);

    JoglUtil.printGLError(gl, glu, "display()", true);
  }
  public void displayOctree(GL gl, GLU glu) {
    gl.glDisable(GL.GL_CULL_FACE);
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
    for (Octant o : visibleLeaves) {
      gl.glColor3f(1, 0.5f, 0.5f);
      o.displayOctant(gl);
      o.displayOctantInfo(gl, glu);
    }
    if (!vizController.getVizConfig().isWireFrame()) {
      gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
    }

    if (vizController.getVizModel().isCulling()) {
      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);
    }
  }
Example #20
0
  /** The scene's implementation of the init method. */
  public void init(GLAutoDrawable drawable) {
    super.init(drawable);

    System.out.println("FlyingTextScene - init");

    final GL gl = drawable.getGL();

    // Create the text renderer
    renderer = new TextRenderer(new Font("Palatino Linotype", Font.TRUETYPE_FONT, 72), true);

    // Create the background texture
    BufferedImage bgImage = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g = bgImage.createGraphics();
    g.setColor(new Color(0.3f, 0.3f, 0.3f));
    g.fillRect(0, 0, 2, 2);
    g.setColor(new Color(0.7f, 0.7f, 0.7f));
    g.fillRect(0, 0, 1, 1);
    g.fillRect(1, 1, 1, 1);
    g.dispose();
    backgroundTexture = TextureIO.newTexture(bgImage, false);
    backgroundTexture.bind();
    backgroundTexture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
    backgroundTexture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    backgroundTexture.setTexParameteri(GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
    backgroundTexture.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

    width = glComposite.getCanvas().getWidth();
    height = glComposite.getCanvas().getHeight();

    // Compute maximum width of text we're going to draw to avoid
    // popping in/out at edges
    maxTextWidth = (int) renderer.getBounds("Java 2D").getWidth();
    maxTextWidth = Math.max(maxTextWidth, (int) renderer.getBounds("OpenGL").getWidth());

    // Create random text
    textInfo.clear();
    for (int i = 0; i < NUM_STRINGS; i++) {
      textInfo.add(randomTextInfo());
    }

    // Set up properties; note we don't need the depth buffer in this demo
    gl.glDisable(GL.GL_DEPTH_TEST);

    glComposite.initAnimator(drawable, 100);
  }
Example #21
0
  public void beginPicking(DrawContext dc) {
    javax.media.opengl.GL gl = dc.getGL();

    gl.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_CURRENT_BIT);

    gl.glDisable(GL.GL_DITHER);
    gl.glDisable(GL.GL_LIGHTING);
    gl.glDisable(GL.GL_FOG);
    gl.glDisable(GL.GL_BLEND);
    gl.glDisable(GL.GL_TEXTURE_2D);

    if (dc.isDeepPickingEnabled()) gl.glDisable(GL.GL_DEPTH_TEST);
  }
Example #22
0
  private void initOpenGL() {
    pgl = (PGraphicsOpenGL) g;
    gl = pgl.gl;
    gl.setSwapInterval(1);

    gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
    gl.glClearDepth(1.0f); // Depth Buffer Setup
    gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
    gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do
    gl.glHint(
        GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // Really Nice Perspective Calculations
    gl.glDisable(GL.GL_TEXTURE_2D);

    // Set up lighting
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmbient, 0);
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiffuse, 0);
    //      gl.glLightfv( GL.GL_LIGHT1, GL.GL_SPECULAR, lightSpecular, 0 );
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPosition, 0);
    gl.glEnable(GL.GL_LIGHTING);
    gl.glEnable(GL.GL_LIGHT1);
  }
Example #23
0
  protected void drawIcon(DrawContext dc) {
    if (this.getIconFilePath() == null) return;

    GL gl = dc.getGL();
    OGLStackHandler ogsh = new OGLStackHandler();

    try {
      // Initialize texture if necessary
      Texture iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath());
      if (iconTexture == null) {
        this.initializeTexture(dc);
        iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath());
        if (iconTexture == null) {
          String msg = Logging.getMessage("generic.ImageReadFailed");
          Logging.logger().finer(msg);
          return;
        }
      }
      gl.glDisable(GL.GL_DEPTH_TEST);

      double width = this.getScaledIconWidth();
      double height = this.getScaledIconHeight();

      // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
      // into the GL projection matrix.
      java.awt.Rectangle viewport = dc.getView().getViewport();
      ogsh.pushProjectionIdentity(gl);
      double maxwh = width > height ? width : height;
      gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

      // Translate and scale
      ogsh.pushModelviewIdentity(gl);
      double scale = this.computeScale(viewport);
      Vec4 locationSW = this.computeLocation(viewport, scale);
      gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
      // Scale to 0..1 space
      gl.glScaled(scale, scale, 1);
      gl.glScaled(width, height, 1d);

      if (!dc.isPickingMode()) {
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

        // Draw background color behind the map
        gl.glColor4ub(
            (byte) this.backColor.getRed(),
            (byte) this.backColor.getGreen(),
            (byte) this.backColor.getBlue(),
            (byte) (this.backColor.getAlpha() * this.getOpacity()));
        dc.drawUnitQuad();

        // Draw world map icon
        gl.glColor4d(1d, 1d, 1d, this.getOpacity());
        gl.glEnable(GL.GL_TEXTURE_2D);
        iconTexture.bind();

        TextureCoords texCoords = iconTexture.getImageTexCoords();
        dc.drawUnitQuad(texCoords);
        gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
        gl.glDisable(GL.GL_TEXTURE_2D);

        // Draw crosshair for current location
        gl.glLoadIdentity();
        gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
        // Scale to width x height space
        gl.glScaled(scale, scale, 1);
        // Set color
        float[] colorRGB = this.color.getRGBColorComponents(null);
        gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity());

        // Draw crosshair
        Position groundPos = this.computeGroundPosition(dc, dc.getView());
        if (groundPos != null) {
          int x = (int) (width * (groundPos.getLongitude().degrees + 180) / 360);
          int y = (int) (height * (groundPos.getLatitude().degrees + 90) / 180);
          int w = 10; // cross branch length
          // Draw
          gl.glBegin(GL.GL_LINE_STRIP);
          gl.glVertex3d(x - w, y, 0);
          gl.glVertex3d(x + w + 1, y, 0);
          gl.glEnd();
          gl.glBegin(GL.GL_LINE_STRIP);
          gl.glVertex3d(x, y - w, 0);
          gl.glVertex3d(x, y + w + 1, 0);
          gl.glEnd();
        }

        // Draw view footprint in map icon space
        if (this.showFootprint) {
          this.footPrintPositions = this.computeViewFootPrint(dc, 32);
          if (this.footPrintPositions != null) {
            gl.glBegin(GL.GL_LINE_STRIP);
            LatLon p1 = this.footPrintPositions.get(0);
            for (LatLon p2 : this.footPrintPositions) {
              int x = (int) (width * (p2.getLongitude().degrees + 180) / 360);
              int y = (int) (height * (p2.getLatitude().degrees + 90) / 180);
              // Draw
              if (LatLon.locationsCrossDateline(p1, p2)) {
                int y1 = (int) (height * (p1.getLatitude().degrees + 90) / 180);
                gl.glVertex3d(x < width / 2 ? width : 0, (y1 + y) / 2, 0);
                gl.glEnd();
                gl.glBegin(GL.GL_LINE_STRIP);
                gl.glVertex3d(x < width / 2 ? 0 : width, (y1 + y) / 2, 0);
              }
              gl.glVertex3d(x, y, 0);
              p1 = p2;
            }
            gl.glEnd();
          }
        }
        // Draw 1px border around and inside the map
        gl.glBegin(GL.GL_LINE_STRIP);
        gl.glVertex3d(0, 0, 0);
        gl.glVertex3d(width, 0, 0);
        gl.glVertex3d(width, height - 1, 0);
        gl.glVertex3d(0, height - 1, 0);
        gl.glVertex3d(0, 0, 0);
        gl.glEnd();
      } else {
        // Picking
        this.pickSupport.clearPickList();
        this.pickSupport.beginPicking(dc);
        // Where in the world are we picking ?
        Position pickPosition =
            computePickPosition(
                dc, locationSW, new Dimension((int) (width * scale), (int) (height * scale)));
        Color color = dc.getUniquePickColor();
        int colorCode = color.getRGB();
        this.pickSupport.addPickableObject(colorCode, this, pickPosition, false);
        gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
        dc.drawUnitQuad();
        this.pickSupport.endPicking(dc);
        this.pickSupport.resolvePick(dc, dc.getPickPoint(), this);
      }
    } finally {
      dc.restoreDefaultDepthTesting();
      dc.restoreDefaultCurrentColor();
      if (dc.isPickingMode()) dc.restoreDefaultBlending();
      ogsh.pop(gl);
    }
  }
Example #24
0
 public void disableAlpha() {
   gl.glDisable(GL.GL_ALPHA);
   gl.glDisable(GL.GL_BLEND);
 }
Example #25
0
  public void disableTexture() {
    currentTexture = null;

    gl.glDisable(GL.GL_TEXTURE_2D);
  }
Example #26
0
  public void display(GLCanvas canvas) {
    GL gl = canvas.getGL();

    //
    // render the simulation
    //
    try {
      sim.update();
    } catch (Exception e) {
      Log.println("[Editor] exception in simulation update/calculate paths: " + e.getMessage());
      e.printStackTrace();
    }
    renderer.render(sim, canvas);

    //
    // render the grid
    //
    gl.glColor4f(0.4f, 0.4f, 0.4f, 0.4f);
    gl.glEnable(GL.GL_BLEND);
    gl.glBegin(GL.GL_LINES);
    for (int x = 0; x < 100; x++) {
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4);
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4,
          50 * Constants.PLANET_MAX_SIZE * 4);
    }

    for (int x = 0; x < 100; x++) {
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4);
      gl.glVertex2f(
          +50 * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4);
    }
    gl.glDisable(GL.GL_BLEND);
    gl.glEnd();

    //
    // render rectangle selection
    //
    if (drag_start != null && drag_end != null && selected_planets.size() == 0) {
      gl.glLineWidth(2);
      gl.glColor4f(1, 1, 1, 1);
      Widget.renderOutlinedQuad(
          drag_start.x, drag_start.y, drag_end.x - drag_start.x, -(drag_end.y - drag_start.y));
      gl.glLineWidth(1);
    }

    //
    // render reference system
    //
    gl.glColor3f(1, 1, 1);
    gl.glBegin(GL.GL_LINES);
    gl.glColor3f(1, 0, 0);
    gl.glVertex2f(Constants.PLANET_MAX_SIZE * 50, 0);
    gl.glVertex2f(-Constants.PLANET_MAX_SIZE * 50, 0);
    gl.glColor3f(0, 1, 0);
    gl.glVertex2f(0, Constants.PLANET_MAX_SIZE * 50);
    gl.glVertex2f(0, -Constants.PLANET_MAX_SIZE * 50);
    gl.glEnd();

    try {
      Thread.sleep(5);
    } catch (InterruptedException e) {
    }

    //
    // check mouse over planet
    //
    if (sim.getPlanet(
                renderer.getCamera().getScreenToWorldX(mouse_pos.x),
                renderer.getCamera().getScreenToWorldY(mouse_pos.y))
            != null
        && !this.wasGuiIntersected(mouse_pos.x, mouse_pos.y)
        && drag_start != null) for (WorldAlignementContainer cont : conts) cont.setVisible(false);
    else for (WorldAlignementContainer cont : conts) cont.setVisible(true);
  }
  public static void apply(final JoglRenderer renderer, final VertexProgramState state) {
    final GL gl = GLU.getCurrentGL();
    final RenderContext context = ContextManager.getCurrentContext();
    final ContextCapabilities caps = context.getCapabilities();

    if (caps.isVertexProgramSupported()) {
      // ask for the current state record
      final VertexProgramStateRecord record =
          (VertexProgramStateRecord) context.getStateRecord(StateType.VertexProgram);
      context.setCurrentState(StateType.VertexProgram, state);

      if (!record.isValid() || record.getReference() != state) {
        record.setReference(state);
        if (state.isEnabled()) {
          // Vertex program not yet loaded
          if (state._getProgramID() == -1) {
            if (state.getProgramAsBuffer() != null) {
              final int id = create(state.getProgramAsBuffer());
              state._setProgramID(id);
            } else {
              return;
            }
          }

          gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
          gl.glBindProgramARB(GL.GL_VERTEX_PROGRAM_ARB, state._getProgramID());

          // load environmental parameters...
          for (int i = 0; i < VertexProgramState._getEnvParameters().length; i++) {
            if (VertexProgramState._getEnvParameters()[i] != null) {
              gl.glProgramEnvParameter4fARB(
                  GL.GL_VERTEX_PROGRAM_ARB,
                  i,
                  VertexProgramState._getEnvParameters()[i][0],
                  VertexProgramState._getEnvParameters()[i][1],
                  VertexProgramState._getEnvParameters()[i][2],
                  VertexProgramState._getEnvParameters()[i][3]);
            }
          }

          // load local parameters...
          if (state.isUsingParameters()) {
            // no parameters are used
            for (int i = 0; i < state._getParameters().length; i++) {
              if (state._getParameters()[i] != null) {
                gl.glProgramLocalParameter4fARB(
                    GL.GL_VERTEX_PROGRAM_ARB,
                    i,
                    state._getParameters()[i][0],
                    state._getParameters()[i][1],
                    state._getParameters()[i][2],
                    state._getParameters()[i][3]);
              }
            }
          }

        } else {
          gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
        }
      }

      if (!record.isValid()) {
        record.validate();
      }
    }
  }
Example #28
0
  public void display(GLAutoDrawable glDrawable) {
    GL gl = glDrawable.getGL();

    // Store old matrices
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glViewport(0, 0, glDrawable.getWidth(), glDrawable.getHeight());

    // Store enabled state and disable lighting, texture mapping and the depth buffer
    gl.glPushAttrib(GL.GL_ENABLE_BIT);
    gl.glDisable(GL.GL_BLEND);
    gl.glDisable(GL.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Retrieve the current viewport and switch to orthographic mode
    IntBuffer viewPort = BufferUtil.newIntBuffer(4);
    gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort);
    glu.gluOrtho2D(0, viewPort.get(2), viewPort.get(3), 0);

    // Render the text
    gl.glColor3f(1, 1, 1);

    int x = OFFSET;
    int maxx = 0;
    int y = OFFSET + CHAR_HEIGHT;

    if (keyboardEntries.size() > 0) {
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS);
      maxx =
          Math.max(
              maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS));

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < keyboardEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        String text = (String) keyboardEntries.get(i);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, text);
        maxx = Math.max(maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, text));
        y += OFFSET;
      }
    }

    if (mouseEntries.size() > 0) {
      x = maxx + OFFSET;
      y = OFFSET + CHAR_HEIGHT;
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, MOUSE_CONTROLS);

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < mouseEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, (String) mouseEntries.get(i));
        y += OFFSET;
      }
    }

    // Restore enabled state
    gl.glPopAttrib();

    // Restore old matrices
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();
  }
Example #29
0
  @Override
  public void render(final DrawContext dc) {
    //      _lastDC = dc;

    runFrameWorkers();

    final GTexture texture = getTexture();
    if ((texture == null) || !texture.hasGLTexture()) {
      return;
    }

    final GL gl = dc.getGL();

    gl.glPushAttrib(
        GL.GL_DEPTH_BUFFER_BIT
            | GL.GL_COLOR_BUFFER_BIT
            | GL.GL_ENABLE_BIT
            | GL.GL_TEXTURE_BIT
            | GL.GL_TRANSFORM_BIT
            | GL.GL_VIEWPORT_BIT
            | GL.GL_CURRENT_BIT);

    gl.glEnable(GL.GL_BLEND);
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight)
    // into the GL projection matrix.
    final Rectangle viewport = dc.getView().getViewport();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    final double maxwh = Math.max(_textureWidth, _textureHeight);
    gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh);

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    // Translate and scale
    final float scale = computeScale(viewport);
    final Vec4 locationSW = computeLocation(viewport, scale);
    gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z());
    // Scale to 0..1 space
    gl.glScalef(scale, scale, 1f);
    gl.glScaled(_textureWidth, _textureHeight, 1d);

    _lastScreenBounds = calculateScreenBounds(viewport, locationSW, scale);

    texture.enable();
    texture.bind();
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);

    gl.glColor4f(1, 1, 1, calculateOpacity());
    dc.drawUnitQuad(texture.getImageTexCoords());

    texture.disable();

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPopMatrix();

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();

    gl.glPopAttrib();
  }
  public void setLighting(LightList list) {
    GL gl = GLContext.getCurrentGL();
    // XXX: This is abuse of setLighting() to
    // apply fixed function bindings
    // and do other book keeping.
    if (list == null || list.size() == 0) {
      gl.glDisable(GLLightingFunc.GL_LIGHTING);
      applyFixedFuncBindings(false);
      setModelView(worldMatrix, viewMatrix);
      return;
    }

    // Number of lights set previously
    int numLightsSetPrev = lightList.size();

    // If more than maxLights are defined, they will be ignored.
    // The GL1 renderer is not permitted to crash due to a
    // GL1 limitation. It must render anything that the GL2 renderer
    // can render (even incorrectly).
    lightList.clear();
    materialAmbientColor.set(0, 0, 0, 0);

    for (int i = 0; i < list.size(); i++) {
      Light l = list.get(i);
      if (l.getType() == Light.Type.Ambient) {
        // Gather
        materialAmbientColor.addLocal(l.getColor());
      } else {
        // Add to list
        lightList.add(l);

        // Once maximum lights reached, exit loop.
        if (lightList.size() >= maxLights) {
          break;
        }
      }
    }

    applyFixedFuncBindings(true);

    gl.glEnable(GLLightingFunc.GL_LIGHTING);

    fb16.clear();
    fb16.put(materialAmbientColor.r)
        .put(materialAmbientColor.g)
        .put(materialAmbientColor.b)
        .put(1)
        .flip();

    gl.getGL2ES1().glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, fb16);

    if (context.matrixMode != GLMatrixFunc.GL_MODELVIEW) {
      gl.getGL2ES1().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
      context.matrixMode = GLMatrixFunc.GL_MODELVIEW;
    }
    // Lights are already in world space, so just convert
    // them to view space.
    gl.getGL2ES1().glLoadMatrixf(storeMatrix(viewMatrix, fb16));

    for (int i = 0; i < lightList.size(); i++) {
      int glLightIndex = GLLightingFunc.GL_LIGHT0 + i;
      Light light = lightList.get(i);
      Light.Type lightType = light.getType();
      ColorRGBA col = light.getColor();
      Vector3f pos;

      // Enable the light
      gl.glEnable(glLightIndex);

      // OGL spec states default value for light ambient is black
      switch (lightType) {
        case Directional:
          DirectionalLight dLight = (DirectionalLight) light;

          fb16.clear();
          fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_DIFFUSE, fb16);
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPECULAR, fb16);

          pos = tempVec.set(dLight.getDirection()).negateLocal().normalizeLocal();
          fb16.clear();
          fb16.put(pos.x).put(pos.y).put(pos.z).put(0.0f).flip();
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_POSITION, fb16);
          gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_CUTOFF, 180);
          break;
        case Point:
          PointLight pLight = (PointLight) light;

          fb16.clear();
          fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_DIFFUSE, fb16);
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPECULAR, fb16);

          pos = pLight.getPosition();
          fb16.clear();
          fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip();
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_POSITION, fb16);
          gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_CUTOFF, 180);

          if (pLight.getRadius() > 0) {
            // Note: this doesn't follow the same attenuation model
            // as the one used in the lighting shader.
            gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_CONSTANT_ATTENUATION, 1);
            gl.getGL2ES1()
                .glLightf(
                    glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, pLight.getInvRadius() * 2);
            gl.getGL2ES1()
                .glLightf(
                    glLightIndex,
                    GLLightingFunc.GL_QUADRATIC_ATTENUATION,
                    pLight.getInvRadius() * pLight.getInvRadius());
          } else {
            gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_CONSTANT_ATTENUATION, 1);
            gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, 0);
            gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_QUADRATIC_ATTENUATION, 0);
          }

          break;
        case Spot:
          SpotLight sLight = (SpotLight) light;

          fb16.clear();
          fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_DIFFUSE, fb16);
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPECULAR, fb16);

          pos = sLight.getPosition();
          fb16.clear();
          fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip();
          gl.getGL2().glLightfv(glLightIndex, GLLightingFunc.GL_POSITION, fb16);

          Vector3f dir = sLight.getDirection();
          fb16.clear();
          fb16.put(dir.x).put(dir.y).put(dir.z).put(1.0f).flip();
          gl.getGL2ES1().glLightfv(glLightIndex, GLLightingFunc.GL_SPOT_DIRECTION, fb16);

          float outerAngleRad = sLight.getSpotOuterAngle();
          float innerAngleRad = sLight.getSpotInnerAngle();
          float spotCut = outerAngleRad * FastMath.RAD_TO_DEG;
          float spotExpo = 0.0f;
          if (outerAngleRad > 0) {
            spotExpo = (1.0f - (innerAngleRad / outerAngleRad)) * 128.0f;
          }

          gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_CUTOFF, spotCut);
          gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_SPOT_EXPONENT, spotExpo);

          if (sLight.getSpotRange() > 0) {
            gl.getGL2ES1()
                .glLightf(
                    glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, sLight.getInvSpotRange());
          } else {
            gl.getGL2ES1().glLightf(glLightIndex, GLLightingFunc.GL_LINEAR_ATTENUATION, 0);
          }

          break;
        default:
          throw new UnsupportedOperationException("Unrecognized light type: " + lightType);
      }
    }

    // Disable lights after the index
    for (int i = lightList.size(); i < numLightsSetPrev; i++) {
      gl.glDisable(GLLightingFunc.GL_LIGHT0 + i);
    }

    // This will set view matrix as well.
    setModelView(worldMatrix, viewMatrix);
  }