示例#1
0
  public void init(GLAutoDrawable drawable) {
    drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));
    final GL2 gl = drawable.getGL().getGL2();
    // drawable.getGL().getGL2();
    gl.glViewport(0, 0, SCREENW, SCREENH);

    // Clear color buffer with black
    // gl.glClearColor(1.0f, 0.5f, 1.0f, 1.0f);
    gl.glClearColor(.0f, .0f, .0f, 1.0f);
    gl.glClearDepth(1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

    gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER);
    shader.init(gl);
    int programName = shader.getID();
    gl.glBindAttribLocation(programName, Object3D.VERTEXPOSITION, "inposition");
    gl.glBindAttribLocation(programName, Object3D.VERTEXCOLOR, "incolor");
    gl.glBindAttribLocation(programName, Object3D.VERTEXNORMAL, "innormal");
    gl.glBindAttribLocation(programName, Object3D.VERTEXTEXCOORD0, "intexcoord0");
    shader.link(gl);
    uniformMat = gl.glGetUniformLocation(programName, "mat");
    uniformLight = gl.glGetUniformLocation(programName, "lightdir");
    gl.glUseProgram(programName);
    gl.glUniform3f(uniformLight, 0f, 10f, -10f);
    obj.init(gl, mats, programName);
    gl.glUseProgram(0);
  }
示例#2
0
  public void init(GLAutoDrawable drawable) {
    drawable.setAutoSwapBufferMode(false);

    GL2ES2 gl = drawable.getGL().getGL2ES2();
    System.err.println("Entering initialization");
    System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
    System.err.println("GL_EXTENSIONS:");
    System.err.println("  " + gl.glGetString(gl.GL_EXTENSIONS));

    pmvMatrix = new PMVMatrix();

    pmod.initShaderState(gl);
    st = ShaderState.getCurrent();

    // Push the 1st uniform down the path
    st.glUseProgram(gl, true);

    pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();

    if (!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) {
      throw new GLException("Error setting PMVMatrix in shader: " + st);
    }

    // OpenGL Render Settings
    gl.glClearColor(0, 0, 0, 1);
    gl.glEnable(GL2ES2.GL_DEPTH_TEST);

    st.glUseProgram(gl, false);

    // Let's show the completed shader state ..
    System.out.println(st);
  }
示例#3
0
  // ------------------------------------------------------------
  // GLEventListener
  public void init(GLAutoDrawable drawable) {
    if (debugging) drawable.setGL(new DebugGL(drawable.getGL()));

    try {
      // Specify new projection for this window
      init(drawable.getGL());
    } catch (GLException e) {
      e.printStackTrace();
    }
  }
 public void display(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   synchronized (this._camera) {
     try {
       gl.glClear(
           GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
       NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0);
       this._nyar.update(this._camera);
       if (this._nyar.isExistMarker(this.ids[0])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       if (this._nyar.isExistMarker(this.ids[1])) {
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0);
         NyARGLDrawUtil.drawColorCube(gl, 40);
         gl.glPopMatrix();
       }
       Thread.sleep(1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
示例#5
0
文件: Test.java 项目: JibouLBF/Fablab
  @Override
  public void display(GLAutoDrawable gLDrawable) {
    final GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate about the three axes
    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();

    // increasing rotation for the next iteration
    rotateT += 0.2f;
  }
示例#6
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (derefMethod == DRAWARRAY) {
      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6);
    } else if (derefMethod == ARRAYELEMENT) {
      gl.glBegin(GL2.GL_TRIANGLES);
      gl.glArrayElement(2);
      gl.glArrayElement(3);
      gl.glArrayElement(5);
      gl.glEnd();
    } else if (derefMethod == DRAWELEMENTS) {
      int indices[] = new int[] {0, 1, 3, 4};
      if (indicesBuf == null) {
        indicesBuf = GLBuffers.newDirectIntBuffer(indices.length);
        indicesBuf.put(indices);
      }
      indicesBuf.rewind();
      gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf);
    }
    gl.glFlush();

    // gl calls from C example's mouse routine are moved here
    if (setupMethod == INTERLEAVED) setupInterleave(gl);
    else if (setupMethod == POINTER) setupPointers(gl);
  }
示例#7
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f);

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, 0.5f, 0.0f);
    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);

    glut.glutSolidTorus(0.275f, 0.85f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, -0.5f, 0.0f);
    gl.glRotatef(270.0f, 1.0f, 0.0f, 0.0f);
    glut.glutSolidCone(1.0f, 2.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.75f, 0.0f, -1.0f);
    glut.glutSolidSphere(1.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPopMatrix();
    gl.glFlush();
  }
