이 메서드는 posCoords 배열의 좌표를 준비합니다. 그것은 30 %의 시간 동안 제대로 작동하고, 나머지 70 %는 처음 몇 개의 삼각형이 그리드에 엉망이됩니다. 전체 표가 GL_TRIANGLE_STRIP을 사용하여 그려집니다. 나는 무엇이 잘못 됐는지 알아 내려고 노력하면서 내 머리카락을 꺼냈다. 어떤 아이디어? 삼각형으로 GL_TRIANGLE_STRIP 및 정점 배열 오류
if(!ES2) {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
int cols = floor(SCREEN_WIDTH/blockSize);
int rows = floor(SCREEN_HEIGHT/blockSize);
int cells = cols*rows;
NSLog(@"Cells: %i", cells);
coordCount = /*Points per coordinate*/2 * /*Coordinates per cell*/ 2 * cells + /* additional coord per row */2*2*rows;
NSLog(@"Coord count: %i", coordCount);
if(texCoords) free(texCoords);
if(posCoords) free(posCoords);
if(dposCoords) free(dposCoords);
texCoords = malloc(sizeof(GLfloat)*coordCount);
posCoords = malloc(sizeof(GLfloat)*coordCount);
dposCoords = malloc(sizeof(GLfloat)*coordCount);
int index = 0;
float lowY, hiY = 0;
int x,y = 0;
BOOL drawLeftToRight = YES;
for(y=0;y<SCREEN_HEIGHT;y+=blockSize) {
lowY = y;
hiY = y + blockSize;
// Draw a single row
for(x=0;x<=SCREEN_WIDTH;x+=blockSize) {
CGFloat px,py,px2,py2 = 0;
// Top point of triangle
if(drawLeftToRight) {
px = x;
py = lowY;
// Bottom point of triangle
px2 = x;
py2 = hiY;
}
else {
px = SCREEN_WIDTH-x;
py = lowY;
// Bottom point of triangle
px2 = SCREEN_WIDTH-x;
py2 = hiY;
}
// Top point of triangle
posCoords[index] = px;
posCoords[index+1] = py;
// Bottom point of triangle
posCoords[index+2] = px2;
posCoords[index+3] = py2;
texCoords[index] = px/SCREEN_WIDTH;
texCoords[index+1] = py/SCREEN_HEIGHT;
texCoords[index+2] = px2/SCREEN_WIDTH;
texCoords[index+3] = py2/SCREEN_HEIGHT;
index+=4;
}
drawLeftToRight = !drawLeftToRight;
}