2017-10-13 3 views
0

내 앱은 OpenGL ES를 사용하여 사용자가 자신의 서명을 그려주는 화면을 렌더링합니다. 내 코드는 3 년 이상 정상적으로 작동했지만 Xcode 9로 업그레이드 한 후 시뮬레이트 및 장치에서 모두 그려지는 선에 이상한 색 변화가 발생했습니다. 선은 순수한 빨강, 녹색 또는 파랑 색을 사용했지만 이제는 회색/검정색 선이 섞여 있습니다.
OpenGL에 대해 많이 알지 못하고 샘플 코드와 튜토리얼에서 코드를 작성했습니다.opengles 드로잉 색상이 xcode로 바뀝니다. 9

이 변경의 원인은 무엇입니까?

엑스 코드 9로 업그레이드 한 후 도면이다
drawing after upgrading xcode

코드 변경 색상 :

// Change the brush color 
- (void)changeBrushColor:(NSString *) newColor 
{ 
    SEL setcolor = NSSelectorFromString(newColor); 
    UIColor *nColor = [UIColor performSelector:setcolor]; 

    CGColorRef color = nColor.CGColor; 
    const CGFloat *components = CGColorGetComponents(color); 

    brushColor[0] = (GLfloat) components[0]; 
    brushColor[1] = (GLfloat) components[1]; 
    brushColor[2] = (GLfloat) components[2]; 
    brushColor[3] = (GLfloat) components[3]; 

    if (initialized) { 
     glUseProgram(program[PROGRAM_POINT].id); 
     glUniform4fv(program[PROGRAM_POINT].uniform[UNIFORM_VERTEX_COLOR], 1, brushColor); 
    } 
} 

코드 그릴 : CGPoint newMidPoint = CGPointMake를 (X/스케일 Y/규모);

[currentStroke insertObject:[NSValue valueWithCGPoint:newMidPoint] atIndex:2]; 
    [currentStroke removeObjectAtIndex:0]; 
    [currentStroke removeObjectAtIndex:0]; 
    //NSLog(@" after draw currentstroke %@: ", currentStroke); 


    // Load data to the Vertex Buffer Object & Draw it 
    //glUseProgram(program[PROGRAM_POINT].id); 
    //glBindBuffer(GL_ARRAY_BUFFER, vboId); 
    glBufferData(GL_ARRAY_BUFFER, vertexCount*2*sizeof(GLfloat), vertexBuffer, GL_DYNAMIC_DRAW); 
    //glEnableVertexAttribArray(ATTRIB_VERTEX); 
    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, 0); 

    // Draw 
    glDrawArrays(GL_POINTS, 0, (int)vertexCount); 

    // Display the buffer 
    //glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer); 
    [context presentRenderbuffer:GL_RENDERBUFFER]; 

초기화 코드 :

 - (BOOL)initGL 
     { 
      // Generate IDs for a framebuffer object and a color renderbuffer 
      glGenFramebuffers(1, &viewFramebuffer); 
      g 

    lGenRenderbuffers(1, &viewRenderbuffer); 

      glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer); 
      glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer); 
      // This cal 

l associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer) 
     // allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view). 
     [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(id<EAGLDrawable>)self.layer]; 
     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer); 

     glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth); 
     glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight); 


     if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 
     { 
      NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); 
      return NO; 
     } 

     // Setup the view port in Pixels 
     glViewport(0, 0, backingWidth, backingHeight); 

     // Create a Vertex Buffer Object to hold our data 
     glGenBuffers(1, &vboId); 

     // Load the brush texture 
     brushTexture = [self textureFromName:@"brush"]; 

     // Load shaders 
     [self setupShaders]; 

     // Enable blending and set a blending function appropriate for premultiplied alpha pixel data 
     glEnable(GL_BLEND); 
     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 

     //moved from draw 
     glUseProgram(program[PROGRAM_POINT].id); 
     glBindBuffer(GL_ARRAY_BUFFER, vboId); 
     glEnableVertexAttribArray(ATTRIB_VERTEX); 

    // //***** for testing ****** 
    // [self sample]; 
    // //***** for testing ****** 

     return YES; 
    } 

답변

0

나는 결국 내 문제에 대한 해결책을 발견했다. 64x64 대 32x32의 브러쉬 텍스처 이미지를 사용하여 문제를 해결했습니다. 나는 이것이 왜 효과가 있었는지 확신 할 수 없으며 문제를 일으킨 원인에 대한 몇 가지 의견을 여전히 좋아할 것입니다.