示例#1
0
 public void init(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   glu = new GLU();
   //
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   gl.glShadeModel(GL2.GL_SMOOTH);
   setupPointers(gl);
 }
示例#2
0
文件: Test.java 项目: JibouLBF/Fablab
 @Override
 public void init(GLAutoDrawable glDrawable) {
   GL2 gl = glDrawable.getGL().getGL2();
   gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   gl.glClearDepth(1.0f);
   gl.glEnable(GL.GL_DEPTH_TEST);
   gl.glDepthFunc(GL.GL_LEQUAL);
   gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
 }
示例#3
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;
    }
  }
示例#4
0
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = (GL2) drawable.getGL();
    GLUgl2 glu = new GLUgl2();

    if (!gl.isExtensionAvailable("GL_ARB_vertex_buffer_object"))
      System.out.println("Error: VBO support is missing");

    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearDepth(1.0f);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glDepthFunc(GL2.GL_LEQUAL);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);

    game = new Game(gl, glu, input);
  }
示例#5
0
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glu = new GLU();
    /*
     * jogl specific addition for tessellation
     */
    tessellCallBack tessCallback = new tessellCallBack(gl, glu);
    //
    double rect[][] =
        new double[][] { // [4][3] in C; reverse here
          {50.0, 50.0, 0.0}, {200.0, 50.0, 0.0}, {200.0, 200.0, 0.0}, {50.0, 200.0, 0.0}
        };
    double tri[][] =
        new double[][] { // [3][3]
          {75.0, 75.0, 0.0}, {125.0, 175.0, 0.0}, {175.0, 75.0, 0.0}
        };
    double star[][] =
        new double[][] { // [5][6]; 6x5 in java
          {250.0, 50.0, 0.0, 1.0, 0.0, 1.0},
          {325.0, 200.0, 0.0, 1.0, 1.0, 0.0},
          {400.0, 50.0, 0.0, 0.0, 1.0, 1.0},
          {250.0, 150.0, 0.0, 1.0, 0.0, 0.0},
          {400.0, 150.0, 0.0, 0.0, 1.0, 0.0}
        };

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    startList = gl.glGenLists(2);

    GLUtessellator tobj = glu.gluNewTess();

    glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback); // glVertex3dv);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback); // beginCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback); // endCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback); // errorCallback);

    /* rectangle with triangular hole inside */
    gl.glNewList(startList, GL2.GL_COMPILE);
    gl.glShadeModel(GL2.GL_FLAT);
    glu.gluTessBeginPolygon(tobj, null);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, rect[0], 0, rect[0]);
    glu.gluTessVertex(tobj, rect[1], 0, rect[1]);
    glu.gluTessVertex(tobj, rect[2], 0, rect[2]);
    glu.gluTessVertex(tobj, rect[3], 0, rect[3]);
    glu.gluTessEndContour(tobj);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, tri[0], 0, tri[0]);
    glu.gluTessVertex(tobj, tri[1], 0, tri[1]);
    glu.gluTessVertex(tobj, tri[2], 0, tri[2]);
    glu.gluTessEndContour(tobj);
    glu.gluTessEndPolygon(tobj);
    gl.glEndList();

    glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback); // vertexCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback); // beginCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback); // endCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback); // errorCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_COMBINE, tessCallback); // combineCallback);

    /* smooth shaded, self-intersecting star */
    gl.glNewList(startList + 1, GL2.GL_COMPILE);
    gl.glShadeModel(GL2.GL_SMOOTH);
    glu.gluTessProperty(
        tobj, //
        GLU.GLU_TESS_WINDING_RULE, //
        GLU.GLU_TESS_WINDING_POSITIVE);
    glu.gluTessBeginPolygon(tobj, null);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, star[0], 0, star[0]);
    glu.gluTessVertex(tobj, star[1], 0, star[1]);
    glu.gluTessVertex(tobj, star[2], 0, star[2]);
    glu.gluTessVertex(tobj, star[3], 0, star[3]);
    glu.gluTessVertex(tobj, star[4], 0, star[4]);
    glu.gluTessEndContour(tobj);
    glu.gluTessEndPolygon(tobj);
    gl.glEndList();
    glu.gluDeleteTess(tobj);
  }