glGetIntegerv(GL_VIEWPORT,& rect)在iOS上返回GL_INVALID_ENUM

时间:2012-12-24 12:52:41

标签: ios opengl-es

我希望在调用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应该以某种方式初始化吗?

0 个答案:

没有答案