Package org.mt4j.util.opengl

Examples of org.mt4j.util.opengl.GLTexture


                    }
                   
                    if (MT4jSettings.getInstance().isOpenGlMode()){
                      PImage img = pa.loadImage(basePath + tFile);
                    if (Tools3D.isPowerOfTwoDimension(img)){
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                    }else{
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
//                      ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
                    }
                    }else{
                      texture = pa.loadImage(basePath + tFile);
                    }
                    textureCache.put(tFile, texture);
                }else{
                  System.out.println("Trying to load obj texture from: " + basePath + tFile);
                    if (MT4jSettings.getInstance().isOpenGlMode()){
                      PImage img = pa.loadImage(basePath + tFile);
                    if (Tools3D.isPowerOfTwoDimension(img)){
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                    }else{
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
//                      ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
                    }
                    }else{
                      texture = pa.loadImage(basePath + tFile);
                    }
                    textureCache.put(tFile, texture);
                }
              }
             
//              RgbFile f;
//              if (fromUrl) {
//                f = new RgbFile(new URL(basePath + tFile).openStream());
//              } else {
//                f = new RgbFile(new FileInputStream(basePath + tFile));
//              }
//              BufferedImage bi = f.getImage();

              boolean luminance = suffix.equals("int") || suffix.equals("inta");
              boolean alpha = suffix.equals("inta") || suffix.equals("rgba");
              cur.transparent = alpha;

              String s = null;
              if (luminance && alpha) s = "LUM8_ALPHA8";
              else if (luminance) s = "LUMINANCE";
              else if (alpha) s = "RGBA";
              else s = "RGB";