示例#8
0
  /*
   * Initialize z-buffer, projection matrix, light source, and lighting model.
   * Do not specify a material property here.
   */
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glut = new GLUT();
    //
    float position[] = {0.0f, 3.0f, 3.0f, 0.0f};
    float local_view[] = {0.0f};

    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LESS);

    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0);
    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, local_view, 0);

    gl.glFrontFace(GL.GL_CW);
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_AUTO_NORMAL);
    gl.glEnable(GL2.GL_NORMALIZE);
    gl.glEnable(GL2.GL_FOG);
    {
      float fogColor[] = {0.5f, 0.5f, 0.5f, 1.0f};

      fogMode = GL2.GL_EXP;
      gl.glFogi(GL2.GL_FOG_MODE, fogMode);
      gl.glFogfv(GL2.GL_FOG_COLOR, fogColor, 0);
      gl.glFogf(GL2.GL_FOG_DENSITY, 0.35f);
      gl.glHint(GL2.GL_FOG_HINT, GL.GL_DONT_CARE);

      gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    }
  }
示例#9
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   if (w <= (h * 3))
     gl.glOrtho(
         -6.0,
         6.0,
         -2.0 * ((float) h * 3) / (float) w,
         2.0 * ((float) h * 3) / (float) w,
         0.0,
         10.0);
   else
     gl.glOrtho(
         -6.0 * (float) w / ((float) h * 3), //
         6.0 * (float) w / ((float) h * 3),
         -2.0,
         2.0,
         0.0,
         10.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
示例#10
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);
 }
示例#11
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   try {
     // Specify new projection for this window
     projection(drawable.getGL(), width, height);
   } catch (GLException e) {
     e.printStackTrace();
   }
 }
示例#12
0
 public void display(GLAutoDrawable drawable) {
   try {
     // Draw the contents of the window (abstract method)
     draw(drawable.getGL());
   } catch (GLException e) {
     e.printStackTrace();
   }
 }
示例#13
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   glu.gluOrtho2D(0.0, (double) w, 0.0, (double) h);
 }
示例#14
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL gl = drawable.getGL();

    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, w, 0, h, -1.0, 1.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
示例#15
0
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glClear(GL.GL_COLOR_BUFFER_BIT);
   gl.glColor3f(1.0f, 1.0f, 1.0f);
   gl.glCallList(startList);
   gl.glCallList(startList + 1);
   gl.glFlush();
 }
示例#16
0
  public void dispose(GLAutoDrawable drawable) {
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    st.destroy(gl);
    st = null;
    pmvMatrix.destroy();
    pmvMatrix = null;
    quit = true;
  }
示例#17
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);
 }
 public void init(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadMatrixd(this._nyar.getGlProjectionMatrix(), 0);
   gl.glEnable(GL.GL_DEPTH_TEST);
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   Animator animator = new Animator(drawable);
   animator.start();
   return;
 }
示例#19
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   if (w <= h)
     gl.glOrtho(-2.5, 2.5, -2.5 * (float) h / (float) w, 2.5 * (float) h / (float) w, -10.0, 10.0);
   else
     gl.glOrtho(-2.5 * (float) w / (float) h, 2.5 * (float) w / (float) h, -2.5, 2.5, -10.0, 10.0);
   gl.glMatrixMode(GL2.GL_MODELVIEW);
 }
示例#20
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0, 1.0, 0.25, 25.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);
  }
示例#21
0
文件: Test.java 项目: JibouLBF/Fablab
 @Override
 public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
   GL2 gl = gLDrawable.getGL().getGL2();
   final float aspect = (float) width / (float) height;
   gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
   gl.glLoadIdentity();
   final float fh = 0.5f;
   final float fw = fh * aspect;
   gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
   gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
   gl.glLoadIdentity();
 }
示例#22
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;
    }
  }
