Ejemplo n.º 1
0
  public void render3D() {
    actor.lookThrough();
    //		GL.rotate(rot, rot, rot);
    flashlight.run();

    //		flashlight.uniform1i("time", (int)System.currentTimeMillis());
    //		flashlight.uniform1i("counter", dfps % 8);
    flashlight.uniform1i("fboSupported", frameBuffer.isSupported() ? 1 : 0);
    flashlight.uniform3f("camPos", actor.getX(), actor.getY(), actor.getZ());
    flashlight.uniform3f("flashlightPos", actor.getX(), actor.getY(), actor.getZ());
    flashlight.uniform3f("specColor", 1, 1, 1);
    flashlight.uniform1f("intensity", 1);
    flashlight.uniform1i("lightNumber", 0);
    //		flashlight.uniform4f("lightModelViewProjectionMatrix", shadowMatrix);
    flashlight.uniform1i("shadowMap", 0);
    //		GL.setReflection(new Point(0.5f, 0.5f, 0.5f));
    //		GL.setShininess(100);

    world3D.render(GL.QUADS, 0, 4 * 6, sprites);
    world3D.render(GL.QUADS, 4 * 6, 4 * 6, tile);
    world3D.render(GL.QUADS, 4 * 6 * 2, 4 * 6 * amountX * amountZ, sprites);

    flashlight.stop();
  }
Ejemplo n.º 2
0
  public void init() {
    rot = 0;

    BufferedImage image = null;

    try {
      sprites = new SpriteSheet("res/images/sprites.png", 36, 18);
      brick = new Texture("res/images/brick.png");
      tile = new Texture("res/images/tile.png");
    } catch (IOException e) {
      e.printStackTrace();
    }

    amountX = 220;
    amountZ = 220;

    loc = 2.5f;

    world2D = new Bundle(4 * 3, 2, true, false);
    world3D = new Bundle((4 * 6 * 2) + (4 * 6 * amountX * amountZ), 3, true, false);

    world2D.beginEditingVertices();
    world2D.addVertices(GL.genRectVerts(0, 0, 100, 100));
    world2D.endEditingVertices();

    world2D.beginEditingTextures();
    world2D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world2D.endEditingTextures();

    world3D.beginEditingTextures();
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
    world3D.endEditingTextures();

    world3D.beginEditingVertices();
    world3D.addVertices(GL.genCubeVerts(0, loc, -10, 2, 2, 2));

    world3D.addVertices(GL.genCubeVerts(-100, -2, -100, 200, 2, 200));
    world3D.endEditingVertices();

    world3D.beginEditingTextures();
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));

    for (int z = 0; z < amountZ; z++) {
      for (int x = 0; x < amountX; x++) {
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
      }
    }

    world3D.endEditingTextures();

    world3D.beginEditingVertices();
    for (int z = 0; z < amountZ; z++) {
      for (int x = 0; x < amountX; x++) {
        world3D.addVertices(GL.genCubeVerts(x * 4, y, z * 4, 2, 2, 2));
      }
    }

    world3D.endEditingVertices();

    //		world3D.beginEditingColors();
    //
    //		world3D.setColors(0, GL.genRectColors(0.5f, 0.5f, 0.5f, 1));
    //
    //		for (int i = 0; i < 100000; i++)
    //		{
    //			world3D.addColors(GL.genRectColors(0.5f, 0.5f, 0.5f, 1));
    //		}
    //
    //		world3D.endEditingColors();

    font =
        new Font(
            "res/images/fonts/font.png",
            26,
            4,
            new char[] {
              'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                  'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
              'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
                  'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '-', '+', '=', '~', '`', '!',
                  '@', '#', '$', '%', '^', '&', '*', '(', ')',
              '?', '>', '<', ';', ':', '\'', '"', '{', '}', '[', ']', '\\', '|', ',', '.', '/', ' ',
                  ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
            });

    actor = new Actor();
    actor.setLocation(0, 2, 0);

    flashlight = new Shader();
    flashlight.loadFile(
        new String[] {"res/shaders/vertex.vs"},
        new String[] {
          "res/shaders/vertex.fs",
          "res/shaders/flashlight.shade",
          "res/shaders/diffuseLights.shade",
        });

    try {
      frameBuffer = new FrameBuffer();
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    }

    rising = true;
  }