Exemplo n.º 1
0
  @Override
  protected void init() {
    initializeProgram();

    try {
      cylinderMesh = new Mesh("UnitCylinder.xml");
      planeMesh = new Mesh("LargePlane.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);
    glEnable(GL_DEPTH_CLAMP);

    projectionUniformBuffer = glGenBuffers();
    glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, ProjectionBlock.SIZE, GL_DYNAMIC_DRAW);

    // Bind the static buffers.
    glBindBufferRange(
        GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, ProjectionBlock.SIZE);

    glBindBuffer(GL_UNIFORM_BUFFER, 0);
  }
Exemplo n.º 2
0
 @Override
 public void click(Point p) {
   checked = !checked;
   try {
     if (call != null) call.click(this);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Exemplo n.º 3
0
  public TextureTest() {
    try {
      FileInputStream s = new FileInputStream("textures/texture1.png");
      t = TextureLoader.getTexture("PNG", s);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  private static TextureResource loadTexture(String fileName) {
    String[] splitArray = fileName.split("\\.");
    String ext = splitArray[splitArray.length - 1];

    try {
      BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName));
      int[] pixels =
          image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());

      ByteBuffer buffer = Util.createByteBuffer(image.getHeight() * image.getWidth() * 4);
      boolean hasAlpha = image.getColorModel().hasAlpha();

      for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
          int pixel = pixels[y * image.getWidth() + x];

          buffer.put((byte) ((pixel >> 16) & 0xFF));
          buffer.put((byte) ((pixel >> 8) & 0xFF));
          buffer.put((byte) ((pixel) & 0xFF));
          if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF));
          else buffer.put((byte) (0xFF));
        }
      }

      buffer.flip();

      TextureResource resource = new TextureResource();
      glBindTexture(GL_TEXTURE_2D, resource.getId());

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      glTexImage2D(
          GL_TEXTURE_2D,
          0,
          GL_RGBA8,
          image.getWidth(),
          image.getHeight(),
          0,
          GL_RGBA,
          GL_UNSIGNED_BYTE,
          buffer);

      return resource;
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

    return null;
  }
  @Override
  protected void init() {
    initializePrograms();

    try {
      realHallway = new Mesh("RealHallway.xml");
      fauxHallway = new Mesh("FauxHallway.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }
  }
Exemplo n.º 6
0
 /**
  * Application init
  *
  * @param args Commandline args
  */
 public static void main(String[] args) {
   try {
     init(false);
     run();
   } catch (Exception e) {
     e.printStackTrace(System.err);
     Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
   } finally {
     cleanup();
   }
   System.exit(0);
 }
Exemplo n.º 7
0
 public static void init(int w, int h) {
   try {
     initGL();
     initWindow(w, h);
     initShader();
     // initTexture();
     // initModel();
     loadGraphicData("data/graphic.data");
     // camera.setCameraBound(20.0f, -1.0f, -10f, 10f);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 8
0
  @Override
  protected void init() {
    glClearColor(0, 0, 0, 0);
    glPixelZoom(1, -1);

    try {
      for (int i = 0; i < fonts.length; ++i) {
        fonts[i] = new Font(new File(FONT_NAMES[i]), FONT_MAPS[i], width, height);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
Exemplo n.º 9
0
  public void Load() {
    mCamera = new Camera(GetGameWindow());

    Light.Load(mGameWindow.Width(), mGameWindow.Height());
    ComplexPolygon.Load(mGameWindow.Width(), mGameWindow.Height());

    mShadowMask = new Texture(mGameWindow.Width(), mGameWindow.Height());

    try {
      mShadowMaskObject = new FrameBufferObject(mShadowMask);
    } catch (Exception e) {
      e.printStackTrace();
    }

    mCamera.ForceScaleFocus((mGameWindow.Width() / 1600.0f + mGameWindow.Height() / 900.0f) / 2);

    mAmbientLighting = 0.0f;
  }
Exemplo n.º 10
0
  private int load(String path) {
    int[] pixels = null;
    try {
      BufferedImage image = ImageIO.read(new FileInputStream(path));
      width = image.getWidth();
      height = image.getHeight();
      pixels = new int[width * height];
      image.getRGB(0, 0, width, height, pixels, 0, width);
    } catch (Exception e) {
      e.printStackTrace();
    }

    int[] data = new int[width * height];
    for (int i = 0; i < width * height; i++) {
      int a = (pixels[i] & 0xff000000) >> 24;
      int r = (pixels[i] & 0xff0000) >> 16;
      int g = (pixels[i] & 0xff00) >> 8;
      int b = (pixels[i] & 0xff);

      data[i] = a << 24 | b << 16 | g << 8 | r;
    }

    int result = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, result);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA,
        width,
        height,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        BufferUtils.createIntBuffer(data));
    glBindTexture(GL_TEXTURE_2D, 0);

    return result;
  }
Exemplo n.º 11
0
  void renderLoop() {
    long startTime = System.currentTimeMillis() + 5000;
    long fps = 0;

    while (glfwWindowShouldClose(window.handle) == GLFW_FALSE) {
      Runnable event;
      while ((event = events.poll()) != null) event.run();

      try {
        display();
      } catch (Exception e) {
        e.printStackTrace();
        break;
      }

      glfwSwapBuffers(window.handle);

      if (startTime > System.currentTimeMillis()) {
        fps++;
      } else {
        long timeUsed = 5000 + (startTime - System.currentTimeMillis());
        startTime = System.currentTimeMillis() + 5000;
        log(
            String.format(
                "%s: %d frames in 5 seconds = %.2f",
                getPlatformInfoStringUTF8(platform, CL_PLATFORM_VENDOR),
                fps,
                fps / (timeUsed / 1000f)));
        fps = 0;
      }
    }

    cleanup();

    window.signal.countDown();
  }
  @Override
  protected void onStart() {
    INSTANCE = this;

    RENDER_THREAD_ID = Thread.currentThread().getId();

    try {
      loadIcons();
      Display.setIcon(icons);
      Display.setVSyncEnabled(GameSettings.Graphics.vsync);
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      setDisplayMode(
          GameSettings.Display.window_width,
          GameSettings.Display.window_height,
          GameSettings.Display.fullscreen);
      Display.create();
      // ROBO //todo get all this changed to proper OGL
      glClearColor(0f, 0f, 0f, 1f);
      glClearDepth(1f);
      glViewport(0, 0, GameSettings.Display.window_width, GameSettings.Display.window_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      glOrtho(
          0.0f,
          GameSettings.Display.resolution.getWidth(),
          GameSettings.Display.resolution.getHeight(),
          0.0f,
          0.1f,
          -1f);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      glLoadIdentity();
      curAlpha = 1f;
      capabilities = GLContext.getCapabilities();

      System.out.println("OpenGL version: " + glGetString(GL_VERSION));

      System.out.println("Building shaders..");
      long ms = getTime();
      ShaderFactory.buildAllShaders();
      System.out.println("Done! Took " + (getTime() - ms) + "ms.");

    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    } finally {
      if (looping) {
        looping = false;
        Display.destroy();
      }
    }

    started = getTime();
    next_tick = getTime();
    getDelta();
  }