我跟着蘋果的GLPaint油漆應用程序,並試圖修改它..在示例代碼中,他們使用簡單的particle.png來繪製。蘋果GLPaint修改問題
我的問題是我想用我的一些選擇的其他圖像繪製。乍一看似乎很容易與一些「finger.png」更換「particle.png」,但沒有奏效。當我更換「particle.png」與「finger.png」,我得到了這樣的事情:
我「finger.png」圖像看起來財產以後這樣的:
部分代碼:
- (id)initWithCoder:(NSCoder*)coder
{
CGSize myShadowOffset = CGSizeMake (0, 0);
NSMutableArray* recordedPaths;
CGImageRef brushImage;
CGContextRef brushContext;
GLubyte *brushData;
size_t width, height;
// Create a texture from an image
// First create a UIImage object from the data in a image file, and then extract the Core Graphics image
////--------------------Modification--------------------------------///////
brushImage = [UIImage imageNamed:@"finger.png"].CGImage;
////--------------------Modification--------------------------------///////
// Get the width and height of the image
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
NSLog(@"%f%f",(CGFloat)width, (CGFloat)height);
// Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,
// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.
// Make sure the image exists
if(brushImage)
{
// Allocate memory needed for the bitmap context
brushData = (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.0, 0.0, (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);
// 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, brushData);
// Release the image data; it's no longer needed
free(brushData);
}
我不明白爲什麼我收到畫這樣的。任何人都可以指出我需要做出哪些其他更改以使此應用程序像以前一樣工作?我不是OpenGL的專家,所以任何幫助或建議將不勝感激..
@cdshader:謝謝你的建議..也許你是對的,但讓我更具體。當我使用** finger.png **時,我在觸摸/輕按上獲得那些方形圖像**(用紅色橢圓標記)**。那是因爲您所說的透明度? –
我相信是的,你看到的是整個圖像的全部。我會想象你的finger.png是一個與你的實心方塊大小相同的方形圖像。 – cdasher
不,我得到的圖像的形狀確切的是它在圖片中的樣子,但仍然沒有成功。 –