示例#1
0
 protected void setBlendingFunction(DrawContext dc) {
   GL2 gl = dc.getGL().getGL2();
   double alpha = this.getOpacity();
   gl.glColor4d(alpha, alpha, alpha, alpha);
   gl.glEnable(GL2.GL_BLEND);
   gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
 }
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    // If you do not add this line
    // opengl will draw things in the order you
    // draw them in your program
    gl.glEnable(GL2.GL_DEPTH_TEST);

    // By enabling lighting, color is worked out differently.
    gl.glEnable(GL2.GL_LIGHTING);

    // When you enable lighting you must still actually
    // turn on a light such as this default light.
    gl.glEnable(GL2.GL_LIGHT0);
    // Light property vectors.
    float lightAmb[] = {0.0f, 0.0f, 0.0f, 1.0f};
    float lightDifAndSpec[] = {1.0f, 1.0f, 1.0f, 1.0f};
    // float lightPos[] = { 0.0f, 1.5f, 3.0f, 1.0f };
    float globAmb[] = {0.2f, 0.2f, 0.2f, 1.0f};
    // float globAmb[] = {0.5f,0.5f,0.5f,1f};
    // Light properties.
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, lightAmb, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, lightDifAndSpec, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, lightDifAndSpec, 0);
    // gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPos,0);

    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL2.GL_BLEND);
  }
  public void setup() {

    // OPENGL SPECIFIC INITIALIZATION (OPTIONAL)
    GL2 gl = getGL2();
    gl.glEnable(GL2.GL_CULL_FACE);
    float light_model_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
    float light0_diffuse[] = {0.9f, 0.9f, 0.9f, 0.9f};
    float light0_direction[] = {0.0f, -0.4f, 1.0f, 0.0f};
    gl.glEnable(GL2.GL_NORMALIZE);
    gl.glShadeModel(GL2.GL_SMOOTH);

    gl.glLightModeli(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, GL2.GL_FALSE);
    gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, GL2.GL_FALSE);
    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, light_model_ambient, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, light0_diffuse, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light0_direction, 0);
    gl.glEnable(GL2.GL_LIGHT0);

    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glColor3f(0.9f, 0.9f, 0.9f);

    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

    background(0, 0, 0);

    video_frame = new VideoFrame();
  }
示例#4
0
 @Override
 public void init(GL2 gl) {
   displayListIndex = gl.glGenLists(1);
   gl.glEnable(GL.GL_LINE_SMOOTH);
   gl.glEnable(GL.GL_BLEND);
   gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
 }
示例#5
0
  /**
   * Called back immediately after the OpenGL context is initialized. Can be used to perform
   * one-time initialization. Run only once.
   */
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
    glu = new GLU(); // get GL Utilities
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    // Do not enable depth test
    //      gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    //      gl.glDepthFunc(GL_LEQUAL);  // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    // Load the texture image
    try {
      // Use URL so that can read from JAR and disk file.
      BufferedImage image = ImageIO.read(this.getClass().getResource(textureFileName));

      // Create a OpenGL Texture object
      texture = AWTTextureIO.newTexture(GLProfile.getDefault(), image, false);
      // Use linear filter if image is larger than the original texture
      gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      // Use linear filter if image is smaller than the original texture
      gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    } catch (GLException | IOException e) {
      e.printStackTrace();
    }

    // Texture image flips vertically. Shall use TextureCoords class to retrieve
    // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f.
    TextureCoords textureCoords = texture.getImageTexCoords();
    textureCoordTop = textureCoords.top();
    textureCoordBottom = textureCoords.bottom();
    textureCoordLeft = textureCoords.left();
    textureCoordRight = textureCoords.right();

    // Enable the texture
    texture.enable(gl);
    texture.bind(gl);
    // gl.glEnable(GL_TEXTURE_2D);

    // Enable blending
    gl.glEnable(GL_BLEND);
    gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    // Allocate the stars
    for (int i = 0; i < stars.length; i++) {
      stars[i] = new Star();
      // Linearly distributed according to the star number
      stars[i].distance = ((float) i / numStars) * 5.0f;
    }
  }
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    // If you do not add this line
    // opengl will draw things in the order you
    // draw them in your program
    gl.glEnable(GL2.GL_DEPTH_TEST);

    gl.glClearColor(1, 1, 1, 1);
    // Turn on for transparency and blending
    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL2.GL_BLEND);
  }
  @Override
  public void render(GL2 gl, float trajectory) {
    //		flat = true;

    gl.glPushMatrix();
    {
      gl.glTranslatef(c.x, c.y, c.z);
      gl.glRotatef(trajectory, 0, -1, 0);
      gl.glRotatef((flat) ? -90 : 0, 1, 0, 0);
      gl.glRotatef(rotation, 0, 0, 1);

      Vec3 scale = new Vec3(0.75f, 2.0f, 0);
      if (miniature) scale = scale.multiply(0.5f);
      scale = scale.multiply(0.8f);

      gl.glScalef(scale.x, scale.y, scale.z);
      gl.glTranslatef(0, 0.2f, 0);

      gl.glDepthMask(false);
      gl.glDisable(GL_LIGHTING);
      gl.glEnable(GL_BLEND);
      gl.glEnable(GL_TEXTURE_2D);

      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE);

      whiteSpark.bind(gl);

      gl.glColor3f(colors[color][0], colors[color][1], colors[color][2]);

      gl.glBegin(GL_QUADS);
      {
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(-0.5f, -0.5f, 0.0f);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(-0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(0.5f, -0.5f, 0.0f);
      }
      gl.glEnd();

      gl.glDisable(GL_BLEND);
      gl.glEnable(GL_LIGHTING);
      gl.glDepthMask(true);

      gl.glColor3f(1, 1, 1);
    }
    gl.glPopMatrix();
  }
