Ejemplo n.º 1
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    double eqn[] = {0.0, 1.0, 0.0, 0.0};
    double eqn2[] = {1.0, 0.0, 0.0, 0.0};

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glPushMatrix();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    /* clip lower half -- y < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE0, eqn, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE0);
    /* clip left half -- x < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE1, eqn2, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE1);

    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glut.glutWireSphere(1.0, 20, 16);
    gl.glPopMatrix();

    gl.glFlush();
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unused")
  private static void drawBox(GL2 gl) {
    gl.glDisable(GLLightingFunc.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(-0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, -0.5f, 0.5f);
    gl.glVertex3f(-0.5f, -0.5f, -0.5f);
    gl.glVertex3f(0.5f, -0.5f, -0.5f);
    gl.glVertex3f(0.5f, 0.5f, -0.5f);
    gl.glVertex3f(-0.5f, 0.5f, -0.5f);
    gl.glVertex3f(-0.5f, -0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(0.5f, 0.5f, 0.5f);
    gl.glVertex3f(0.5f, 0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, -0.5f, -0.5f);
    gl.glEnd();

    gl.glEnable(GL.GL_TEXTURE_2D);
    gl.glEnable(GLLightingFunc.GL_LIGHTING);
    gl.glEnable(GLLightingFunc.GL_LIGHT0);
  }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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();
  }
  public void draw() {

    GL2 gl = getGL2();

    pushMatrix();

    translate(0, 0, -2);
    rotate(view_rotx, 1.0, 0.0, 0.0);
    rotate(view_roty, 0.0, 1.0, 0.0);
    rotate(view_rotz, 0.0, 0.0, 1.0);
    translate(0, 0, 2);

    if (app != null) {
      if (is_playing) {
        map_previous = map;
        map =
            new DepthMap(
                app.w,
                app.h,
                DepthMap.fromRawDepthFile(
                    new File(app.filename), app.frame_now - 1, app.w, app.h, false));
        map.maskZ(app.z_threshold.getValue() / 100f);
        // map.maskRect(130,40,100,100);//head
        // map.maskRect(50,140,130,100);//arms
        map.setUVuniform();
        if (app.frame_now < app.frames) {
          app.frame_now += 1;
          app.time_domain.setValue(app.frame_now);
        } else {
          app.play_button.setText("Play");
          stop();
        }
      }
    }

    if (map != null) {
      if (app.show_diff.isSelected() && map != null && map_previous != null) {

        // map.drawNormals(gl);

        // gl.glClear(GL2.GL_DEPTH);
        // gl.glEnable(GL2.GL_BLEND);

        computeColorMap();
        gl.glDisable(GL2.GL_LIGHTING);
        gl.glEnable(GL2.GL_TEXTURE_2D);
        gl.glColor4f(1f, 1f, 1f, 0.75f);
        video_frame.use(gl);
        map.drawTextureNormals(gl);
        gl.glDisable(GL2.GL_TEXTURE_2D);
        gl.glEnable(GL2.GL_LIGHTING);
        gl.glDisable(GL2.GL_BLEND);
      } else {
        gl.glColor3f(0.9f, 0.9f, 0.9f);
        map.drawNormals(gl);
      }
    }

    popMatrix();
  }
Ejemplo n.º 7
0
  @Override
  public void init(GLAutoDrawable dr) {
    GL2 gl = dr.getGL().getGL2();
    // Задает цвет фона
    gl.glClearColor(0f, 0f, 0f, 0f);
    gl.glClearDepth(1.0f);
    // Интерполирует цвет, если вершины заданы различным цветом
    gl.glShadeModel(GL2.GL_SMOOTH);
    // Удаления невидимых линий и поверхностей
    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LEQUAL);
    // Сглаживание
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
    // Включение отображения текстур
    gl.glEnable(GL.GL_TEXTURE_2D);

    try {
      model = ModelFactory.createModel("model/globalstar/Globalstar.3ds");
      model.setUseLighting(false);
    } catch (Exception e) {
      System.out.println("Ошибка загрузки модели");
      e.printStackTrace();
      System.exit(1);
    }
  }
  @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.º 9
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();
  }
Ejemplo n.º 10
0
    public Light(GL2 gl, Vector3f pos, Vector3f amb, Vector3f dif, Vector3f spec) {
      position = new float[] {pos.x, pos.y, pos.z, 1};
      ambient = new float[] {amb.x, amb.y, amb.z, 1};
      diffuse = new float[] {dif.x, dif.y, dif.z, 1};
      specular = new float[] {spec.x, spec.y, spec.z, 1};
      gl.glEnable(GL2.GL_LIGHT0 + lightNumber);
      if (lightNumber == 0) // if this is the first light enable lighting
      gl.glEnable(GL2.GL_LIGHTING);

      updateLightParameters(gl);
    }
Ejemplo n.º 11
0
  @Override
  public void init(GLAutoDrawable drawable) {
    try {
      gl = drawable.getGL().getGL2();

      gl.glClearColor(0.7f, 0.7f, 0.9f, 1.0f);
      // gl.setSwapInterval(1);

      gl.glEnable(GL.GL_DEPTH_TEST);
      gl.glEnable(GL2.GL_LIGHTING);

      gl.glEnable(GL.GL_CULL_FACE);
      gl.glCullFace(GL.GL_BACK);

      /////////////////////////////////
      // carregando e compilando objetos
      /////////////////////////////////
      createSceneObjects();

      Iterator<SceneObject> it = scene.getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject sceneObject = it.next();

        JWavefrontModel[] models = sceneObject.getAnimationModels();
        if (models == null) continue;
        for (JWavefrontModel model : models) {
          if (sceneObject.useTexture())
            model.compile(
                drawable,
                JWavefrontModel.WF_MATERIAL
                    | JWavefrontModel.WF_TEXTURE
                    | JWavefrontModel.WF_SMOOTH);
          else model.compile(drawable, JWavefrontModel.WF_COLOR | JWavefrontModel.WF_SMOOTH);
        }
      }

      // light
      setSunLight();
      // fog
      setFog();

      gl.glMatrixMode(GL2.GL_PROJECTION);
      gl.glLoadIdentity();
      float h = (float) mainFrame.getWidth() / (float) mainFrame.getHeight();
      glu.gluPerspective(FPCamera.FOV, h, FPCamera.NEAR, FPCamera.FAR);

    } catch (IOException ex) {
      Logger.getLogger(Renderer.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Ejemplo n.º 12
0
  @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();
  }
  @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);
  }
Ejemplo n.º 14
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);
  }
  @Override
  protected void paintColorScale(GL2 gl, Axis1D axis, int width, int height) {
    if (colorTexture != null && axis instanceof TaggedAxis1D) {
      TaggedAxis1D taggedAxis = (TaggedAxis1D) axis;

      colorTexture.prepare(gl, 0);

      int count = updateCoordinateBuffers(taggedAxis, width, height);

      gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
      gl.glPolygonMode(GL2.GL_FRONT, GL2.GL_FILL);

      gl.glEnable(GL2.GL_TEXTURE_1D);

      gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
      gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);

      gl.glVertexPointer(2, GL2.GL_FLOAT, 0, vertexCoords.rewind());
      gl.glTexCoordPointer(1, GL2.GL_FLOAT, 0, textureCoords.rewind());

      try {
        gl.glDrawArrays(GL2.GL_QUAD_STRIP, 0, count);
      } finally {
        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
        gl.glDisable(GL2.GL_TEXTURE_1D);
      }
    }

    gl.glDisable(GL2.GL_TEXTURE_1D);

    outlineColorQuad(gl, axis, width, height);
  }
Ejemplo n.º 16
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);
 }
Ejemplo n.º 17
0
  /** ***************************************************** */
  public void draw(GL2 gl, GLU glu, Camera cam) {
    if (transform != null) transform.execute(gl);
    gl.glTranslatef(x, y, z);

    applyMaterial(gl);
    gl.glLineWidth(wfwidth);

    // Draw
    GLUquadric qobj = glu.gluNewQuadric();

    if (facestatus) {
      if (wfstatus) {
        gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
        gl.glPolygonOffset(1.0f, 1.0f);
      }

      gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
      gl.glNormal3f(norm.x, norm.y, norm.z);
      gl.glColor4f(color.r, color.g, color.b, color.a);
      glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops);

      if (wfstatus) gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL);
    }
    if (wfstatus) {
      gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
      gl.glNormal3f(norm.x, norm.y, norm.z);
      gl.glColor4f(wfcolor.r, wfcolor.g, wfcolor.b, wfcolor.a);
      glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops);
    }
  }
Ejemplo n.º 18
0
  private void renderBlast(GL2 gl) {
    GLU glu = new GLU();

    Shader shader = Shader.get("dissolve");
    if (shader != null) {
      shader.enable(gl);

      shader.setSampler(gl, "cloudSampler", 0);
      shader.setUniform(gl, "dissolveFactor", 1.0f - ((float) blastDuration / 60.0f));
    }

    gl.glEnable(GL2.GL_TEXTURE_2D);

    GLUquadric sphere = glu.gluNewQuadric();

    glu.gluQuadricDrawStyle(sphere, GLU.GLU_FILL);
    glu.gluQuadricTexture(sphere, true);

    gl.glPushMatrix();
    {
      noiseSampler.bind(gl);
      noiseSampler.setTexParameterf(gl, GL2.GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);

      gl.glTranslatef(bound.c.x, bound.c.y, bound.c.z);

      glu.gluSphere(sphere, blastRadius, 24, 24);
    }
    gl.glPopMatrix();
  }
Ejemplo n.º 19
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);
  }
Ejemplo n.º 20
0
  // Where the printing happens
  private void glPrint(GL2 gl, int x, int y, int set, String fmt) {

    // If There's No Text
    if (fmt == null) {
      return;
    }

    // Did User Choose An Invalid Character Set?
    if (set > 1) {
      // If So, Select Set 1 (Italic)
      set = 1;
    }

    gl.glEnable(GL.GL_TEXTURE_2D); // Enable Texture Mapping
    gl.glLoadIdentity(); // Reset The Modelview Matrix
    gl.glTranslated(x, y, 0); // Position The Text (0,0 - Top Left)
    gl.glListBase(base - 32 + (128 * set)); // Choose The Font Set (0 or 1)
    gl.glScalef(1.0f, 2.0f, 1.0f); // Make The Text 2X Taller

    if (stringBuffer.capacity() < fmt.length()) {
      stringBuffer = GLBuffers.newDirectByteBuffer(fmt.length());
    }

    stringBuffer.clear();
    stringBuffer.put(fmt.getBytes());
    stringBuffer.flip();
    // Write the text to the screen
    gl.glCallLists(fmt.length(), GL.GL_UNSIGNED_BYTE, stringBuffer);
    gl.glDisable(GL.GL_TEXTURE_2D); // Disable Texture Mapping
  }
