예제 #1
0
 /**
  * Convenience method to create a texture with a given internal format.
  *
  * @param width the width of the empty texture
  * @param height the height of the empty texture
  * @param filter the filter to use
  * @param format the internal format
  * @return a generated texture
  */
 public static Texture createTexture(int width, int height, ImageData.Format format, int filter)
     throws SlickException {
   EmptyImageData data = new EmptyImageData(width, height);
   ByteBuffer dataBuffer = data.getImageBufferData();
   String ref = "pixelhandler:" + width + "x" + height + ":" + format.toString();
   try {
     return InternalTextureLoader.get()
         .createTexture(data, dataBuffer, ref, GL11.GL_TEXTURE_2D, filter, filter, false, format);
   } catch (IOException e) {
     throw new SlickException("Error generating texture", e);
   }
 }
예제 #2
0
 /**
  * Inicia el Visor OpenGL indicando la instancia de partido, las dimensiones de la pantalla
  * (sx,sy), si Se ejecuta en pantalla completa(fullscreen), e indicando la instancia del jframe
  * Principal(dejar nulo)
  *
  * @param partido
  * @param sx
  * @param sy
  * @param fullscreen
  * @param principal
  * @throws SlickException
  */
 public VisorOpenGl(Partido partido, int sx, int sy, boolean fullscreen, PrincipalFrame principal)
     throws SlickException {
   this.partido = partido;
   this.sx = sx;
   this.sy = sy;
   this.dxsaque = (sx + 300 * 2) / 75;
   sx2 = sx / 2;
   sy2 = sy / 2;
   this.principal = principal;
   AppGameContainer container = new AppGameContainer(this);
   container.setForceExit(false);
   container.setDisplayMode(sx, sy, fullscreen);
   container.start();
   SoundStore.get().clear();
   InternalTextureLoader.get().clear();
 }
예제 #3
0
 void stop() {
   SoundStore.get().clear();
   InternalTextureLoader.get().clear();
   if (partido.fueGrabado()) {
     if (JOptionPane.showConfirmDialog(
             principal, "Desea guardar el partido?", "Guardar Partido", JOptionPane.YES_NO_OPTION)
         == 0) {
       if (jfc.showSaveDialog(principal) == JFileChooser.APPROVE_OPTION) {
         try {
           partido.getPartidoGuardado().save(jfc.getSelectedFile());
           if (principal != null) {
             principal.addGuardadoLocal(new File[] {jfc.getSelectedFile()});
           }
         } catch (Exception ex) {
           logger.error("Error al guardar partido", ex);
         }
       }
     }
   }
   if (sonidos) {
     for (Sound s : ambiente) {
       s.stop();
     }
     gol.stop();
     remate[0].stop();
     remate[1].stop();
     poste[0].stop();
     poste[1].stop();
     ovacion[0].stop();
     ovacion[1].stop();
     rebote.stop();
     silbato.stop();
   }
   if (principal != null) {
     principal.setVisible(true);
     principal.requestFocus();
   } else {
     System.exit(0);
   }
 }
예제 #4
0
 /**
  * Inicia el Visor OpenGL indicando la instancia de partido guardado, las dimensiones de la
  * pantalla (sx,sy), si Se ejecuta en pantalla completa(fullscreen), e indicando la instancia del
  * jframe Principal(dejar nulo)
  */
 public VisorOpenGl(
     PartidoGuardado partido, int sx, int sy, boolean fullscreen, PrincipalFrame principal)
     throws SlickException {
   pg = (PartidoGuardado) partido;
   guardado = true;
   progreso = true;
   inicio = 0;
   fin = pg.getIterciones() - 1;
   // System.out.println("Reproduciendo partido guardado...");
   this.partido = partido;
   this.sx = sx;
   this.sy = sy;
   this.dxsaque = (sx + 300 * 2) / 75;
   sx2 = sx / 2;
   sy2 = sy / 2;
   this.principal = principal;
   AppGameContainer container = new AppGameContainer(this);
   container.setForceExit(false);
   container.setDisplayMode(sx, sy, fullscreen);
   container.start();
   SoundStore.get().clear();
   InternalTextureLoader.get().clear();
 }
예제 #5
0
 public static int toPowerOfTwo(int n) {
   return InternalTextureLoader.get2Fold(n);
 }
예제 #6
0
  /**
   * Load a texture into OpenGL from a BufferedImage
   *
   * @param resourceName The location of the resource to load
   * @param resourceimage The BufferedImage we are converting
   * @param target The GL target to load the texture against
   * @param dstPixelFormat The pixel format of the screen
   * @param minFilter The minimising filter
   * @param magFilter The magnification filter
   * @return The loaded texture
   * @throws IOException Indicates a failure to access the resource
   */
  public static Texture getTexture(
      String resourceName,
      BufferedImage resourceimage,
      int target,
      int dstPixelFormat,
      int minFilter,
      int magFilter)
      throws IOException {
    ImageIOImageData data = new ImageIOImageData();
    int srcPixelFormat = 0;

    // create the texture ID for this texture
    int textureID = InternalTextureLoader.createTextureID();
    TextureImpl texture = new TextureImpl(resourceName, target, textureID);

    // Enable texturing
    Renderer.get().glEnable(SGL.GL_TEXTURE_2D);

    // bind this texture
    Renderer.get().glBindTexture(target, textureID);

    BufferedImage bufferedImage = resourceimage;
    texture.setWidth(bufferedImage.getWidth());
    texture.setHeight(bufferedImage.getHeight());

    if (bufferedImage.getColorModel().hasAlpha()) {
      srcPixelFormat = SGL.GL_RGBA;
    } else {
      srcPixelFormat = SGL.GL_RGB;
    }

    // convert that image into a byte buffer of texture data
    ByteBuffer textureBuffer = data.imageToByteBuffer(bufferedImage, false, false, null);
    texture.setTextureHeight(data.getTexHeight());
    texture.setTextureWidth(data.getTexWidth());
    texture.setAlpha(data.getDepth() == 32);

    if (target == SGL.GL_TEXTURE_2D) {
      Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter);
      Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter);

      if (Renderer.get().canTextureMirrorClamp()) {
        Renderer.get()
            .glTexParameteri(
                SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
        Renderer.get()
            .glTexParameteri(
                SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
      } else {
        Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP);
        Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP);
      }
    }

    Renderer.get()
        .glTexImage2D(
            target,
            0,
            dstPixelFormat,
            texture.getTextureWidth(),
            texture.getTextureHeight(),
            0,
            srcPixelFormat,
            SGL.GL_UNSIGNED_BYTE,
            textureBuffer);

    return texture;
  }