Author Topic: The object's width & height will be stretch based on aspect ratio of SurfaceView  (Read 350 times)

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Hi, I try to create a square image using the following code, i found that the object will be stretch in some device (i.e. full screen SurfaceView with different aspect ratio), how to keep the model in square? Thanks!

Code: [Select]
Texture waterMarkTexture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(context.getResources().getDrawable(R.drawable.watermark)), 128, 128));
      boolean isWaterMarkTextureAdded = TextureManager.getInstance().containsTexture("watermark");
      if (!isWaterMarkTextureAdded) {
        TextureManager.getInstance().addTexture("watermark", waterMarkTexture);
      }
      Object3D waterMarkModel = Primitives.getPlane(1, 16);
      waterMarkModel.setTexture("watermark");
      waterMarkModel.setOrigin(new SimpleVector(45, 55, 0));
      waterMarkModel.rotateX((float) (Math.toRadians(19.3)));
      waterMarkModel.build();
      world.addObject(waterMarkModel);
« Last Edit: March 22, 2017, 07:03:56 pm by jaychang0917 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Do you have a screen shot? As long as the device's pixel-ratio is 1-1 (which it should be), I don't see why there should be any distortion.

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
The watermark (orange icon) is a square image, but you see that it is stretched. The device's screen resolution is 2560x1440.

Also, seems there is some jaggies at bottom right corner of watermark.

Has any idea?

« Last Edit: March 23, 2017, 10:27:22 am by jaychang0917 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
There's something fishy with the way you are doing things then. IIRC, you were mixing jPCT-AE with direct GL calls? Maybe something is wrong with that. If jPCT-AE alone gets the proper screen dimensions in the Framebuffer's constructor and nothing else happens, a square object will be rendered as a square. You can build yourself a basic test case to prove that.
No idea, what's going on here...

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Yes, i figured out the problem, it is due to incorrect GL viewport. Thanks your suggestion.