//              t = new TextureLoader(bi, s, TextureLoader.GENERATE_MIPMAP);
            } else {
//              tFile.toLowerCase();
//              tFile.toLowerCase(Locale.ENGLISH);
//              basePath.toLowerCase();
             
              PImage cachedImage = textureCache.get(tFile);
              if (cachedImage != null){
                texture = cachedImage;
                //System.out.println("->Loaded texture from CACHE : \"" + tFile + "\"");
              }else{
                File textureFile = new File(basePath + tFile);
                if (textureFile.exists()){
                  boolean success = textureFile.renameTo(new File(basePath + tFile));
                    if (!success) {
                        // File was not successfully renamed
                      System.out.println("failed to RENAME file: " + textureFile.getAbsolutePath());
                    }
                   
                    if (MT4jSettings.getInstance().isOpenGlMode()){
                      PImage img = pa.loadImage(basePath + tFile);
                    if (Tools3D.isPowerOfTwoDimension(img)){
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                    }else{
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
//                      ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
                    }
                    }else{
                      texture = pa.loadImage(basePath + tFile);
                    }
                    textureCache.put(tFile, texture);
                }else{
                  System.out.println("Trying to load obj texture from: " + basePath + tFile);
                    if (MT4jSettings.getInstance().isOpenGlMode()){
                      PImage img = pa.loadImage(basePath + tFile);
                    if (Tools3D.isPowerOfTwoDimension(img)){
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                    }else{
                      texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
//                      ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
                    }
                    }else{
                      texture = pa.loadImage(basePath + tFile);
                    }
View Full Code Here


                }
                PImage texture = null;
                if (MT4jSettings.getInstance().isOpenGlMode()){ //TODO check if render thread
                  PImage img = pa.loadImage(texturePath);
                  if (Tools3D.isPowerOfTwoDimension(img)){
                    texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                  }else{
                    texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                    // ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
                  }
                }else{
                  texture     = pa.loadImage(texturePath);
                }
                mesh.setTexture(texture);
                mesh.setTextureEnabled(true);

                textureCache.put(materialName, texture);
                if (debug)
                  logger.debug("->Loaded material texture: \"" + materialName + "\"");
                break;
              }
              if (j+1==suffix.length){
                logger.error("Couldnt load material texture: \"" + materialName + "\"");
              }
            }
          }else{//Probably loading from jar file
            PImage texture = null;
            String[] suffix = new String[]{"jpg", "JPG", "tga" , "TGA", "bmp", "BMP", "png", "PNG", "tiff", "TIFF"};
            for (String suffixString : suffix) {
              String modelFolder  = pathToModel.substring(0, pathToModel.lastIndexOf(MTApplication.separator));
              String texturePath   = modelFolder + MTApplication.separator + materialName + "." +  suffixString;
              if (MT4jSettings.getInstance().isOpenGlMode()){
                PImage img = pa.loadImage(texturePath);
                if (Tools3D.isPowerOfTwoDimension(img)){
                  texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.TEXTURE_2D, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                }else{
                  texture = new GLTexture(pa, img, new GLTextureSettings(TEXTURE_TARGET.RECTANGULAR, SHRINKAGE_FILTER.Trilinear, EXPANSION_FILTER.Bilinear, WRAP_MODE.REPEAT, WRAP_MODE.REPEAT));
                  // ((GLTexture)texture).setFilter(SHRINKAGE_FILTER.BilinearNoMipMaps, EXPANSION_FILTER.Bilinear);
                }
              }else{
                texture = pa.loadImage(texturePath);
              }
View Full Code Here

    //Create FBO
//    this.fbo = new GLFBO(pa, pa.width, pa.height);
    this.fbo = new GLFBO(pa, fboWidth, fboHeight);
   
    //Attach texture to FBO to draw into
    GLTexture tex = fbo.addNewTexture();
   
    //Invert y texture coord (FBO texture is flipped)
    Vertex[] v = this.getVerticesLocal();
    for (int i = 0; i < v.length; i++) {
      Vertex vertex = v[i];
View Full Code Here

      boolean textureDrawn = false;
      if (this.isTextureEnabled()
        && this.getTexture() != null
        && this.getTexture() instanceof GLTexture) //Bad for performance?
      {
        GLTexture tex = (GLTexture)this.getTexture();
        textureTarget = tex.getTextureTarget();
       
        //tells opengl which texture to reference in following calls from now on!
        //the first parameter is eigher GL.GL_TEXTURE_2D or ..1D
        gl.glEnable(textureTarget);
        gl.glBindTexture(textureTarget, tex.getTextureID());
        gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
       
        if (this.isUseVBOs()){//Texture
          gl.glBindBuffer(GL.GL_ARRAY_BUFFER, this.getGeometryInfo().getVBOTextureName());
          gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
View Full Code Here

//      this.setTexture(glTex);
     
      GLTextureSettings ts = new GLTextureSettings();
      ts.wrappingHorizontal = WRAP_MODE.CLAMP;
      ts.wrappingVertical = WRAP_MODE.CLAMP;
      GLTexture glTex = new GLTexture(app, menuImage.width, menuImage.height, ts);
      glTex.loadGLTexture(menuImage);
      this.setTexture(glTex);
    }else{
      this.setTexture(menuImage);
    }
   
View Full Code Here

    }
   
//    if (MT4jSettings.getInstance().isOpenGlMode()){ //FIXME USE WHICH ONE?
    if (this.isUseDirectGL()){
      if (newTexImage instanceof GLTexture) {
        GLTexture glTex = (GLTexture) newTexImage;
       
        if (glTex.getTextureTargetEnum() == TEXTURE_TARGET.RECTANGULAR){
          this.setTextureMode(PConstants.IMAGE);
         
          if (this.getGeometryInfo().isTextureCoordsNormalized()){
            //0..1 -> 0..width
            this.unNormalizeFromPOTtoRectMode(newTexImage, this.getVerticesLocal());
            this.getGeometryInfo().setTextureCoordsNormalized(false);
          }else{
            //0..oldWidth -> 0..newWidth  GLTexture is NPOT but this component's texture coords have seemingly already been un-normalized
            //FIXME dont do it if it has the same dimensions!
            this.fromRectModeToRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
          }
        }else{
          //GLTexture is POT -> normalize tex coords if neccessary
          this.setTextureMode(PConstants.NORMALIZED);
         
          if (this.getGeometryInfo().isTextureCoordsNormalized()){
            //0..1 -> 0..1
          }else{
            //0..width -> 0..1
            this.normalizeFromRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
            this.getGeometryInfo().setTextureCoordsNormalized(true);
          }
        }
        this.textureImage = newTexImage;
        //FIXME always save last tex dimensions? also if POT?
        this.lastTextureDimension.setXYZ(newTexImage.width, newTexImage.height, 0);
      }else{
        //We are in OpenGL mode but the new texture is not a GLTexture -> create new GLTexture from PImage
        boolean isPOT = Tools3D.isPowerOfTwoDimension(newTexImage);
        GLTextureSettings ts = new GLTextureSettings();
        if (!isPOT){
          ts.target = TEXTURE_TARGET.RECTANGULAR;
          this.setTextureMode(PConstants.IMAGE);
         
          if (this.getGeometryInfo().isTextureCoordsNormalized()){
            //0..1 -> 0..newWidth
            this.unNormalizeFromPOTtoRectMode(newTexImage, this.getVerticesLocal());
            this.getGeometryInfo().setTextureCoordsNormalized(false);
          }else{
            //0..oldWidth -> 0..newWidth
            //FIXME dont do it if it has the same dimensions!
            this.fromRectModeToRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
          }
         
          this.textureImage = newTexImage;
          this.lastTextureDimension.setXYZ(newTexImage.width, newTexImage.height, 0);
        }else{
          ts.target = TEXTURE_TARGET.TEXTURE_2D;
          this.setTextureMode(PConstants.NORMALIZED);
         
          //We are in OpenGL mode, new texture is a PImage, is POT -> create POT GLTexture and un-normalize tex coords if neccessary
          if (this.getGeometryInfo().isTextureCoordsNormalized()){
            //0..1 -> 0..1
          }else{
            //normalize 0..width -> 0..1
            this.normalizeFromRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
            this.getGeometryInfo().setTextureCoordsNormalized(true);
          }
        }
       
        //Create new GLTexture from PImage
        ts.shrinkFilter     = SHRINKAGE_FILTER.BilinearNoMipMaps;
        ts.expansionFilter     = EXPANSION_FILTER.Bilinear;
        ts.wrappingHorizontal   = WRAP_MODE.CLAMP_TO_EDGE;
        ts.wrappingVertical   = WRAP_MODE.CLAMP_TO_EDGE;
        GLTexture newGLTexture = new GLTexture(this.getRenderer(), newTexImage, ts);
//        newGLTexture.format = newTexImage.format;  //FIXME REMOVE?
       
        this.textureImage = newGLTexture;
        this.lastTextureDimension.setXYZ(newTexImage.width, newTexImage.height, 0);
      }
View Full Code Here

//    this.boundingShape = null;
    this.setBounds(null);
   
    //Delete openGL texture object
    if (this.getTexture() instanceof GLTexture){
      GLTexture tex = (GLTexture) this.getTexture();
      //Delete texture
      tex.destroy();
      this.setTexture(null);
      this.setTextureEnabled(false);
    }
    super.destroy();
  }
View Full Code Here

TOP

Related Classes of org.mt4j.util.opengl.GLTexture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.