2

iPhone、iPad向けお絵描きアプリ【GLPaintアプリを参考に】を開発中です。私はブラシ効果に取り組んでいます。Image1に示すように、ペイントアプリのブラシ効果を取得したい

ここに画像の説明を入力

画像 2 のようなブラシ ストロークがあります。

ここに画像の説明を入力

ブラシ テクスチャに次のコードを使用しています。

CGImageRef      brushImage;
CGContextRef    brushContext;
GLubyte         *brushData;
size_t          width, height;
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        brushImage = [UIImage imageNamed:@"flower@2x.png"].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に似た「望ましい」ブラシストロークを得るのを手伝ってください。

4

1 に答える 1

0

GL_POINT_SPRITE_OESモードを使用しないでください。標準の三角形を介してスプライトを描画します。次に、スプ​​ライト テクスチャ座標をターゲット出力座標にバインドし、スプライト テクスチャを繰り返し可能にする必要があります。スプライト テクスチャのサイズが 32x32 であると仮定します。デフォルトのテクスチャ座標は rect{{0,0},{1.0,1.0}}です。位置にスプライトを描画{x,y}するには、 rect に基づくスプライト テクスチャ 座標を使用する必要があります{{(x%32)/32.0, (y%32)/32.0},{1.0, 1.0}}。このようにして、スプライト コンテンツが汚れるのを防ぎます。

于 2012-06-27T18:49:43.860 に答える