1

我想在glkView:drawInRect:调用之前获取 OpenGL 窗口的大小。我决定使用glGetIntegerv(GL_VIEWPORT, &rect)(而不是self.bounds或类似)更加独立于平台,但它有GL_INVALID_ENUM错误。

这是测试代码:

#define SHOW {\
  struct { GLint x, y, w, h; } rect;\
  glGetIntegerv(GL_VIEWPORT, (GLint*)&rect);\
  printf("%s %d %d\n", __FUNCTION__, rect.w, rect.h);\
}

...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { SHOW; ... }
- (void)viewDidLoad { SHOW; ... }
- (void)viewWillAppear:(BOOL)animated { SHOW; ... }
- (void)viewDidAppear:(BOOL)animated { SHOW; ... }
- (void)viewDidLayoutSubviews { SHOW; ... }
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { SHOW; ... }

这是输出:

-[ViewController viewDidLoad] 0 0
-[ViewController viewWillAppear:] 0 0
-[ViewController application:didFinishLaunchingWithOptions:] 0 0
-[ViewController viewWillLayoutSubviews] 0 0
-[ViewController viewDidLayoutSubviews] 0 0
-[ViewController glkView:drawInRect:] 1024 768
-[ViewController viewDidAppear:] 1024 768
-[ViewController glkView:drawInRect:] 1024 768

为什么glGetIntegerv(GL_VIEWPORT, &rect)在 glkView:drawInRect: 之前不可用?应该GL_VIEWPORT以某种方式初始化?

4

0 回答 0