Exemplo n.º 1
0
  public static void setupLighting() {
    FloatBuffer lightPosition = BufferUtils.createFloatBuffer(4);
    lightPosition.put(0.0f).put(0.0f).put(0.0f).put(0.0f).flip();

    FloatBuffer whiteLight = BufferUtils.createFloatBuffer(4);
    whiteLight.put(1.0f).put(1.0f).put(1.0f).put(1.0f).flip();

    FloatBuffer lModelAmbient = BufferUtils.createFloatBuffer(4);
    lModelAmbient.put(0.4f).put(0.4f).put(0.4f).put(1.0f).flip();

    glShadeModel(GL_SMOOTH);
    glMaterial(GL_FRONT, GL_SPECULAR, whiteLight);
    glMaterialf(GL_FRONT, GL_SHININESS, 50.0f);

    glLight(GL_LIGHT0, GL_POSITION, lightPosition);
    glLight(GL_LIGHT0, GL_SPECULAR, whiteLight);
    glLight(GL_LIGHT0, GL_DIFFUSE, whiteLight);
    glLightModel(GL_LIGHT_MODEL_AMBIENT, lModelAmbient);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  }
Exemplo n.º 2
0
 private void initMaterial() {
   int face = conv(mScene.getColorMaterialFace());
   GL11.glEnable(GL11.GL_COLOR_MATERIAL);
   if (mScene.getColorMaterialFace() != JGLColorMaterialFace.UNSET) {
     GL11.glColorMaterial(face, conv(mScene.getColorMaterialMode()));
   }
   if (mScene.getMaterialAmbient() != null) {
     GL11.glMaterial(
         face, GL11.GL_AMBIENT, Color4fLogic.toFloatBuffer(mScene.getMaterialAmbient()));
   }
   if (mScene.getMaterialDiffuse() != null) {
     GL11.glMaterial(
         face, GL11.GL_DIFFUSE, Color4fLogic.toFloatBuffer(mScene.getMaterialDiffuse()));
   }
   if (mScene.getMaterialSpecular() != null) {
     GL11.glMaterial(
         face, GL11.GL_SPECULAR, Color4fLogic.toFloatBuffer(mScene.getMaterialSpecular()));
   }
   if (mScene.getMaterialEmission() != null) {
     GL11.glMaterial(
         face, GL11.GL_EMISSION, Color4fLogic.toFloatBuffer(mScene.getMaterialEmission()));
   }
   if (mScene.getMaterialShininess() >= 0) {
     GL11.glMaterialf(face, GL11.GL_SHININESS, mScene.getMaterialShininess());
   }
 }
Exemplo n.º 3
0
  public void initialize() {
    if (GLContext.getCapabilities().OpenGL12) {
      gl12 = true;
    }

    // Default values for certain GL state.
    glShadeModel(GL_SMOOTH);
    glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // Enable rescaling/normaling of normal vectors.
    // Fixes lighting issues with scaled models.
    if (gl12) {
      glEnable(GL12.GL_RESCALE_NORMAL);
    } else {
      glEnable(GL_NORMALIZE);
    }

    if (GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) {
      caps.add(Caps.NonPowerOfTwoTextures);
    } else {
      logger.log(
          Level.WARNING,
          "Your graphics card does not "
              + "support non-power-of-2 textures. "
              + "Some features might not work.");
    }

    maxLights = glGetInteger(GL_MAX_LIGHTS);
    maxTexSize = glGetInteger(GL_MAX_TEXTURE_SIZE);
  }
Exemplo n.º 4
0
 public static void func_74519_b() {
   GL11.glEnable(2896);
   GL11.glEnable(16384);
   GL11.glEnable(16385);
   GL11.glEnable(2903);
   GL11.glColorMaterial(1032, 5634);
   float var0 = 0.4F;
   float var1 = 0.6F;
   float var2 = 0.0F;
   GL11.glLight(
       16384,
       4611,
       func_74517_a(
           field_82884_b.field_72450_a,
           field_82884_b.field_72448_b,
           field_82884_b.field_72449_c,
           0.0D));
   GL11.glLight(16384, 4609, func_74521_a(var1, var1, var1, 1.0F));
   GL11.glLight(16384, 4608, func_74521_a(0.0F, 0.0F, 0.0F, 1.0F));
   GL11.glLight(16384, 4610, func_74521_a(var2, var2, var2, 1.0F));
   GL11.glLight(
       16385,
       4611,
       func_74517_a(
           field_82885_c.field_72450_a,
           field_82885_c.field_72448_b,
           field_82885_c.field_72449_c,
           0.0D));
   GL11.glLight(16385, 4609, func_74521_a(var1, var1, var1, 1.0F));
   GL11.glLight(16385, 4608, func_74521_a(0.0F, 0.0F, 0.0F, 1.0F));
   GL11.glLight(16385, 4610, func_74521_a(var2, var2, var2, 1.0F));
   GL11.glShadeModel(7424);
   GL11.glLightModel(2899, func_74521_a(var0, var0, var0, 1.0F));
 }
