はい、同じ問題がありました。ブラシのエッジが本来よりも暗くなっています。Apple の API pre がアルファを RGB チャネルに乗算することがわかりました。
そこで、Photoshop で RGB 値のみを使用し、アルファ チャネルを使用しないグレースケール ブラシを作成することで、これに対抗しました。これは、フルカラーの色素沈着を表す白と色の色素沈着がないことを表す黒を使用して、ブラシを希望どおりに表示する必要があります。そのブラシを、Apple の glPaint サンプル コードで行った方法でロードします。次に、R チャネル (または G または B チャネルはすべて等しいため) をテクスチャのアルファ チャネルにコピーします。次に、ブラシ テクスチャのすべてのピクセルの RGB 値を最大に設定します。
これで、ブラシには、ブラシがどのように見えるかのデータを含むアルファ チャネルができました。そしてRGBはすべて1です。
最後に、ブレンド機能を使用しました。
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
描画する前に色を設定することを忘れないでください。
glColor4f(1.0f,0.0f,0.0f,1.0f); //red color
以下のコードをチェックして、それが機能するかどうかを確認してください。
-(GLuint) createBrushWithImage: (NSString*)brushName
{
GLuint brushTexture;
CGImageRef brushImage;
CGContextRef brushContext;
GLubyte *brushData,*brushData1;
size_t width, height;
//initialize brush image
brushImage = [UIImage imageNamed:brushName].CGImage;
// Get the width and height of the image
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
//make the brush texture and context
if(brushImage) {
// Allocate memory needed for the bitmap context
brushData = (GLubyte *) calloc(width * height *4, sizeof(GLubyte));
// We are going to use brushData1 to make the final texture
brushData1 = (GLubyte *) calloc(width * height *4, sizeof(GLubyte));
// Use the bitmatp creation function provided by the Core Graphics framework.
brushContext = CGBitmapContextCreate(brushData, width, height, 8, width *4 , CGImageGetColorSpace(brushImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the image to the context.
CGContextDrawImage(brushContext, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), brushImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(brushContext);
for(int i=0; i< width*height;i++){
//set the R-G-B channel to maximum
brushData1[i*4] = brushData1[i*4+1] =brushData1[i*4+2] =0xff;
//store originally loaded brush image in alpha channel
brushData1[i*4+3] = brushData[i*4];
}
// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &brushTexture);
// Bind the texture name.
glBindTexture(GL_TEXTURE_2D, brushTexture);
// Set the texture parameters to use a minifying filter and a linear filer (weighted average)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Specify a 2D texture image, providing the a pointer to the image data in memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData1);
// Release the image data; it's no longer needed
free(brushData1);
free(brushData);
}
ブラシテクスチャを返します。}