Esempio n. 1
0
  /* (non-Javadoc)
   * @see chu.engine.Game#init(int, int, java.lang.String)
   */
  public void init(int width, int height, String name) {
    super.init(width, height, name);
    Player p1 = new Player("Player", (byte) 0);
    localPlayer = p1;
    ByteBuffer icon16, icon32;
    icon16 = icon32 = null;
    try {
      icon16 =
          ByteBuffer.wrap(
              TextureLoader.getTexture(
                      "PNG", ResourceLoader.getResourceAsStream("res/gui/icon16.png"))
                  .getTextureData());
      icon32 =
          ByteBuffer.wrap(
              TextureLoader.getTexture(
                      "PNG", ResourceLoader.getResourceAsStream("res/gui/icon32.png"))
                  .getTextureData());
    } catch (IOException e) {
      e.printStackTrace();
    }
    Display.setIcon(new ByteBuffer[] {icon16, icon32});
    FEResources.loadResources();
    FEResources.loadBitmapFonts();
    WeaponFactory.loadWeapons();
    UnitFactory.loadUnits();
    p1.getParty().setColor(Party.TEAM_BLUE);

    /* OpenGL final setup */
    glEnable(GL_LINE_SMOOTH);

    UnitFactory.getUnit("Lyn");
    connect = new ConnectStage();
    setCurrentStage(new TitleStage());
    SoundTrack.loop("main");
  }
Esempio n. 2
0
  @Override
  public void draw(boolean flip) {
    try {
      if (ladder != null) GL11.glDeleteTextures(ladder.getTextureID());
      ladder =
          TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/amobox.png"));
    } catch (IOException e) {
      e.printStackTrace();
    }
    ladder.bind();
    GL11.glLoadIdentity();
    GL11.glTranslated(x, y, 0);

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(100, 100);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2f(100 + ladder.getTextureWidth(), 100);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2f(100 + ladder.getTextureWidth(), 100 + ladder.getTextureHeight());
    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2f(100, 100 + ladder.getTextureHeight());
    GL11.glEnd();
    GL11.glLoadIdentity();
  }