Exemplo n.º 5
0
  private void initGL() {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // sets background to grey
    glClearDepth(1.0f); // clear depth buffer
    glEnable(GL_DEPTH_TEST); // Enables depth testing
    glDepthFunc(GL_LEQUAL); // sets the type of test to use for depth testing
    glMatrixMode(GL_PROJECTION); // sets the matrix mode to project

    // GLU.gluOrtho2D(-10, 10, -10, 10);
    // GLU.gluOrtho2D(0 - COORD_WIDTH / 2, 0 + COORD_WIDTH / 2, 0 - COORD_HEIGHT / 2, 0 +
    // COORD_HEIGHT / 2);
    float fovy = 90.0f;
    float aspect = DISPLAY_MODE.getWidth() / (float) DISPLAY_MODE.getHeight();
    float zNear = 0.1f;
    float zFar = 20000.0f;
    GLU.gluPerspective(fovy, aspect, zNear, zFar);

    glViewport(0, 0, DISPLAY_MODE.getWidth(), DISPLAY_MODE.getHeight());
    // GLU.gluOrtho2D(-10, 10, -10, 10);
    // GLU.gluOrtho2D(-1, 1, -1, 1);

    glOrtho(
        0 - COORD_WIDTH / 2,
        0 + COORD_WIDTH / 2,
        0 - COORD_HEIGHT / 2,
        0 + COORD_HEIGHT / 2,
        zNear,
        zFar);

    System.out.println(COORD_WIDTH + ", " + COORD_HEIGHT);

    glMatrixMode(GL_MODELVIEW);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // ----------- Variables & method calls added for Lighting Test -----------//
    initLightArrays();
    glShadeModel(GL_SMOOTH);
    glMaterial(GL_FRONT, GL_SPECULAR, matSpecular); // sets specular material color
    glMaterialf(GL_FRONT, GL_SHININESS, 50.0f); // sets shininess

    glLight(GL_LIGHT0, GL_POSITION, lightPosition); // sets light position
    glLight(GL_LIGHT0, GL_SPECULAR, whiteLight); // sets specular light to white
    glLight(GL_LIGHT0, GL_DIFFUSE, whiteLight); // sets diffuse light to white
    glLightModel(GL_LIGHT_MODEL_AMBIENT, lModelAmbient); // global ambient light

    glEnable(GL_LIGHTING); // enables lighting
    glEnable(GL_LIGHT0); // enables light0

    glEnable(GL_COLOR_MATERIAL); // enables opengl to use glColor3f to define material color
    glColorMaterial(
        GL_FRONT,
        GL_AMBIENT_AND_DIFFUSE); // tell opengl glColor3f effects the ambient and diffuse properties
                                 // of material
    // ----------- END: Variables & method calls added for Lighting Test -----------//

  }
Exemplo n.º 6
0
 public void setUpLighting() {
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glLightModel(GL_LIGHT_MODEL_AMBIENT, asFloatBuffer(new float[] {1.00f, 1.00f, 1.00f, 1f}));
   glLight(GL_LIGHT0, GL_POSITION, asFloatBuffer(new float[] {10000, 0, 0, 1}));
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT, GL_DIFFUSE);
 }
Exemplo n.º 7
0
  public void render() {
    if (((ViewerContainer3D) v.getContainer()).getPbuffer() != currentPbuffer) {
      for (int i = 0; i < vbo.length; i++) {
        vbo[i] = -1;
        selectedVbo[i] = -1;
      }
      currentPbuffer = ((ViewerContainer3D) v.getContainer()).getPbuffer();
    }

    for (int i = 0; i < tubes.length; i++) {
      if (hidden[i]) continue;

      int vbo;
      if (!selected[i]) {
        if (this.vbo[i] == -1) {
          Color c = colors[i];
          GL15.glDeleteBuffers(this.vbo[i]);
          this.vbo[i] = createTubeVbo(i, colors[i]);
        }
        vbo = this.vbo[i];
      } else {
        if (this.selectedVbo[i] == -1) {
          Color c = selectedColors[i];
          GL15.glDeleteBuffers(this.selectedVbo[i]);
          this.selectedVbo[i] = createTubeVbo(i, selectedColors[i]);
        }
        vbo = this.selectedVbo[i];
      }

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);

      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);

      GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
      GL11.glEnable(GL11.GL_COLOR_MATERIAL);

      GL11.glColorPointer(3, GL11.GL_FLOAT, vertexStride, colorPointer);
      GL11.glVertexPointer(3, GL11.GL_FLOAT, vertexStride, vertexPointer);
      GL11.glNormalPointer(GL11.GL_FLOAT, vertexStride, normalPointer);

      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, totalNumVerts[i]);

      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
      GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
      GL11.glDisable(GL11.GL_COLOR_MATERIAL);

      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    }
  }
Exemplo n.º 8
0
 private static void setUpLighting() {
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glLightModel(
       GL_LIGHT_MODEL_AMBIENT,
       BufferTools.asFlippedFloatBuffer(new float[] {0.05f, 0.05f, 0.05f, 1f}));
   glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(new float[] {0, 0, 0, 1}));
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT, GL_DIFFUSE);
 }
Exemplo n.º 9
0
 public void renderBackground(float paramRed, float paramGreen, float paramBlue) {
   glPushMatrix();
   glDisable(GL_BLEND);
   glBegin(GL_QUADS);
   glColor3f(paramRed, paramGreen, paramBlue);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
   glNormal3f(0f, 0f, 1.0f);
   glVertex2f(0, 0);
   glVertex2f(Display.getWidth(), 0);
   glVertex2f(Display.getWidth(), Display.getHeight());
   glVertex2f(0, Display.getHeight());
   glEnd();
   glPopMatrix();
 }
 private static void setUpStates() {
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glLightModel(
       GL_LIGHT_MODEL_AMBIENT,
       BufferTools.asFlippedFloatBuffer(new float[] {0.05f, 0.05f, 0.05f, 1f}));
   glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(new float[] {0, 0, 0, 1}));
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT, GL_DIFFUSE);
   glColor3f(0.4f, 0.27f, 0.17f);
   glMaterialf(GL_FRONT, GL_SHININESS, 10f);
   if (GLContext.getCapabilities().GL_ARB_depth_clamp) {
     glEnable(ARBDepthClamp.GL_DEPTH_CLAMP);
   }
 }