Ejemplo n.º 21
0
  private void setFog() {

    gl.glEnable(GL2.GL_FOG);
    gl.glFogf(GL2.GL_FOG_START, 5.0f);
    gl.glFogf(GL2.GL_FOG_END, 50.0f);
    gl.glFogfv(GL2.GL_FOG_COLOR, new float[] {0.8f, 0.8f, 0.9f, 1.0f}, 0);
    gl.glFogi(GL2.GL_FOG_MODE, GL.GL_LINEAR);
  }
Ejemplo n.º 22
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.º 23
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);
    }
  }
Ejemplo n.º 24
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
    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 {
      // Create a OpenGL Texture object from (URL, mipmap, file suffix)
      // Use URL so that can read from JAR and disk file.
      texture =
          TextureIO.newTexture(
              this.getClass().getResource(textureFileName), false, textureFileType);
    } catch (GLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Use linear filter for texture if image is larger than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Use linear filter for texture if image is smaller than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    // 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();
    textureTop = textureCoords.top();
    textureBottom = textureCoords.bottom();
    //      textureLeft = textureCoords.left();
    //      textureRight = textureCoords.right();

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

    // we want back facing polygons to be filled completely and that we want front
    // facing polygons to be outlined only.
    gl.glPolygonMode(GL_BACK, GL_FILL); // Back Face Is Filled In
    gl.glPolygonMode(GL_FRONT, GL_LINE); // Front Face Is Drawn With Lines

    for (int x = 0; x < numPoints; x++) { // Loop Through The Y Plane
      for (int y = 0; y < numPoints; y++) {
        // Apply The Wave To Our Mesh
        // xmax is 45. Get 9 after dividing by 5. Subtract 4.5 to centralize.
        points[x][y][0] = (float) x / 5.0f - 4.5f;
        points[x][y][1] = (float) y / 5.0f - 4.5f;
        // Sine wave pattern
        points[x][y][2] = (float) (Math.sin(Math.toRadians(x / 5.0f * 40.0f)));
      }
    }
  }
Ejemplo n.º 25
0
 @Override
 public void init(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   gl.glClearColor(0, 0, 0, 0); // dene a cor de fundo
   gl.glEnable(GL2.GL_DEPTH_TEST); // remoção de superfície oculta
   gl.glMatrixMode(GL2.GL_PROJECTION); // dene que a matrix é a de projeção
   gl.glLoadIdentity(); // carrega a matrix de identidade
   gl.glOrtho(-5, 5, -5, 5, -5, 5); // dene uma projeção ortográca
 }
Ejemplo n.º 26
0
	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);
	}
Ejemplo n.º 27
0
 /** Render this material in OpenGL2. */
 public void render() {
   GL2 gl = GLContext.getCurrent().getGL().getGL2();
   gl.glEnable(GL2.GL_COLOR_MATERIAL);
   gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, ambient.getComponents(), 0);
   gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, diffuse.getComponents(), 0);
   gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, specular.getComponents(), 0);
   gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, emission.getComponents(), 0);
   gl.glMateriali(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, shininess);
 }
Ejemplo n.º 28
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.glDepthFunc(GL.GL_LESS);
   gl.glEnable(GL.GL_DEPTH_TEST);
   gl.glShadeModel(GL2.GL_FLAT);
   gl.glDepthRange(0.0, 1.0); /* The default z mapping */
 }
Ejemplo n.º 29
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.º 30
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;
    }
  }