最后我想提请使用OpenGL ES框架线的XCode 4.2的iPhone简单的游戏app.I研究一些关于GLKView和GLKViewController绘制在iPhone上线。下面是这是我在我的项目试过我的示例代码,在iPhone中使用OpenGL ES绘制直线?
@synthesize context = _context;
@synthesize effect = _effect;
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
//[self setupGL];
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
NSLog(@"DrawInRect Method");
[EAGLContext setCurrentContext:self.context];
// This method is calling multiple times....
glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
const GLfloat line[] =
{
-0.5f, -0.5f, //point A
0.5f, -0.5f, //point B
};
glVertexPointer(2, GL_FLOAT, 0, line);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
}
当我运行该项目,只有灰色的颜色只出现在屏幕上,行不显示。此外,代表正在呼叫无限的时间。请指导我在哪里做错了。为什么行不出现或绘图?你能帮忙吗?我试了2天。提前致谢。
Mr.Chris非常感谢您的帮助很大。这个答案我等了7天。现在我在你的帮助下画一条线。我希望你的帮助在将来。再次感谢。 – Gopinath 2012-03-23 12:22:30
你好先生,我需要你的帮助。你能告诉我们如何分配点A和点B的值吗?提前致谢。 – Gopinath 2012-03-24 04:42:10
我不确定我了解你的问题。你在问如何设置A点和B点的值? – 2012-03-26 07:01:53