Exemple #1
0
  public static void initPerspective(int width, int height, float zClose, float zFar) {
    fov = 55.0f;

    glEnable(GL_TEXTURE_2D);

    //		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    //		glEnable(GL_TEXTURE_2D);

    //		glEnable(GL_CULL_FACE);

    //		glShadeModel(GL_SMOOTH); // Enable Smooth Shading
    glClearDepth(1.0); // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST); // Enables Depth Testing
    glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    gluPerspective(fov, (float) width / height, zClose, zFar);
    //		glOrtho(1, 1, 1, 1, -1, 1);
    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

    // Really Nice Perspective Calculations
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // GL_DECAL);
  }
  /**
   * *************************************************************************************************************************************************************************************************
   * Initialization stuff comes in here...
   * ************************************************************************************************************************************************************************************************
   */
  private void init() {

    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setVSyncEnabled(true);
      Display.setTitle("MS3D Loader [G36C]");
      Display.create();

      Keyboard.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Initialization failed!\n\n" + e.getMessage());
      System.exit(0);
    }

    /* OpenGL */
    int width = Display.getDisplayMode().getWidth();
    int height = Display.getDisplayMode().getHeight();

    GL11.glViewport(0, 0, width, height); // Reset The Current Viewport
    GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Projection Matrix
    GLU.gluPerspective(
        45.0f,
        ((float) width / (float) height),
        0.1f,
        1000.0f); // Calculate The Aspect Ratio Of The Window
    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
    GL11.glLoadIdentity(); // Reset The Modelview Matrix

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background color
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    // Load model
    //		g36c = new
    // MS3DModel(resourceLoader.loadResourceAsStream("models/gsg9.ms3d"),this.getClass().getResource("./data/textures").getPath());
    g36c =
        new MS3DModel(
            resourceLoader.loadResourceAsStream("models/assassin.ms3d"),
            this.getClass().getResource("./data/textures").getPath());

    //		tdsLoader=new TDSLoader();
    //		try {
    //			tdsLoader.load(resourceLoader.loadResourceAsStream("models/face.3ds"));
    //			System.out.println(tdsLoader.getObjectSize());
    //		} catch (IOException e) {
    //			e.printStackTrace();
    //		}

    // Load font
    font = new Font(resourceLoader.loadResourceAsStream("textures/font.bmp"), 12, width, height);

    // Init timer
    timer = new Timer();
  }
  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);
  }
Exemple #4
0
 protected void setupGLState() {
   GL11.glPushAttrib(
       GL11.GL_ENABLE_BIT
           | GL11.GL_TRANSFORM_BIT
           | GL11.GL_HINT_BIT
           | GL11.GL_COLOR_BUFFER_BIT
           | GL11.GL_SCISSOR_BIT
           | GL11.GL_LINE_BIT
           | GL11.GL_TEXTURE_BIT);
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glPushMatrix();
   GL11.glLoadIdentity();
   GL11.glOrtho(0, width, height, 0, -1.0, 1.0);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glPushMatrix();
   GL11.glLoadIdentity();
   GL11.glEnable(GL11.GL_TEXTURE_2D);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glEnable(GL11.GL_LINE_SMOOTH);
   GL11.glDisable(GL11.GL_DEPTH_TEST);
   GL11.glDisable(GL11.GL_LIGHTING);
   GL11.glDisable(GL11.GL_SCISSOR_TEST);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
 }
