Rendering issues when not using APDE (PShape)

When using PShapes in Processing, I ran in the following issue:


PShape cubeShape;
PShape secondaryShape;
PImage cubeImage;
PImage blank;
float rotationX;
float rotationY;
float sX, sY;
int childs;
PFont questionFont, optionFont;

void setup(){
  frameRate(60);
  orientation(PORTRAIT);
  fullScreen(P3D);
  shapeMode(CORNER);
  textAlign(CORNER);
  smooth(5);
  cubeShape = loadShape("Abc.obj");
  cubeShape.setFill(color(255));
  cubeShape.setTint(color(255));
  secondaryShape = loadShape("Abc.obj");
  secondaryShape.setFill(color(255));
  secondaryShape.setTint(color(255,255,255));
  cubeImage = loadImage("cubesite_front.PNG");
  childs = cubeShape.getChildCount();
  questionFont = createFont("cube.ttf",7); 
  optionFont = createFont("cube.ttf", 85);
  textureWrap(REPEAT);
  textureMode(IMAGE);
  secondaryShape.setTexture(loadImage("cubesite_any.png"));
  rotationX = 0.0f;
  rotationY = 0.0f;
  editSite(cubeImage, "Test", "Left", "Top", "Right", "Bottom");
  cubeImage = getMirror(cubeImage);
}

void draw(){
  cubeShape.setTexture(cubeImage);
  Runtime runtime = Runtime.getRuntime();
  float usedRam = 1.0f - (float) runtime.freeMemory() / (float) runtime.totalMemory();
  int usedRamPercent = (int) (usedRam*100.0f);
  background(255);
  lights();
  textSize(width/20);
  fill(0,125,255);
  text("Rotation X: " + String.valueOf(degrees(rotationX)).split("\\.")[0]+"°\n"+"Rotation Y: " + String.valueOf(degrees(rotationY)).split("\\.")[0]+"°",width/20,height/20);
  String rightBar = "Touch X: " + String.valueOf(sX) + "\nTouch Y: " + String.valueOf(sY) 
  + "\n\nRAM: " + usedRamPercent + "%"
  + "\nFPS: " + String.valueOf(frameRate).split("\\.")[0];
  text(rightBar,width-width/20-textWidth(rightBar),height/20); 
  textSize(width/20);
  fill(125,25,0);
  text("",width/2,height/7);
  if (rotationX>=TWO_PI||rotationX<=-TWO_PI) rotationX=0;
  if (rotationY>=TWO_PI||rotationY<=-TWO_PI) rotationY=0;
  for (int i = 0; i <childs; i++){
    PShape currentChild = cubeShape.getChild(i); 
    PShape secondaryChild = secondaryShape.getChild(i);
    boolean front = true;
    for (int j = 0; j < currentChild.getVertexCount(); j++){
      PVector currentVector = currentChild.getVertex(j);
      front = !(currentVector.z<0.95);
    }
    pushMatrix();
    translate(width/2,height/2,height/6);
    scale(height/7);
    rotateX(rotationX);
    rotateY(rotationY);
    shape(front ? currentChild : secondaryChild);
    popMatrix();
  }
}
 

PImage getMirror(PImage img) {
  PGraphics pg = createGraphics(img.width, img.height, JAVA2D);
  pg.beginDraw();
  pg.smooth(4);
  pg.scale(-1, 1);
  pg.image(img, -img.width, 0);
  pg.endDraw();
  return pg.get();
}

private void editSite(PImage background, String center, String left, String top, String right, String bottom){ 
  PGraphics siteGraphics = createGraphics(background.width,background.height); 
  imageMode(CORNER); 
  siteGraphics.beginDraw(); 
  siteGraphics.image(background,0,0); 
  siteGraphics.textSize(width/10); 
  fittedText(siteGraphics,center,questionFont,siteGraphics.width/2,siteGraphics.height/2,siteGraphics.width-siteGraphics.width/6,siteGraphics.height-siteGraphics.height/6); 
  siteGraphics.pushMatrix(); 
  siteGraphics.translate(0,0);
  siteGraphics.rotate(-HALF_PI); 
  siteGraphics.textAlign(CENTER, CENTER); 
  siteGraphics.textFont(optionFont); 
  siteGraphics.text(left,-siteGraphics.height/2,siteGraphics.width/6/2); 
  siteGraphics.rotate(PI); 
  siteGraphics.text(right,siteGraphics.height/2,-siteGraphics.width+siteGraphics.width/6/2); 
  siteGraphics.rotate(-HALF_PI); 
  siteGraphics.text(top,siteGraphics.width/2,siteGraphics.height/6/2); 
  siteGraphics.text(bottom,siteGraphics.width/2,siteGraphics.height-siteGraphics.height/6/2); siteGraphics.popMatrix(); 
  siteGraphics.endDraw(); 
  cubeImage = siteGraphics.get(); 
}