示例#8
0
  protected void beginDrawIcons(DrawContext dc) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    this.oglStackHandler.clear();

    int attributeMask =
        GL2.GL_DEPTH_BUFFER_BIT // for depth test, depth mask and depth func
            | GL2.GL_TRANSFORM_BIT // for modelview and perspective
            | GL2.GL_VIEWPORT_BIT // for depth range
            | GL2.GL_CURRENT_BIT // for current color
            | GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, and blend
            | GL2.GL_DEPTH_BUFFER_BIT // for depth func
            | GL2.GL_ENABLE_BIT; // for enable/disable changes
    this.oglStackHandler.pushAttrib(gl, attributeMask);

    // Apply the depth buffer but don't change it.
    if ((!dc.isDeepPickingEnabled())) gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthMask(false);

    // Suppress any fully transparent image pixels
    gl.glEnable(GL2.GL_ALPHA_TEST);
    gl.glAlphaFunc(GL2.GL_GREATER, 0.001f);

    // Load a parallel projection with dimensions (viewportWidth, viewportHeight)
    this.oglStackHandler.pushProjectionIdentity(gl);
    gl.glOrtho(
        0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);

    this.oglStackHandler.pushModelview(gl);
    this.oglStackHandler.pushTexture(gl);

    if (dc.isPickingMode()) {
      this.pickSupport.beginPicking(dc);

      // Set up to replace the non-transparent texture colors with the single pick color.
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_COMBINE);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_SRC0_RGB, GL2.GL_PREVIOUS);
      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_COMBINE_RGB, GL2.GL_REPLACE);
    } else {
      gl.glEnable(GL.GL_TEXTURE_2D);
      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
    }
  }
示例#9
0
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    TextRenderer.createInstance();
    PrimitiveBuffers.createBuffers();
    AssetManager.setInstance(new DesktopAssetManager());

    DesktopTextureManager textureManager = new DesktopTextureManager();
    textureManager.setGL2(drawable.getGL().getGL2());
    TextureManager.setInstance(textureManager);
    TextureManager.init(new DesktopGL2(gl));

    DefaultShaders.createDefaultShaders(new DesktopGL2(gl));
    GenoShaders.createShaders(new DesktopGL2(gl));
    GenoTexID.createTextures(new DesktopGL2(gl));

    gl.glDisable(GL2.GL_DEPTH_TEST);
    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  }
示例#10
0
 public void renderSelection(GL2 g) {
   if ((Globals.tab == Tab.labels || Globals.tab == Tab.height)) {
     g.glDisable(GL2.GL_ALPHA_TEST);
     g.glEnable(GL2.GL_BLEND);
     g.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
     double color = System.currentTimeMillis();
     color %= 2000d;
     color -= 1000d;
     color = Math.abs(color);
     color /= 1000d;
     g.glColor4d(1, 1, 0, 0.1d + 0.2d * color);
     g.glBegin(GL2.GL_QUADS);
     g.glVertex2f(0, 0);
     g.glVertex2f(0, 4);
     g.glVertex2f(4, 4);
     g.glVertex2f(4, 0);
     g.glEnd();
     g.glColor4f(1, 1, 1, 1);
     g.glDisable(GL2.GL_BLEND);
     g.glEnable(GL2.GL_ALPHA_TEST);
   }
 }
示例#11
0
  @Override
  public void display(GLAutoDrawable drawable) {

    gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    // desenha ou nao a bounding sphere de cada objeto
    if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_B)) { // tecla B
      BoundingVolume.isVisible = !BoundingVolume.isVisible;
    }
    // habilita ou nao fog
    if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_F)) { // tecla F
      fogEnabled = !fogEnabled;
      if (fogEnabled) gl.glEnable(GL2.GL_FOG);
      else gl.glDisable(GL2.GL_FOG);
    }

    // atualiza camera
    camera.update();
    // atualiza objetos
    {
      Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject so = it.next();
        // animacao da porta
        if (so.getName().contains("door")) {
          if (Collision.collide(
              camera.getSceneObject().getBoundingSphere(), so.getBoundingSphere()))
            so.setAnimating(true);
          else so.setAnimating(false);
        }

        so.update();
      }
    }

    glu.gluLookAt(
        FPCamera.position.x,
        FPCamera.position.y,
        FPCamera.position.z,
        FPCamera.position.x + FPCamera.look.x,
        FPCamera.position.y + FPCamera.look.y,
        FPCamera.position.z + FPCamera.look.z,
        FPCamera.up.x,
        FPCamera.up.y,
        FPCamera.up.z);

    if (FPCamera.changed) { // se direcao da camera mudar
      FPCamera.changed = false;

      frustum.generate(drawable); // gera o frustum

      Scene.getInstance().clearVisibleObjectsList();

      Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject so = it.next();
        if (frustum.sphereInFrustum(so.getBoundingSphere()))
          Scene.getInstance().addVisibleObject(so);
      }

      //            System.out.println("Renderable objects: "+ Scene.getInstance().getSize());
      //            System.out.println(FPCamera.position);
    }

    // desenha objetos
    {
      Iterator<SceneObject> it = Scene.getInstance().getVisibleObjectsIterator();
      SceneObject so;
      while (it.hasNext()) {
        so = it.next();

        if (so.getName().contains("lake")) {
          gl.glPushAttrib(GL2.GL_ENABLE_BIT);
          gl.glEnable(GL.GL_BLEND);
          gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
          so.draw(drawable);
          gl.glPopAttrib();
          continue;
        }
        so.draw(drawable);
      }
    }

    //        int e = gl.glGetError();
    //        if(e != GL.GL_NO_ERROR) {
    //            System.err.println("Erro: "+ gl.glGetString(e));
    //        }
    // calculo do fps
    ++frame;
    long time = System.currentTimeMillis();
    elapsed = time - timebase;
    if (elapsed > 1000) {
      long fps = frame * 1000 / (time - timebase);
      timebase = time;
      frame = 0;

      String str = "FPS: " + fps;
      mainFrame.setTitle(str);
    }

    // gl.glFlush();
  }