Exemple #5
0
  public int loadTexture(String fileName) {
    Texture texture = null;
    try {
      texture =
          TextureLoader.getTexture(
              EngineSettings.TEXTURE_TYPE,
              new FileInputStream(
                  EngineSettings.RES_TEXTURE_LOC
                      + fileName
                      + "."
                      + EngineSettings.TEXTURE_TYPE.toLowerCase()));
      GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
      GL11.glTexParameteri(
          GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
      GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 15f);
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_FASTEST);
    } catch (IOException e) {
      e.printStackTrace();
    }

    int textureID = texture.getTextureID();
    textures.add(textureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    return textureID;
  }
  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 -----------//

  }
  /**
   * Returns true to apply default vanilla values to fog position. Can be overridden to configure
   * fog GL settings.
   */
  @SideOnly(Side.CLIENT)
  public boolean setupFog() {
    float voidFactor = (float) EndTerritory.getVoidFactor(Minecraft.getMinecraft().thePlayer);
    float fogMultiplier = Math.max(1F, MathUtil.square(voidFactor * 0.8F + 0.8F));

    GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP2);
    GL11.glFogf(GL11.GL_FOG_DENSITY, getFogDensity() * fogMultiplier);
    GL11.glHint(GL11.GL_FOG_HINT, GL11.GL_DONT_CARE);
    return true;
  }
 public static void drawTTFString(CustomFont f, String text, double x, double y, int color) {
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glDisable(GL11.GL_DEPTH_TEST);
   GL11.glEnable(GL11.GL_POINT_SMOOTH);
   GL11.glHint(GL11.GL_POINT_SMOOTH_HINT, GL11.GL_NICEST);
   GL11.glDepthMask(false);
   f.drawGoodString(mc.ingameGUI, text, x, y, color, false);
   GL11.glDepthMask(true);
   GL11.glDisable(GL11.GL_POINT_SMOOTH);
   GL11.glEnable(GL11.GL_DEPTH_TEST);
   GL11.glDisable(GL11.GL_BLEND);
 }
Exemple #9
0
  private void doRenderLoop() {
    try {
      while (!isDisplayable()) {
        Thread.sleep(50);
      }
      Display.setParent(this);
      Display.setVSyncEnabled(true);
      Display.create();
      mMouseState = new boolean[Mouse.getButtonCount()];
      for (int i = 0; i < mMouseState.length; i++) {
        mMouseState[i] = Mouse.isButtonDown(i);
      }

      // GL11.glsetSwapInterval(1);
      GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
      // gl11.glColor3f(1.0f, 0.0f, 0.0f);
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      GL11.glClearDepth(1.0);
      GL11.glLineWidth(2);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      if (mScene.getAmbientLight() != null) {
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glLightModel(
            GL11.GL_LIGHT_MODEL_AMBIENT, Color4fLogic.toFloatBuffer(mScene.getAmbientLight()));
      }
      if (mScene.getColorMaterialFace() != JGLColorMaterialFace.UNSET) {
        initMaterial();
      }
      if (mScene.getFogMode() != JGLFogMode.UNSET) {
        initFog();
      }

      Dimension newDim;

      while (!Display.isCloseRequested() && !mCloseRequested) {
        newDim = mNewCanvasSize.getAndSet(null);
        if (newDim != null) {
          GL11.glViewport(0, 0, newDim.width, newDim.height);
          syncViewportSize();
        }
        doRender();
        doMouse();
        doKeys();
        doEye();
        Display.update();
      }

      Display.destroy();
    } catch (InterruptedException | LWJGLException e) {
      e.printStackTrace();
    }
  }
Exemple #10
0
  private void establishProjectionMatrix() {
    // glViewport(0, 0, WIDTH, HEIGHT);

    // Reset Projection matrix
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0f, (float) WIDTH / (float) HEIGHT, 0.1f, 200.0f);

    // Try to use the nicest calc
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glEnable(GL_PERSPECTIVE_CORRECTION_HINT);
  }
Exemple #11
0
  public void setUpFog() {
    glEnable(GL_FOG);

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

    glFogi(GL_FOG_MODE, GL_LINEAR);
    glFog(GL_FOG_COLOR, fogColor);
    glFogf(GL_FOG_DENSITY, 0.005f);
    glHint(GL_FOG_HINT, GL_NICEST);
    glFogf(GL_FOG_START, 300.0f);
    glFogf(GL_FOG_END, 2000.0f);

    glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
  }
Exemple #12
0
 public static void initOpenGL() {
   GLPrep.resizedRefresh();
   GL11.glEnable(GL11.GL_ALPHA_TEST); // allows alpha channels or
   // transperancy
   GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f); // set alpha aceptance
   GL11.glEnable(GL11.GL_COLOR_MATERIAL);
   GL11.glDisable(GL11.GL_DITHER);
   GL11.glShadeModel(GL11.GL_SMOOTH); // smooth shading
   GL11.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
   GL11.glDepthMask(true); // turn on depth mask
   GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
   GL11.glDepthFunc(GL11.GL_ALWAYS); // The Type Of Depth Test To Do
   GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
   GL11.glEnable(GL11.GL_TEXTURE_2D); // enable 2d textures
   RenderManager.registerRenders();
 }
