我有一个简单的16x16粒子,从不透明变为透明。不幸的是,在我的iPhone端口显示不同,我看不到代码中的差异。大部分代码基本相同。OpenGL ES/iPhone的透明度/混合问题
我上传的图像here显示问题
左边的粒子是不正确的渲染iPhone版本,右边是它如何出现在Mac和Windows。这只是一个简单的RGBA .png文件。
我试过无数的混合函数和glTexEnv设置,但我似乎无法使它们相同。
只是要彻底,在iPhone上我的纹理加载代码看起来像我用的是glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)以下
GLuint TextureLoader::LoadTexture(const char *path)
{
NSString *macPath = [NSString stringWithCString:path length:strlen(path)];
GLuint texture = 0;
CGImageRef textureImage = [UIImage imageNamed:macPath].CGImage;
if (textureImage == nil)
{
NSLog(@"Failed to load texture image");
return 0;
}
NSInteger texWidth = CGImageGetWidth(textureImage);
NSInteger texHeight = CGImageGetHeight(textureImage);
GLubyte *textureData = new GLubyte[texWidth * texHeight * 4];
memset(textureData, 0, texWidth * texHeight * 4);
CGContextRef textureContext = CGBitmapContextCreate(textureData, texWidth, texHeight, 8, texWidth * 4, CGImageGetColorSpace(textureImage), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)texWidth, (float)texHeight), textureImage);
CGContextRelease(textureContext);
//Make a texture ID, bind it, create it
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
delete[] textureData;
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return texture;
}
的混合功能;
我会尝试任何想法的人扔我,因为这对我来说有点神秘。
干杯。
模拟器渲染左侧的图像还是实际的硬件? – 2009-10-01 08:17:08