iPhone 및 iPad 용 페인팅 앱 [GLPaint 앱에서 가져온 참조]을 개발 중입니다. 브러시 효과를 연구 중입니다. 내가 브러쉬 질감에 대한 다음 코드를 사용하고 2iPhone OpenGL ES 페인트 브러시 효과
이미지와 유사 브러시 스트로크를 가지고
이미지 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과 비슷한 "원하는"브러쉬 획을 얻을 수있게 도와주세요.