Exemple #13
0
  // ***************************************************************************
  // initGL
  // ***************************************************************************
  private static boolean initGL() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    // Calculate the aspect ratio of the window
    GLU.gluPerspective(45.0f, ((float) targetWidth) / ((float) targetHeight), 0.1f, 100.0f);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // Enable Texture Mapping (NEW)
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    return true;
  }
  private static void initWindow(int w, int h) {
    HEIGHT = h;
    WIDTH = w;
    // Configure our window
    glfwDefaultWindowHints(); // optional, the current window hints are already the default
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    glfwWindowHint(GLFW_DECORATED, GL_FALSE);
    glfwWindowHint(GLFW_DOUBLE_BUFFER, GL_TRUE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    // glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    // Create the window
    window = glfwCreateWindow(WIDTH, HEIGHT, "GameEngine", glfwGetPrimaryMonitor(), NULL);
    if (window == NULL) throw new RuntimeException("Failed to create the GLFW window");

    // Get the resolution of the primary monitor
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Center our window
    glfwSetWindowPos(window, (vidmode.width() - WIDTH) / 2, (vidmode.height() - HEIGHT) / 2);

    // Make the OpenGL context current
    glfwMakeContextCurrent(window);
    // GLContext.createFromCurrent();
    // Enable v-sync
    glfwSwapInterval(1);
    GL.createCapabilities();
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    // glEnable(GL_DEPTH_TEST);
    // glDepthFunc(GL_LESS);
    // glDepthMask(true);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    // glDisable(GL_DEPTH_TEST);

    glClearColor(0.20f, 0.10f, 0.20f, 1.0f);
  }
Exemple #15
0
  public static void init(VorxelSettings set, Geode gamep) {
    world = new World();
    game = gamep;
    try {
      DisplayMode d[] = Display.getAvailableDisplayModes();
      DisplayMode displayMode = d[0];
      Display.setDisplayMode(displayMode);
      Display.create();

      Mouse.create();
      Keyboard.create();

      GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
      GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
      GL11.glClearDepth(1.0); // Depth Buffer Setup
      GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
      GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

      GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
      GL11.glLoadIdentity(); // Reset The Projection Matrix
      // Calculate The Aspect Ratio Of The Window
      GLU.gluPerspective(
          45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 100.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

      // Really Nice Perspective Calculations
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      TextureHelper.init();
      Cube.dirt.texture = new VTex(4);
      Cube.grass.texture = Cube.dirt.texture;
      Cube.grass.toptexture = new VTex(1);
      Mouse.setGrabbed(true);
      world.createSpawn();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
  }
Exemple #16
0
  @Override
  public void init() throws IOException {
    super.init();

    screen.setTitle("MD2 Loader");

    createGameActions();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 800 / 600, 1.0f, 2000.0f);
    glMatrixMode(GL_MODELVIEW);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // Here, we turn on a lighting and enable lighting.  We don't need to
    // set anything else for lighting because we will just take the defaults.
    // We also want color, so we turn that on

    // Habilita Z-Buffer
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHT0); // Turn on a light with defaults set
    glEnable(GL_LIGHTING); // Turn on lighting
    glEnable(GL_COLOR_MATERIAL); // Allow color

    // To make our model render somewhat faster, we do some front back culling.
    // It seems that Quake2 orders their polygons clock-wise.
    // Seleciona o modo de aplicação da textura
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, modo);
    glEnable(GL_CULL_FACE); // Turn culling on
    glCullFace(GL_FRONT);
    glEnable(GL_TEXTURE_2D);
    g_World.load(FILE_NAME);
    // g_LoadMd2.importMD2(g_World, "modelsd2/model8/head.md2", "modelsd2/model8/head.png");
    // g_LoadMd2.importMD2(g_World, "modelsd2/model8/throne.md2", "modelsd2/model8/throne.png");
  }
