Ejemplo n.º 1
0
  void setupLight(GL2 gl) {
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glEnable(GL2.GL_CULL_FACE);
    gl.glCullFace(GL2.GL_BACK);

    /* create light 0 and give it a position */
    // float light0pos[] = {1.1f, 1.1f, -1.1f, 1};
    float light0pos[] = {1f, 1f, 1f, 0};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light0pos, 0);
    /* turn light 0 on */
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_RESCALE_NORMAL);

    float ambient[] = {0.3f, 0.3f, 0.3f};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient, 0);
    float specular[] = {1f, 1f, 1f, 1};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, specular, 0);

    gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, new float[] {0.5f, 0.5f, 0.5f, 1}, 0);
    gl.glMaterialf(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 20);

    /*turn lighting on */
    gl.glEnable(GL2.GL_LIGHTING);
    gl.glClearAccum(0, 0, 0, 0);
    lightEnabled = true;
  }
  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();
  }
Ejemplo n.º 3
0
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glut = new GLUT();
    //
    float ambient[] = new float[] {0.0f, 0.0f, 0.0f, 1.0f};
    float diffuse[] = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float specular[] = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float position[] = new float[] {0.0f, 3.0f, 3.0f, 0.0f};

    float lmodel_ambient[] = new float[] {0.2f, 0.2f, 0.2f, 1.0f};
    float local_view[] = new float[] {0.0f};

    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, ambient, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0);

    gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient, 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(GL.GL_DEPTH_TEST);

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClearAccum(0.0f, 0.0f, 0.0f, 0.0f);
    /* make teapot display list */
    teapotList = gl.glGenLists(1);
    gl.glNewList(teapotList, GL2.GL_COMPILE);
    glut.glutSolidTeapot(0.5f);
    gl.glEndList();
  }
  @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);
  }
Ejemplo n.º 5
0
  /** Configures the GL light with the light parameters. */
  public void turnOn(GL2 gl, int glLight) {
    if (isGLLight(glLight)) {
      gl.glEnable(glLight);

      if (ambient != null) {
        gl.glLightfv(glLight, GLLightingFunc.GL_AMBIENT, ambient, 0);
      } else {
        gl.glLightfv(glLight, GLLightingFunc.GL_AMBIENT, new float[] {0f, 0f, 0f, 0f}, 0);
      }
      if (diffuse != null) {
        gl.glLightfv(glLight, GLLightingFunc.GL_DIFFUSE, diffuse, 0);
      } else {
        gl.glLightfv(glLight, GLLightingFunc.GL_DIFFUSE, new float[] {0f, 0f, 0f, 0f}, 0);
      }
      if (specular != null) {
        gl.glLightfv(glLight, GLLightingFunc.GL_SPECULAR, specular, 0);
      } else {
        gl.glLightfv(glLight, GLLightingFunc.GL_SPECULAR, new float[] {0f, 0f, 0f, 0f}, 0);
      }

      gl.glLightf(glLight, GLLightingFunc.GL_CONSTANT_ATTENUATION, attenuationConstant);
      gl.glLightf(glLight, GLLightingFunc.GL_LINEAR_ATTENUATION, attenuationLinear);
      gl.glLightf(glLight, GLLightingFunc.GL_QUADRATIC_ATTENUATION, attenuationQuadratic);

      switch (type) {
        case Directional:
          gl.glLightfv(
              glLight,
              GLLightingFunc.GL_POSITION,
              new float[] {direction.x, direction.y, direction.z, type.w},
              0);
          break;
        case Point:
          gl.glLightfv(
              glLight,
              GLLightingFunc.GL_POSITION,
              new float[] {position.x, position.y, position.z, type.w},
              0);
          break;
        case Spot:
          gl.glLightfv(
              glLight,
              GLLightingFunc.GL_POSITION,
              new float[] {position.x, position.y, position.z, type.w},
              0);
          gl.glLightfv(
              glLight,
              GLLightingFunc.GL_SPOT_DIRECTION,
              new float[] {direction.x, direction.y, direction.z},
              0);
          gl.glLightf(glLight, GLLightingFunc.GL_SPOT_CUTOFF, cutoff);
          gl.glLightf(glLight, GLLightingFunc.GL_SPOT_EXPONENT, spotExp);
          break;
        default:
          // TODO(yin): Maybe custom lights?
      }
    }
  }
Ejemplo n.º 6
0
  private void setSunLight() {
    float ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
    float diffuse[] = {0.7f, 0.7f, 0.7f, 1.0f};
    float specular[] = {1, 1, 1, 1.0f};
    float position[] = {0, 16, 10, 1};

    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    gl.glColorMaterial(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE);

    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, specular, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0);
  }
Ejemplo n.º 7
0
  /*
   * Initialize material property and light source.
   */
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    float light_ambient[] = {0.0f, 0.0f, 0.0f, 1.0f};
    float light_diffuse[] = {1.0f, 0.0f, 1.0f, 1.0f};
    float light_specular[] = {1.0f, 0.0f, 1.0f, 1.0f};
    /* light_position is NOT default value */
    float light_position[] = {1.0f, 1.0f, 1.0f, 0.0f};

    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_ambient, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, light_diffuse, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_specular, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_position, 0);

    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glDepthFunc(GL.GL_LESS);
    gl.glEnable(GL.GL_DEPTH_TEST);
  }
Ejemplo n.º 8
0
 public void updateLightParameters(GL2 gl) {
   gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_AMBIENT, ambient, 0);
   gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_DIFFUSE, diffuse, 0);
   gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_SPECULAR, specular, 0);
   gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_POSITION, position, 0);
 }