iOS 模拟器显示闪烁的线条

iOS simulator shows flickering lines

在我的应用程序中,我画了一系列点(星星),然后画了一系列线(星座图),但是这些线在模拟器上闪烁,当我 运行 我的应用程序在我的 iPhone 根本没有行。有什么想法吗?

(我在 GLKViewController 下的 GLKView 中 运行ning OpenGL 2.0 ES。)

编辑:这是绘图代码,我在其中为星星使用自定义着色器,但我并不真正需要它为线条。不确定如何 return 默认着色器。 (我试过 glUseProgram(0); 它应该可以工作,但没有任何区别。)

- (void)drawRect:(CGRect)rect {
    // Drawing code
    //    NSLog(@"GBStarField drawRect invoked!");

    /*********************************/
    // Draw all stars
    /*********************************/

    // Clear the framebuffer
    glClearColor(0.0, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    // Calculate OpenGL to GLKit View coordinate transformation

    // Calculate perspective transformation
    float aspect = fabsf(self.bounds.size.width / self.bounds.size.height);
    GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(90.0f), aspect, 0.0f, 10.0f);

    self.effect.transform.projectionMatrix = projectionMatrix;

    // Calculate translation transformation
#ifdef USE_RA_DEC
    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 0.0f);
#else
    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -2.0f);
#endif

    // Calculate rotation transformation
    // remember the right hand rule for rotation vector
    modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(rotation/10), 0, 1, 0);
    //modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(-90), 0, 0, 1); // polaris
    //modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(180-279.2346), 0, 1, 0); // vega
    //modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(-38.783692), 0, 0, 1); // vega
    //modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(180-78.63447), 0, 1, 0); // rigel
    //modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, GLKMathDegreesToRadians(8.20164), 0, 0, 1); // rigel

    self.effect.transform.modelviewMatrix = modelViewMatrix;

    [self.effect prepareToDraw];

    // Get uniform locations (must be after linking)
    GLint u_projectionMatrixLocation;
    u_projectionMatrixLocation = glGetUniformLocation(programBrightStar, (const GLchar*) "u_projectionMatrix");
    GLint u_modelViewMatrixLocation;
    u_modelViewMatrixLocation = glGetUniformLocation(programBrightStar, (const GLchar*) "u_modelViewMatrix");

    // Get attribute locations (must be after linking)
    GLint a_positionLocation;
    a_positionLocation =  glGetAttribLocation(programBrightStar, (const GLchar*) "a_position");
    GLint a_colorLocation;
    a_colorLocation =  glGetAttribLocation(programBrightStar, (const GLchar*) "a_color");
    GLint a_pointsizeLocation;
    a_pointsizeLocation =  glGetAttribLocation(programBrightStar, (const GLchar*) "a_pointsize");

    // Working with the star buffers
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &vertexBufferSize);
    //NSLog(@"vertexBufferSize/sizeof(Vertex) = %lu", vertexBufferSize/sizeof(Vertex));

    // Use custom vertex/fragment shader (must be after binging the buffers
    glUseProgram(programBrightStar);

    // Set uniforms for shader (must be after "glUseProgram")
    glUniformMatrix4fv(u_projectionMatrixLocation, 1, GL_FALSE, projectionMatrix.m);
    glUniformMatrix4fv(u_modelViewMatrixLocation, 1, GL_FALSE, modelViewMatrix.m);

    // Set attributes for shader (must be after "glUseProgram")
    glEnableVertexAttribArray(a_positionLocation);
    glVertexAttribPointer(a_positionLocation, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));
    glEnableVertexAttribArray(a_colorLocation);
    glVertexAttribPointer(a_colorLocation, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color));
    glEnableVertexAttribArray(a_pointsizeLocation);
    glVertexAttribPointer(a_pointsizeLocation, 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Pointsize));

    // Draw it as points defined by the vertex and index buffer data
    glDrawArrays(GL_POINTS, 0, vertexBufferSize/sizeof(Vertex));

    /*********************************/
    // Draw all constellations
    /*********************************/

    // Working with the constellation buffers
    glBindBuffer(GL_ARRAY_BUFFER, constellationVertexBuffer[0]);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, constellationIndexBuffer[0]);
    glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &indexBufferSize);
    //NSLog(@"indexBufferSize/sizeof(GLuint) = %lu", indexBufferSize/sizeof(GLuint));

    // Use custom vertex/fragment shader (must be after binging the buffers
    glUseProgram(programBrightStar);

    // Set uniforms for shader (must be after "glUseProgram")
    glUniformMatrix4fv(u_projectionMatrixLocation, 1, GL_FALSE, projectionMatrix.m);
    glUniformMatrix4fv(u_modelViewMatrixLocation, 1, GL_FALSE, modelViewMatrix.m);

    // Set attributes for shader (must be after "glUseProgram")
    glEnableVertexAttribArray(a_positionLocation);
    glVertexAttribPointer(a_positionLocation, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));
    glEnableVertexAttribArray(a_colorLocation);
    glVertexAttribPointer(a_colorLocation, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color));
    glEnableVertexAttribArray(a_pointsizeLocation);
    glVertexAttribPointer(a_pointsizeLocation, 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Pointsize));

    // Draw it as lines defined by the vertex and index buffer data
    glDrawElements(GL_LINES, indexBufferSize/sizeof(GLuint), GL_UNSIGNED_INT, 0);
}

我发现了问题。这是我的着色器。我有一个星星着色器,它从大的正方形点制作圆圈。当图像旋转时,这会拒绝线条。我通过添加第二个着色器来绘制线条解决了这个问题。