Exemple #17
0
  @Override
  protected void init() {
    glEnable(GL_LINE_SMOOTH);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // brak efektu na moim kompie
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glMatrixMode(GL_PROJECTION); // chcemy zrobić coś na macierzy projekcji
    glLoadIdentity();
    if (width > height) {
      glOrtho(-5 * (float) width / height, 5 * (float) width / height, -5, 5, -5, 5);
    } else {

      glOrtho(-5, 5, -5 * (float) height / width, 5 * (float) height / width, -5, 5);
    }
    // glTranslatef(-0.5f, -0.5f, 0);
    // glScalef(0.5f, 0.5f, 0.5f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(1, 1, 1, 0, 0, 0, 0, 1, 0);
    // glScalef(0.5f, 0.5f, 0.5f);

    buffer.rewind();
    buffer.put(data);
    buffer.rewind();

    brickIndices.rewind();
    brickIndices.put(indidata);
    brickIndices.rewind();

    paintedWall.rewind();
    paintedWall.put(paintedWallindi);
    paintedWall.rewind();

    glInterleavedArrays(GL_C3F_V3F, 0, buffer);
  }
  public static void drawLine(
      double x,
      double y,
      double x2,
      double y2,
      float r,
      float g,
      float b,
      float te,
      boolean wiggle) {
    float count =
        FMLClientHandler.instance().getClient().thePlayer.ticksExisted
            + new Random().nextFloat()
            + te;

    Tessellator var12 = Tessellator.instance;

    GL11.glPushMatrix();
    GL11.glAlphaFunc(516, 0.003921569F);
    GL11.glDisable(3553);
    GL11.glEnable(3042);
    GL11.glBlendFunc(770, 771);

    double d3 = x - x2;
    double d4 = y - y2;
    float dist = MathHelper.sqrt_double(d3 * d3 + d4 * d4);
    int inc = (int) (dist / 2.0F);
    float dx = (float) (d3 / inc);
    float dy = (float) (d4 / inc);
    if (Math.abs(d3) > Math.abs(d4)) {
      dx *= 2.0F;
    } else {
      dy *= 2.0F;
    }
    GL11.glLineWidth(3.0F);
    GL11.glEnable(2848);
    GL11.glHint(3154, 4354);

    var12.startDrawing(3);
    for (int a = 0; a <= inc; a++) {
      float r2 = r;
      float g2 = g;
      float b2 = b;
      float mx = 0.0F;
      float my = 0.0F;
      float op = 0.6F;
      if (wiggle) {
        float phase = a / inc;
        mx = MathHelper.sin((count + a) / 7.0F) * 5.0F * (1.0F - phase);
        my = MathHelper.sin((count + a) / 5.0F) * 5.0F * (1.0F - phase);
        r2 *= (1.0F - phase);
        g2 *= (1.0F - phase);
        b2 *= (1.0F - phase);
        op *= phase;
      }
      var12.setColorRGBA_F(r2, g2, b2, op);

      var12.addVertex(x - dx * a + mx, y - dy * a + my, 0.0D);
      if (Math.abs(d3) > Math.abs(d4)) {
        dx *= (1.0F - 1.0F / (inc * 3.0F / 2.0F));
      } else {
        dy *= (1.0F - 1.0F / (inc * 3.0F / 2.0F));
      }
    }
    var12.draw();

    GL11.glBlendFunc(770, 771);
    GL11.glDisable(2848);
    GL11.glDisable(3042);
    GL11.glDisable(32826);
    GL11.glEnable(3553);
    GL11.glAlphaFunc(516, 0.1F);
    GL11.glPopMatrix();
  }
Exemple #19
0
 public void glHint(int target, int mode) {
   GL11.glHint(target, mode);
 }
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
      GLContext.useContext(canvas);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    canvas.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
              GLContext.useContext(canvas);
            } catch (LWJGLException e) {
              e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
          }
        });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    display.asyncExec(
        new Runnable() {
          int rot = 0;

          public void run() {
            if (!canvas.isDisposed()) {
              canvas.setCurrent();
              try {
                GLContext.useContext(canvas);
              } catch (LWJGLException e) {
                e.printStackTrace();
              }
              GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
              GL11.glClearColor(.3f, .5f, .8f, 1.0f);
              GL11.glLoadIdentity();
              GL11.glTranslatef(0.0f, 0.0f, -10.0f);
              float frot = rot;
              GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
              GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
              rot++;
              GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
              GL11.glColor3f(0.9f, 0.9f, 0.9f);
              drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
              canvas.swapBuffers();
              display.asyncExec(this);
            }
          }
        });

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }