简体   繁体   中英

Opengl View drawing issue

For dimension consideration, I resize the opengl view to 2.0 scale than origin, like this:

NSInteger Dimension = 2;
self.glView = [[WQPaintGLView alloc] initWithFrame:CGRectMake(0, 0, width*Dimension, height*Dimension)];

CGAffineTransform tScale        = CGAffineTransformMakeScale((float)1/Dimension, (float)1/Dimension);
CGAffineTransform tTranslate    = CGAffineTransformTranslate(tScale, -width, -height);

self.glView.transform = tTranslate;

[self.canvasContainerView addSubview:self.glView];

But get a strange issue, see:

在此处输入图片说明

I can only draw stuff in the left bottom 1/4 area.

What did I wrong?

The UIView transform and openGL are not very compatible. Also the view resizing after the openGL initialization could be troublesome and in most cases a new render buffer must be created from the view.

Anyway since you scaled the view to have a larger surface you should check for following calls:

  • glViewport should define what part of the buffer you are writing at. Usually it is set like (0, 0, viewWidth, viewHeight). In your case it must include the scale as well.
  • glOrtho (or glFrustum ) define your coordinate system if used. Those should most likely be the same no matter the view scale.
  • Any other matrix usage or scissors that may be defined by the view's frame.

By all means if possible remove the transform on the view and try to find a better solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM