2012-04-11 2 views
2

iPhone 및 iPad 용 페인팅 앱 [GLPaint 앱에서 가져온 참조]을 개발 중입니다. 브러시 효과를 연구 중입니다. 내가 브러쉬 질감에 대한 다음 코드를 사용하고 2iPhone OpenGL ES 페인트 브러시 효과

enter image description here

이미지와 유사 브러시 스트로크를 가지고

enter image description here

이미지 1에서와 같이 내 페인트 응용 프로그램에 대한 브러시 효과를 얻으려면 :

CGImageRef  brushImage; 
CGContextRef brushContext; 
GLubyte   *brushData; 
size_t   width, height; 
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     brushImage = [UIImage imageNamed:@"[email protected]"].CGImage; 
    } 
    else { 
     brushImage = [UIImage imageNamed:@"flower.png"].CGImage; 
    } 
    width = CGImageGetWidth(brushImage) ; 
    height = CGImageGetHeight(brushImage) ; 
    if(brushImage) { 

     brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte)); 
       brushContext = CGBitmapContextCreate(brushData, width, height, 8, width * 4, CGImageGetColorSpace(brushImage),kCGImageAlphaPremultipliedLast); 
     CGContextDrawImage(brushContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), brushImage); 
     CGContextRelease(brushContext); 
     glGenTextures(1, &brushTexture); 
     glBindTexture(GL_TEXTURE_2D, brushTexture); 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData); 
     free(brushData); 
    } 
     CGFloat scale; 
     scale = self.contentScaleFactor; 

    glMatrixMode(GL_PROJECTION); 
    CGRect frame = self.bounds; 
    glLoadIdentity(); 
    glOrthof(0, (frame.size.width) * scale, 0, (frame.size.height) * scale, -1, 1); 
    glViewport(0, 0, (frame.size.width) * scale, (frame.size.height) * scale); 
    glMatrixMode(GL_MODELVIEW); 
    glDisable(GL_DITHER); 
    glEnable(GL_BLEND); 
    glEnable(GL_TEXTURE_2D); 
    glEnableClientState(GL_VERTEX_ARRAY); 
    glEnable(GL_BLEND); 
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 
    glEnable(GL_POINT_SPRITE_OES); 
    glTexEnvf(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE); 
    glPointSize(width/kBrushScale); 
    // Define a starting color 
    HSL2RGB((CGFloat) 0.0/(CGFloat)kPaletteSize, kSaturation, kLuminosity, &components[0], &components[1], &components[2]); 
    glColor4f(components[0] * kBrushOpacity, components[1] * kBrushOpacity, components[2] * kBrushOpacity, kBrushOpacity); 

다른 페인트 브러시 획과 관련된 코드를 검색했지만 코드를 찾을 수 없습니다. image1과 비슷한 "원하는"브러쉬 획을 얻을 수있게 도와주세요.

답변

0

GL_POINT_SPRITE_OES 모드를 사용하지 마십시오. 표준 삼각형을 통해 스프라이트를 그립니다. 그런 다음 스프라이트 텍스처 좌표를 타겟 출력 좌표에 바인딩하고 스프라이트 텍스처를 반복 할 수 있어야합니다. 스프라이트 텍스처 크기가 32x32라고 가정합니다. 기본 텍스처 좌표는 rect {{0,0},{1.0,1.0}}입니다. {x,y} 위치에 스프라이트를 그리려면, {{(x%32)/32.0, (y%32)/32.0},{1.0, 1.0}}을 기반으로 한 스프라이트 텍스처 좌표를 사용해야합니다. 이렇게하면 스프라이트 내용이 번지는 것을 방지 할 수 있습니다.