目前我正在使用简单的游戏应用程序,使用 GL_TRIANGLE_STRIP 绘制一个球图像(从左到右移动)并使用 GL_LINES 在 Touch 开始代理中画一条线,当我触摸屏幕应用程序将退出,就像程序收到信号 exc_bad_access 一样,我花了14 小时,但我无法解决此问题,请帮助我。
提前致谢
我试过源代码:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
Test =YES;
[self.effect prepareToDraw];
const GLfloat line[] =
{
0, 2,
0,-3,
};
GLuint bufferObjectNameArray;
glGenBuffers(1, &bufferObjectNameArray);
glBindBuffer(GL_ARRAY_BUFFER, bufferObjectNameArray);
glBufferData(
GL_ARRAY_BUFFER, // the target buffer
sizeof(line), // the number of bytes to put into the buffer
line, // a pointer to the data being copied
GL_STATIC_DRAW); // the usage pattern of the data
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(
GLKVertexAttribPosition, // the currently bound buffer holds the data
2, // number of coordinates per vertex
GL_FLOAT, // the data type of each component
GL_FALSE, // can the data be scaled
2*4, // how many bytes per vertex (2 floats per vertex)
NULL); // offset to the first coordinate, in this case 0
glDrawArrays(GL_Lines,0,3);
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
NSLog(@"Children count:%d",[self.children count]); // Store ball image in NSMutable array
for (SGGSprite * sprite in self.children)
{
self.effect.texture2d0.name = self.textureInfo.name;
self.effect.texture2d0.enabled = YES;
GLKMatrix4 modelMatrix = GLKMatrix4Identity;
modelMatrix = GLKMatrix4Translate(modelMatrix, -self.position.x, -self.position.y, 0);
modelMatrix = GLKMatrix4Translate(modelMatrix, self.contentSize.width, self.contentSize.height+140, 0);
return modelMatrix;
[self.effect prepareToDraw];
long offset = (long)&_quad;
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
NSLog(@"TexturedVertex:%ld",offset);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, geometryVertex)));
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, textureVertex)));
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // When i tab the screen, the app will quit in this line like thread 1 :program received signal exc_bad_access.
}
}