2
OpenGL ESの新機能です。テストとして私はGLKView上に単純な三角形を描画しようとしています。コンパイルエラーやランタイムエラーはなく、OpenGLエラーもありません。単に三角形を描画しないだけです。これは、描画コールバックコードGLKViewでの描画
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
const GLfloat triangleVertices[] = {
0.0, 2.0, 3.0, // Triangle top centre
-2.0, -2.0, 3.0, // bottom left
2.0, -2.0, 3.0 // bottom right
};
glViewport(0, 0, 12, 12);
[self checkError];
glMatrixMode(GL_MODELVIEW);
// Our new drawing code goes here
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self checkError];
// Red
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glVertexPointer(3, GL_FLOAT, 0, &triangleVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, 3);
[self checkError];
}
ファイル全体のコード
... OpenGLが働いているが、それだけでdoesntの三角形を描く、私が間違って何をやっていることを意味し、鮮明なカラーOKを設定し、 (-glkView:drawInRect:
中)glViewport(12,12)
へ
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController()
@property (nonatomic, retain) EAGLContext *context;
@end
@implementation ViewController
@synthesize context = _context;
@synthesize Zoom = _Zoom;
- (void)dealloc
{
[_context release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1] autorelease];
if (!_context) {
NSLog(@"Failed to create ES context");
}
_Zoom = 1;
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
[self setupGL];
[self checkError];
}
- (void)viewDidUnload
{
[super viewDidUnload];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (void)setupGL
{
[EAGLContext setCurrentContext:self.context];
CGFloat w = self.view.bounds.size.width;
CGFloat h = self.view.bounds.size.height;
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0.65f, 0.65f, 1.00f, 1.0f);
double mLat = (((double)h/2) * (_Zoom/60));
double mLon = (((double)w/2) * (_Zoom/60));
glOrthof((float)-mLon, (float)mLon, (float)-mLat, (float)mLat, -5.0f, 5.0f);
glViewport(0, 0, w, h);
}
-(void) checkError
{
GLenum error = glGetError();
if (error == GL_NO_ERROR)
return;
switch (error)
{
case GL_INVALID_ENUM:
NSLog(@"Invalid Enum");
break;
}
}
#pragma mark - GLKView and GLKViewController delegate methods
- (void)update
{
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
const GLfloat triangleVertices[] = {
0.0, 2.0, 3.0, // Triangle top centre
-2.0, -2.0, 3.0, // bottom left
2.0, -2.0, 3.0 // bottom right
};
glViewport(0, 0, 12, 12);
[self checkError];
glMatrixMode(GL_MODELVIEW);
// Our new drawing code goes here
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self checkError];
// Red
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glVertexPointer(3, GL_FLOAT, 0, &triangleVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, 3);
[self checkError];
}
@end
'setupGL'の中にもう1つあります。 iOS上に「GLU」はありませんか? –
私はそれを見ていますが、ビューが描かれるたびに 'drawInRect:'のものによってオーバーライドされます。 'drawInRect:'はかなり頻繁に呼び出されるのに対して、 '-setupGL'は一度呼び出されるか、まれにしか呼び出されませんか? – user1118321
しかし、私はこれを期待していますが、私はそれに答えるための_正規の資格はありません... –