示例#12
0
  public void display(GLAutoDrawable drawable) {
    update();

    GL2 gl = drawable.getGL().getGL2();
    // Clear Color Buffer, Depth Buffer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    Matrix TmpMatrix = new Matrix(); // Temporary MATRIX Structure ( NEW )
    Vector TmpVector = new Vector(), TmpNormal = new Vector(); // Temporary
    // VECTOR
    // Structures
    // ( NEW )

    gl.glLoadIdentity(); // Reset The Matrix

    if (outlineSmooth) { // Check To See If We Want Anti-Aliased Lines ( NEW
      // )
      gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); // Use The Good
      // Calculations
      // ( NEW )
      gl.glEnable(GL2.GL_LINE_SMOOTH); // Enable Anti-Aliasing ( NEW )
    } else
      // We Don't Want Smooth Lines ( NEW )
      gl.glDisable(GL2.GL_LINE_SMOOTH); // Disable Anti-Aliasing ( NEW )

    gl.glTranslatef(0.0f, 0.0f, -2.0f); // Move 2 Units Away From The Screen
    // ( NEW )
    gl.glRotatef(modelAngle, 0.0f, 1.0f, 0.0f); // Rotate The Model On It's
    // Y-Axis ( NEW )

    gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, TmpMatrix.Data, 0); // Get
    // The
    // Generated
    // Matrix
    // (
    // NEW
    // )

    // Cel-Shading Code //
    gl.glEnable(GL2.GL_TEXTURE_1D); // Enable 1D Texturing ( NEW )
    gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind Our
    // Texture ( NEW
    // )
    gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW )

    gl.glBegin(GL2.GL_TRIANGLES); // Tell OpenGL That We're Drawing
    // Triangles
    // Loop Through Each Polygon
    for (int i = 0; i < polyNum; i++)
      // Loop Through Each Vertex
      for (int j = 0; j < 3; j++) {

        // Fill Up The TmpNormal Structure With
        TmpNormal.X = polyData[i].Verts[j].Nor.X;
        // The Current Vertices' Normal Values
        TmpNormal.Y = polyData[i].Verts[j].Nor.Y;
        TmpNormal.Z = polyData[i].Verts[j].Nor.Z;
        // Rotate This By The Matrix
        TmpMatrix.rotateVector(TmpNormal, TmpVector);
        // Normalize The New Normal
        TmpVector.normalize();

        // Calculate The Shade Value
        float TmpShade = Vector.dotProduct(TmpVector, lightAngle);

        // Clamp The Value to 0 If Negative ( NEW )
        if (TmpShade < 0.0f) {
          TmpShade = 0.0f;
        }
        // Set The Texture Co-ordinate As The Shade Value
        gl.glTexCoord1f(TmpShade);
        // Send The Vertex Position
        gl.glVertex3f(
            polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
      }

    gl.glEnd(); // Tell OpenGL To Finish Drawing
    gl.glDisable(GL2.GL_TEXTURE_1D); // Disable 1D Textures ( NEW )

    // Outline Code
    // Check To See If We Want To Draw The Outline
    if (outlineDraw) {
      // Enable Blending
      gl.glEnable(GL2.GL_BLEND);
      // Set The Blend Mode
      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

      // Draw Backfacing Polygons As Wireframes
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_LINE);
      // Set The Line Width
      gl.glLineWidth(outlineWidth);
      // Don't Draw Any Front-Facing Polygons
      gl.glCullFace(GL2.GL_FRONT);

      // Change The Depth Mode
      gl.glDepthFunc(GL2.GL_LEQUAL);
      // Set The Outline Color
      gl.glColor3fv(outlineColor, 0);

      // Tell OpenGL What We Want To Draw
      gl.glBegin(GL2.GL_TRIANGLES);

      // Loop Through Each Polygon
      for (int i = 0; i < polyNum; i++) {

        // Loop Through Each Vertex
        for (int j = 0; j < 3; j++) {

          // Send The Vertex Position
          gl.glVertex3f(
              polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
        }
      }
      gl.glEnd(); // Tell OpenGL We've Finished
      // Reset The Depth-Testing Mode
      gl.glDepthFunc(GL2.GL_LESS);
      // Reset The Face To Be Culled
      gl.glCullFace(GL2.GL_BACK);
      // Reset Back-Facing Polygon Drawing Mode
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_FILL);

      // Disable Blending
      gl.glDisable(GL2.GL_BLEND);
    }

    // Check To See If Rotation Is Enabled
    if (modelRotate) {
      // Update Angle Based On The Clock
      modelAngle += .2f;
    }
  }