示例#23
0
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glut = new GLUT();
    //
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    makeStripeImage();

    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

    gl.glGenTextures(1, texName, 0);
    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);

    gl.glTexParameterf(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
    gl.glTexParameterf(
        GL2.GL_TEXTURE_1D, //
        GL2.GL_TEXTURE_MAG_FILTER,
        GL.GL_LINEAR);
    gl.glTexParameterf(
        GL2.GL_TEXTURE_1D, //
        GL2.GL_TEXTURE_MIN_FILTER,
        GL.GL_LINEAR);
    gl.glTexImage1D(
        GL2.GL_TEXTURE_1D,
        0,
        GL2.GL_RGBA,
        stripeImageWidth, //
        0,
        GL2.GL_RGB,
        GL.GL_UNSIGNED_BYTE,
        stripeImageBuf);

    gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE);
    currentCoeff = xequalzero;
    currentGenMode = GL2.GL_OBJECT_LINEAR;
    currentPlane = GL2.GL_OBJECT_PLANE;
    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR);
    gl.glTexGendv(GL2.GL_S, GL2.GL_OBJECT_PLANE, currentCoeff, 0);

    // gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LESS);
    gl.glEnable(GL2.GL_TEXTURE_GEN_S);
    gl.glEnable(GL2.GL_TEXTURE_1D);
    gl.glEnable(GL.GL_CULL_FACE);
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_AUTO_NORMAL);
    gl.glEnable(GL2.GL_NORMALIZE);
    gl.glFrontFace(GL.GL_CW);
    gl.glCullFace(GL.GL_BACK);
    gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, 64.0f);
  }
示例#24
0
  @Override
  public void display(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    // Fonts draw selves at the current raster position
    gl.glRasterPos2f(right - (right + 2.0f), bottom + 1);
    caption = "Please wait... drawing frames";
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, caption);

    drawByLevel();

    gl.glFlush();
  }
示例#25
0
  public void display(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glRasterPos2i(1, 1);
    gl.glDrawPixels(
        dim.width,
        dim.height, //
        GL.GL_RGB,
        GL.GL_UNSIGNED_BYTE,
        pixels);

    gl.glFlush();
  }
示例#26
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, currentGenMode);
    gl.glTexGendv(GL2.GL_S, currentPlane, currentCoeff, 0);

    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);
    glut.glutSolidTeapot(2.0f);
    gl.glPopMatrix();
    gl.glFlush();
  }
示例#27
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);
  }
示例#28
0
  /*
   * Initialize fog
   */
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glu = new GLU();
    //
    float fogColor[] = {0.0f, 0.25f, 0.25f, 1.0f};
    f1 = 1.0f;
    f2 = 5.0f;
    f3 = 10.0f;

    gl.glEnable(GL2.GL_FOG);
    gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_EXP);
    gl.glFogfv(GL2.GL_FOG_COLOR, fogColor, 0);
    gl.glFogf(GL2.GL_FOG_DENSITY, 0.25f);
    gl.glHint(GL2.GL_FOG_HINT, GL.GL_DONT_CARE);
    gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FOG_COORDINATE);
    gl.glClearColor(0.0f, 0.25f, 0.25f, 1.0f); /* fog color */
  }
示例#29
0
  /*
   * display() draws 5 teapots at different z positions.
   */
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    //
    if (fogMode == GL2.GL_EXP2) {
      gl.glFogf(GL2.GL_FOG_START, 1.0f);
      gl.glFogf(GL2.GL_FOG_END, 5.0f);
    }
    gl.glFogi(GL2.GL_FOG_MODE, fogMode);

    renderRedTeapot(gl, -4.0f, -0.5f, -1.0f);
    renderRedTeapot(gl, -2.0f, -0.5f, -2.0f);
    renderRedTeapot(gl, 0.0f, -0.5f, -3.0f);
    renderRedTeapot(gl, 2.0f, -0.5f, -4.0f);
    renderRedTeapot(gl, 4.0f, -0.5f, -5.0f);
    gl.glFlush();
  }
示例#30
0
  /**
   * Call-back handler for window re-size event. Also called when the drawable is first set to
   * visible.
   */
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context

    if (height == 0) height = 1; // prevent divide by zero
    float aspect = (float) width / height;

    // Set the view port (display area) to cover the entire window
    gl.glViewport(0, 0, width, height);

    // Setup perspective projection, with aspect ratio matches viewport
    gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
    gl.glLoadIdentity(); // reset projection matrix
    glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar

    // Enable the model-view transform
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity(); // reset
  }