The object's width & height will be stretch based on aspect ratio of SurfaceView

Started by jaychang0917, March 22, 2017, 06:21:22 PM

Previous topic - Next topic

jaychang0917

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!


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);

EgonOlsen

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.

jaychang0917

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?


EgonOlsen

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...

jaychang0917

Yes, i figured out the problem, it is due to incorrect GL viewport. Thanks your suggestion.