2015-02-19 2 views
0

В моем приложении я рисую серию точек (звезд), а затем ряд строк (фигуры созвездий), но линии мерцают на симуляторе, и когда я запускаю приложение на своем iPhone, есть нет линий вообще. Есть идеи?iOS simulator показывает мерцающие линии

(я бегу OpenGL 2.0 ES в GLKView под GLKViewController.)

Edit: Вот код рисования, где я использую пользовательский шейдер для звезд, но я на самом деле не нужно для линий. Не знаете, как вернуться к шейдеру по умолчанию. (Я пробовал 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); 
} 
+0

Опубликуйте свой код рисования линии. Похоже, вы не адаптируете размер линий для соответствия (не Retina) пикселей на экране или расстояние линии от экрана, поэтому линия слишком тонкая, чтобы подсвечивать даже отдельные пиксели. Подумайте, что происходит, когда вы рисуете линию в 3D пространстве от камеры вперед до бесконечности - в конце концов линия исчезнет, ​​потому что в какой-то момент она слишком далеко и, следовательно, слишком тонкая, чтобы быть видимой. – LearnCocos2D

+0

Спасибо, что ответили. Я добавил код. Линии мерцают, даже когда я относительно крупный план. Я также попытался использовать ширину линии 2 и 3, но они все еще мерцают. Кажется, что они все flickr в то же время, как если бы glDrawElements просто не случается иногда. – codesurfer

ответ

0

Я нашел проблему. Это был мой шейдер. У меня был шейдер для звезд, который делал круги из больших квадратных точек. Это отклоняло линии при повороте изображения. Я решил проблему, добавив второй шейдер для рисования линий.