private final char NEWLINE = '\n'; private final String SPACE_SEPARATOR = " "; private final String SPLIT_REGEXP= "\\s+"; String breakLines(String input, int maxLineLength) { String[] tokens = input.split(SPLIT_REGEXP); StringBuilder output = new StringBuilder(input.length()); int lineLen = 0; for (int i = 0; i < tokens.length; i++) { String word = tokens[i]; if (lineLen + (SPACE_SEPARATOR + word).length() > maxLineLength) { if (i > 0) output.append(NEWLINE); lineLen = 0; } if (i < tokens.length - 1 && (lineLen + (word + SPACE_SEPARATOR).length() + tokens[i + 1].length() <=maxLineLength)) word += SPACE_SEPARATOR; output.append(word); lineLen += word.length(); } return output.toString();}
void fittedText(PGraphics graphics,String text, PFont font, float posX, float posY, float fitX, float fitY){ 
  text = breakLines(text, 15); 
  graphics.textFont(font); 
  graphics.textAlign(CENTER,CENTER); 
  graphics.textSize(min(font.getSize()*fitX/textWidth(text), fitY)); 
  graphics.textLeading(graphics.textSize*1.1); 
  graphics.text(text, posX, posY);
}


void mousePressed(){
  sX = mouseX;
  sY = mouseY;
}
void mouseDragged(){
  rotationX += (mouseY-sY)*(HALF_PI/(width));
  sY = mouseY;
  rotationY += (mouseX-sX)*(HALF_PI/(width));
  sX = mouseX;
}

The above demo code functions perfectly when run via APDE, but the texture is just one solid ugly color when build/run from a windows machine via PDE or Android Studio:

Does anyone know why this is happening and how I can fix it?

If needed I will upload the model as well if it is relevant!

Could you zip all and place a shared link on Gdrive or alike?

Here you go!

Fonts?..

Excuse me, but could you clarify? Are the fonts the problem causing this? If you are asking for the font file, it is included in the rar file.

Sorry. I tested it on APDE and forgot that you need to use “app mode” when importing a file.
I’ve tried for one hour to make my PC recognize my phone without success.
USB debugging on, right phone driver installed, ADB reset, but nothing.
And I’v got the emulator never to work. So I can’t help you to test the code.
On APDE the code runs fine. The only thing I would add is a boolean to only draw when dragging, (to save battery.)

Thank you for the advice. This is only a demo, but I think this implementation would be great in the real code too. Anyways the real problem still remains :frowning:. This is the only thread I found, where the OP has the same problem.

You could try to solve it by taking away piece of code bit by bit, until finding the culprit.
APDE uses a previous Processing Android mode (Version 4.0) You could install it on the PC to test it. Why do you need to run it on PC?

@Mesalcode === i have tested your code with android MM and P5 desktop osX 10.12: i get exactly what you want without any error (except for smooth which has to be called before beginShape)…Same thing with AS. I guess that your problem is with the cube.ttf font that i have installed in my font library. At this moment i got an alert: duplicate font with another name (i dont know what it was). Changing your font to Arial Black.ttf, the result is the same: good. Though Frame rate is slow (5FPS at max) and the other faces are not textured.

Could you send me the edited code that ran fine for you? When I try to rename the font file, it doesn’t change anything for me.

@Mesalcode === it is useless; i have used exactly your code, just changing smooth and createFont() and putting ArialBlack.ttf font in the data folder .

I did that and it still doesn’t work for me on Windows. You meantioned some sort of font library, which are you using?

@Mesalcode === as i run osX the font library is inside the general library as a subfolder: i dont know for windows.
PS: i have tested with nougat and Huawei phone: everything works fine (your Touch is not dip, and it returns weird values, like 1000) but that is not the main problem.

@akenaton For me even this minimal code doesn’t display the texture correctly.

PShape cubeShape;
PImage cubeImage;

void setup(){
  orientation(PORTRAIT);
  fullScreen(P3D);
  shapeMode(CORNER);
  textureWrap(REPEAT);
  textureMode(IMAGE);
  cubeShape = loadShape("Abc.obj");
  cubeShape.setFill(color(255));
  cubeShape.setTint(color(255));
  cubeImage = loadImage("cubesite_front.PNG");
  cubeShape.setTexture(cubeImage);
  
}

void draw(){
  background(255);
  lights();
  translate(width/2,height/2,height/6);
  scale(height/7);
  shape(cubeShape);
}

Does this work on your machine?

@Mesalcode === tested; it works: i can see the same thing than on you image, without text.

Thats so odd… The same code just produces this one-colored cube for me.

What Processing version are you using?

@Mesalcode === i dont know exactly but quite the last one

Just to confirm, you really used Android Mode and launched the above code on your phone without an issue? I tried this on Windows and Pop!_OS and it just never works.

@Mesalcode === i do confirm; tested with nexus7 MM && huawei 9.