Esempio n. 3
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;
  }
  public static Texture getTextureFromJar(String path) {
    boolean wasSandboxed = SpoutClient.isSandboxed();
    SpoutClient.disableSandbox();
    try {
      if (textures.containsKey(path)) {
        return textures.get(path);
      }

      Texture texture = null;
      // Check inside jar
      try {
        InputStream stream = Minecraft.class.getResourceAsStream(path);
        texture = TextureLoader.getTexture("PNG", stream, true, GL11.GL_NEAREST);
        stream.close();
      } catch (Exception e) {
      }
      // Check MCP/Eclipse Path
      if (texture == null) {
        texture =
            getTextureFromPath(
                FileUtil.getSpoutcraftDirectory().getAbsolutePath() + "/../.." + path);
      }

      if (texture != null) {
        textures.put(path, texture);
      }

      return texture;
    } finally {
      SpoutClient.enableSandbox(wasSandboxed);
    }
  }
  public static Texture getTextureFromPath(String path) {
    boolean wasSandboxed = SpoutClient.isSandboxed();
    SpoutClient.disableSandbox();
    try {
      if (textures.containsKey(path)) {
        return textures.get(path);
      }
      Texture texture = null;
      try {
        FileInputStream stream = new FileInputStream(path);
        if (stream.available() > 0) {
          texture = TextureLoader.getTexture("PNG", stream, true, GL11.GL_NEAREST);
        }
        stream.close();
      } catch (IOException e) {
      }

      if (texture != null) {
        textures.put(path, texture);
      }
      return texture;
    } finally {
      SpoutClient.enableSandbox(wasSandboxed);
    }
  }
 public LoadTexture(String path, String filetype) {
   try {
     // Load texture atlas image
     textureAtlas = TextureLoader.getTexture(filetype, ResourceLoader.getResourceAsStream(path));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 7
0
 private Texture loadTexture(String key) {
   try {
     return TextureLoader.getTexture("JPG", new FileInputStream(new File(key)));
   } catch (Exception e) {
     System.out.println(e);
   }
   return null;
 }
Esempio n. 8
0
  public TextureTest() {
    try {
      FileInputStream s = new FileInputStream("textures/texture1.png");
      t = TextureLoader.getTexture("PNG", s);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 9
0
 public Texture getTexture() {
   Texture tex = null;
   InputStream in = ResourceLoader.getResourceAsStream("res/tiles/Door16.png");
   try {
     tex = TextureLoader.getTexture("PNG", in);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return tex;
 }
Esempio n. 10
0
 @Override
 public void loadTextures() {
   try {
     texture =
         TextureLoader.getTexture(
             "png", ResourceLoader.getResourceAsStream("graphics/objects/thing2.png"));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 11
0
 public Block(BlockType type, float x, float y) {
   this.type = type;
   this.x = x;
   this.y = y;
   try {
     this.texture = TextureLoader.getTexture("PNG", new FileInputStream(new File(type.location)));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 12
0
  public static Texture loadTexture(String name) {
    try {
      return TextureLoader.getTexture(
          "png", new FileInputStream(new File("content/images/" + name + ".png")));
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
Esempio n. 13
0
  // ***************************************************************************
  // init
  // ***************************************************************************
  private void init() {
    // load textures here and other things

    try {
      // load texture from PNG file
      texture =
          TextureLoader.getTexture(
              "JPG",
              // ResourceLoader.getResourceAsStream("/Users/robert/Desktop/IMG_0994.PNG"));
              ResourceLoader.getResourceAsStream("/Users/robert/Desktop/edkxryo.jpg"));

      System.out.println("Texture loaded:    " + texture);
      System.out.println(">> Image width:    " + texture.getImageWidth());
      System.out.println(">> Image height:   " + texture.getImageHeight());
      System.out.println(">> Texture width:  " + texture.getTextureWidth());
      System.out.println(">> Texture height: " + texture.getTextureHeight());
      System.out.println(">> Texture ID:     " + texture.getTextureID());

      // AL

      // you can play oggs by loading the complete thing into
      // a sound
      // oggEffect = AudioLoader.getAudio("OGG",
      // ResourceLoader.getResourceAsStream("testdata/restart.ogg"));

      // or setting up a stream to read from. Note that the argument becomes
      // a URL here so it can be reopened when the stream is complete. Probably
      // should have reset the stream by thats not how the original stuff worked
      // oggStream = AudioLoader.getStreamingAudio("OGG",
      // ResourceLoader.getResource("testdata/bongos.ogg"));

      // can load mods (XM, MOD) using ibxm which is then played through OpenAL. MODs
      // are always streamed based on the way IBXM works
      // modStream = AudioLoader.getStreamingAudio("MOD",
      // ResourceLoader.getResource("testdata/SMB-X.XM"));

      // playing as music uses that reserved source to play the sound. The first
      // two arguments are pitch and gain, the boolean is whether to loop the content
      // modStream.playAsMusic(1.0f, 1.0f, true);

      // you can play aifs by loading the complete thing into
      // a sound
      // aifEffect = AudioLoader.getAudio("AIF",
      // ResourceLoader.getResourceAsStream("testdata/burp.aif"));

      // you can play wavs by loading the complete thing into
      // a sound
      // wavEffect = AudioLoader.getAudio("WAV",
      // ResourceLoader.getResourceAsStream("testdata/cbrown01.wav"));

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 14
0
 public static Texture LoadTexture(String type, String path) {
   try {
     return TextureLoader.getTexture(type, new FileInputStream(new File(path)));
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace(); // To change body of catch statement use File | Settings | File
     // Templates.
   }
   return null;
 }
Esempio n. 15
0
  public static Texture getTextureFromJar(String path) {
    if (textures.containsKey(path)) {
      return textures.get(path);
    }

    Texture texture = null;
    // Check inside jar
    try {
      InputStream stream = Minecraft.class.getResourceAsStream(path);
      texture =
          TextureLoader.getTexture(
              path.toLowerCase().endsWith(".png") ? "PNG" : "JPG", stream, true, GL11.GL_NEAREST);
      stream.close();
    } catch (Exception e) {
    }
    // Check MCP/Eclipse Path
    if (texture == null) {
      String pathToJar;
      File jar =
          new File(
              CustomTextureManager.class
                  .getProtectionDomain()
                  .getCodeSource()
                  .getLocation()
                  .getFile());
      try {
        pathToJar = jar.getCanonicalPath();
      } catch (IOException e1) {
        pathToJar = jar.getAbsolutePath();
      }
      try {
        pathToJar = URLDecoder.decode(pathToJar, "UTF-8");
      } catch (java.io.UnsupportedEncodingException ignore) {
      }

      File relative = new File(pathToJar + "/../../src/main/resources" + path.substring(4));

      try {
        pathToJar = relative.getCanonicalPath();
      } catch (IOException e) {
        pathToJar = relative.getAbsolutePath();
      }

      texture = getTextureFromPath(pathToJar);
    }

    if (texture != null) {
      textures.put(path, texture);
    }

    return texture;
  }
Esempio n. 16
0
  public static void initEffects() throws IOException {
    pokeball =
        TextureLoader.getTexture("PNG", Main.class.getResourceAsStream("/resources/ball.png"));

    // Need to wrap with BufferedInputStream
    // See: https://stackoverflow.com/questions/5529754/java-io-ioexception-mark-reset-not-supported
    leftReturn =
        AudioLoader.getAudio(
            "WAV", new BufferedInputStream(Main.class.getResourceAsStream("/resources/left.wav")));
    rightReturn =
        AudioLoader.getAudio(
            "WAV", new BufferedInputStream(Main.class.getResourceAsStream("/resources/right.wav")));
  }
Esempio n. 17
0
 public GuiButton(float x, float y, float sx, float sy, String tex) {
   PosX = x;
   PosY = y;
   SizeX = sx;
   SizeY = sy;
   try {
     TextureId =
         (TextureLoader.getTexture(
                 "", ResourceLoader.getResourceAsStream(System.getProperty("user.dir") + tex)))
             .getTextureID();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 18
0
 public int loadWaterMapTexture(String fileName) {
   Texture texture = null;
   try {
     texture =
         TextureLoader.getTexture(
             "PNG", this.getClass().getResourceAsStream("/WaterMaps/" + fileName + ".png"));
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   int textureID = texture.getTextureID();
   textures.add(textureID);
   return textureID;
 }
Esempio n. 19
0
  public ExitButton(double x, double y, double width, double height) {
    super(x, y, width, height);

    try {
      exitButtonTex =
          TextureLoader.getTexture("PNG", new FileInputStream(new File("res/startButton.png")));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      Display.destroy();
      System.exit(1);
    } catch (IOException e) {
      e.printStackTrace();
      Display.destroy();
      System.exit(1);
    }
  }
Esempio n. 20
0
 // setTextures
 public void setTexture(String texture) {
   try {
     Texture =
         TextureLoader.getTexture(
             "PNG",
             new FileInputStream(
                 new File(
                     AbsoluteFilePath
                         + File.separator
                         + "res"
                         + File.separator
                         + texture
                         + ".png")));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 21
0
 public int loadTexture(String fileName) {
   Texture texture = null;
   try {
     texture = TextureLoader.getTexture("PNG", new FileInputStream("res/" + fileName + ".png"));
     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, -0.4f);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   int textureID = texture.getTextureID();
   textures.add(textureID);
   return textureID;
 }
Esempio n. 22
0
  private void loadFont(boolean numericOnly, String fontFolder) {
    if (numericOnly) {
      String[] tmp = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
      names = tmp;
    } else {

    }
    font = new Texture[names.length];
    for (int i = 0; i < names.length; i++) {
      try {
        font[i] =
            TextureLoader.getTexture(
                "PNG", ResourceLoader.getResourceAsStream(fontFolder + "/" + names[i] + ".png"));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 23
0
  public static Texture getTextureFromPath(String path) {
    if (textures.containsKey(path)) {
      return textures.get(path);
    }
    Texture texture = null;
    try {
      FileInputStream stream = new FileInputStream(path);
      if (stream.available() > 0) {
        texture =
            TextureLoader.getTexture(
                path.toLowerCase().endsWith(".png") ? "PNG" : "JPG", stream, true, GL11.GL_NEAREST);
      }
      stream.close();
    } catch (IOException e) {
    }

    if (texture != null) {
      textures.put(path, texture);
    }
    return texture;
  }