示例#13
0
  public void drawTrees(GL2 gl, Texture[] textures) {

    for (int i = 0; i < nbArbres; i++) {

      RandomCoordonnees ran = listeCoord.get(i);

      // On dessine que les arbres au dessus du niveau de la mer
      if (tableauNiveaux[ran.getX()][ran.getY()] >= GameConstants.NIVEAU_EAU) {
        int x = ran.getX() - (tableauNiveaux.length / 2);
        int z = ran.getY() - (tableauNiveaux[0].length / 2);

        // Arbres textures

        textures[indicesTypeArbres[i]].enable(gl);
        textures[indicesTypeArbres[i]].bind(gl);

        // Transparence des PNG : Assombrit l'image !!!
        gl.glEnable(GL_BLEND);
        gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        gl.glBegin(GL_QUADS);

        /*
         * Ordre des coins
         * 10
         * 00
         * 01
         * 11
         *
         * */

        // Dessin des deux faces avec textures
        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            z * GameConstants.LARGEUR_CARRE);
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            z * GameConstants.LARGEUR_CARRE);
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()],
            z * GameConstants.LARGEUR_CARRE);
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()],
            z * GameConstants.LARGEUR_CARRE);

        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            (z * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f));
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            (z * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f));
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()],
            (z * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f));
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()],
            (z * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f));

        gl.glEnd();

        textures[indicesTypeArbres[i]].disable(gl);

        // gl.glDisable(GL_TEXTURE_2D);
        gl.glDisable(GL_BLEND);
      }
    }
  }
  public void draw(GL2 gl) {
    if (particles.size() == 0) return;
    switch (blendMode) {
      case 0: // '\0'
        gl.glDisable(3042);
        gl.glDisable(3008);
        break;

      case 1: // '\001'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(768, 1);
        break;

      case 2: // '\002'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(770, 1);
        break;

      case 3: // '\003'
        gl.glDisable(3042);
        gl.glEnable(3008);
        break;

      case 4: // '\004'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(770, 1);
        break;
    }
    gl.glBindTexture(3553, model.mMaterials[texture].mTextureId);
    gl.glPushMatrix();
    if (particleType == 0 || particleType == 2) {
      if ((flags & 0x1000) == 0) {
        Vec3 view = new Vec3(viewer.getCamera().getPosition());
        view.normalize();
        Vec3 right = Vec3.cross(view, new Vec3(0.0F, 0.0F, 1.0F)).normalize();
        Vec3 up = Vec3.cross(right, view).normalize();
        int tcStart = 0;
        if (flags == 0x40019) tcStart++;
        gl.glBegin(7);
        int count = particles.size();
        Vec3 pos = new Vec3();
        Vec3 cPos = new Vec3();
        Vec3 ofs = new Vec3();
        for (int i = 0; i < count; i++) {
          Particle p = (Particle) particles.get(i);
          if (p.tile < texCoords.size()) {
            gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
            Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
            Vec3.add(right, up, ofs);
            cPos.set(p.pos);
            Vec3.sub(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[tcStart % 4].x, tc[tcStart % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.sub(right, up, ofs);
            Vec3.add(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 1) % 4].x, tc[(tcStart + 1) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(right, up, ofs);
            Vec3.add(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 2) % 4].x, tc[(tcStart + 2) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.sub(right, up, ofs);
            Vec3.sub(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 3) % 4].x, tc[(tcStart + 3) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
          }
        }

        gl.glEnd();
      } else {
        gl.glBegin(7);
        int count = particles.size();
        Vec3 pos = new Vec3();
        Vec3 ofs = new Vec3();
        for (int i = 0; i < count; i++) {
          Particle p = (Particle) particles.get(i);
          if (p.tile < texCoords.size()) {
            gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
            Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
            Vec3.add(p.pos, Vec3.scale(p.corners[0], p.size, ofs), pos);
            gl.glTexCoord2f(tc[0].x, tc[0].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[1], p.size, ofs), pos);
            gl.glTexCoord2f(tc[1].x, tc[1].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[2], p.size, ofs), pos);
            gl.glTexCoord2f(tc[2].x, tc[2].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[3], p.size, ofs), pos);
            gl.glTexCoord2f(tc[3].x, tc[3].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
          }
        }

        gl.glEnd();
      }
    } else if (particleType == 1) {
      gl.glBegin(7);
      int count = particles.size();
      Vec3 pos = new Vec3();
      Vec3 ofs = new Vec3();
      float f = 1.0F;
      Vec3 bv0 = new Vec3(-f, f, 0.0F);
      Vec3 bv1 = new Vec3(f, f, 0.0F);
      for (int i = 0; i < count; i++) {
        Particle p = (Particle) particles.get(i);
        if (p.tile >= texCoords.size() - 1) break;
        gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
        Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
        Vec3.add(p.pos, Vec3.scale(bv0, p.size, ofs), pos);
        gl.glTexCoord2f(tc[0].x, tc[0].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.pos, Vec3.scale(bv1, p.size, ofs), pos);
        gl.glTexCoord2f(tc[1].x, tc[1].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.origin, Vec3.scale(bv1, p.size, ofs), pos);
        gl.glTexCoord2f(tc[2].x, tc[2].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.origin, Vec3.scale(bv0, p.size, ofs), pos);
        gl.glTexCoord2f(tc[3].x, tc[3].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
      }

      gl.glEnd();
    }
    gl.glPopMatrix();
  }
示例#15
0
  public void draw(GL2 gl, Camera camera, Perspective3D perspective3d) {
    Photo photo = this.photo;

    gl.glDisable(GL2.GL_DEPTH_TEST);
    gl.glColor4f(
        (float) 255 / 255, (float) 255 / 255, (float) 255 / 255, (float) photo.getTransparent());

    // Enable Alpha Blending (disable alpha testing)
    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL2.GL_BLEND);

    gl.glDisable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_TEXTURE_2D);

    // XXX
    String textureName = photo.getPath();

    TextureCoords tc = new TextureCoords(0, 0, 1, 1);
    if (textureName != null) {
      Texture texture = this.textureCacheService.getTexture(gl, textureName);

      //            // switch to texture mode and push a new matrix on the stack
      //            gl.glMatrixMode(GL2.GL_TEXTURE);
      //            gl.glPushMatrix();
      //
      //            // check to see if the texture needs flipping
      //            if (texture.getMustFlipVertically()) {
      //                gl.glScaled(1, -1, 1);
      //                gl.glTranslated(0, -1, 0);
      //            }
      //
      //            // switch to modelview matrix and push a new matrix on the stack
      //            gl.glMatrixMode(GL2.GL_MODELVIEW);
      //            gl.glPushMatrix();
      //
      //            // This is required to repeat textures
      //            gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
      //            gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);

      // enable, bind
      texture.enable(gl);
      texture.bind(gl);

      tc = texture.getImageTexCoords();
    }

    gl.glBegin(GL2.GL_POLYGON);
    //        gl.glColor3f((float)123/256, (float)111/256, (float)100/255);
    //        gl.glColor3f((float) 255/255, (float)255/255, (float)255/255);

    LatLon ll = new LatLon(photo.getLat(), photo.getLon());

    Projection proj = Main.getProjection();

    EastNorth eastNorth = proj.latlon2eastNorth(ll);

    double x = perspective3d.calcX(eastNorth.east());
    double y = photo.getHeight();
    double z = -perspective3d.calcY(eastNorth.north());

    Vector3d angle = photo.getRotate();

    double distance = 500d;

    double width = distance * Math.sin(photo.getAngleWitht() / 2d);
    double height = distance * Math.sin(photo.getAngleHeigth() / 2d);

    Vector3d p1 = new Vector3d(distance, -height, -width);
    Vector3d p2 = new Vector3d(distance, -height, width);
    Vector3d p3 = new Vector3d(distance, height, width);
    Vector3d p4 = new Vector3d(distance, height, -width);

    p1 = transform(angle, p1);
    p2 = transform(angle, p2);
    p3 = transform(angle, p3);
    p4 = transform(angle, p4);

    Point3d c = camera.getPoint();

    // gl.glColor4f((float) 255/255, (float)255/255, (float)255/255, (float) 128/255);
    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_BLEND);

    gl.glTexCoord2d(tc.left(), tc.bottom());
    gl.glVertex3d(p1.x + x, p1.y + y, p1.z + z);
    gl.glTexCoord2d(tc.right(), tc.bottom());
    gl.glVertex3d(p2.x + x, p2.y + y, p2.z + z);
    gl.glTexCoord2d(tc.right(), tc.top());
    gl.glVertex3d(p3.x + x, p3.y + y, p3.z + z);
    gl.glTexCoord2d(tc.left(), tc.top());
    gl.glVertex3d(p4.x + x, p4.y + y, p4.z + z);

    gl.glEnd();

    gl.glColor3f((float) 0 / 255, (float) 0 / 255, (float) 255 / 255);

    gl.glPushMatrix();

    gl.glTranslated(x, 0.1, z);

    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE);

    DrawUtil.drawDotY(gl, 0.5, 12);
    gl.glPopMatrix();

    if (textureName != null) {
      Texture texture = this.textureCacheService.getTexture(gl, textureName);

      Texture t = this.textureCacheService.getTexture(gl, textureName);
      // this.textures.get(mesh.materialID);// .get(mesh.materialID);
      if (t != null) {
        t.disable(gl);
      }

      gl.glMatrixMode(GL2.GL_TEXTURE);
      gl.glPopMatrix();

      gl.glMatrixMode(GL2.GL_MODELVIEW);
      gl.glPopMatrix();
    }

    gl.glDisable(GL2.GL_TEXTURE_2D);

    gl.glColor4f((float) 255 / 255, (float) 255 / 255, (float) 255 / 255, (float) 255 / 255);

    gl.glDisable(GL2.GL_BLEND);
    gl.glEnable(GL2.GL_DEPTH_TEST);
  }