www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: jaychang0917 on March 22, 2017, 06:21:22 pm

Title: The object's width & height will be stretch based on aspect ratio of SurfaceView
Post by: jaychang0917 on March 22, 2017, 06:21:22 pm
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);
Title: Re: The object's width & height will be stretch based on aspect ratio of SurfaceView
Post by: EgonOlsen on March 23, 2017, 08:39:13 am
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.
Title: Re: The object's width & height will be stretch based on aspect ratio of SurfaceView
Post by: jaychang0917 on March 23, 2017, 10:20:23 am
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?

(http://i.imgur.com/wsj1FSV.png)
Title: Re: The object's width & height will be stretch based on aspect ratio of SurfaceView
Post by: EgonOlsen on March 23, 2017, 12:32:40 pm
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...
Title: Re: The object's width & height will be stretch based on aspect ratio of SurfaceView
Post by: jaychang0917 on March 24, 2017, 03:16:47 am
Yes, i figured out the problem, it is due to incorrect GL viewport. Thanks your suggestion.