在我的应用程序(Tres)中,我正在从图像选择器中加载图像并将其放在纹理上。在所有测试中都正常工作,但现在在线上,使用视网膜显示屏的iPad用户抱怨图像呈黑色。
我正在查看GL_MAX_TEXTURE_SIZE以确保图像不超过该大小。
这里是设置纹理的代码:
texture_aspect = image.size.width / image.size.height;
CGFloat side = image.size.width;
if(side>GL_MAX_TEXTURE_SIZE)
side = GL_MAX_TEXTURE_SIZE;
UIImage *newImage = [ImageUtils imageWithImage:image scaledToSize:CGSizeMake(side, side)];
image_height = 600.0f;
image_width = image_height * texture_aspect;
if(image_width>600.0f) {
image_width = 900.0f;
image_height = image_width / texture_aspect;
}
NSError* error;
GLKTextureInfo * texture = [GLKTextureLoader textureWithCGImage:newImage.CGImage options:nil error:&error];
if (error) {
NSLog(@"Error loading texture from image: %@",error);
}
这是我绘制图片的方法:
- (void) dibujaFoto {
self.effect.texture2d0.enabled = GL_TRUE;
[self.effect prepareToDraw];
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
GLfloat squareVertices[] = {
-image_width/2, -image_height/2,
image_width/2,-image_height/2,
-image_width/2, image_height/2,
image_width/2,image_height/2,
};
const GLfloat squareTextureCoords[] = {
0.0, 1.0,
1.0, 1.0,
0.0, 0.0,
1.0, 0.0,
};
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, squareVertices);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, squareTextureCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(GLKVertexAttribPosition);
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
self.effect.texture2d0.enabled = GL_FALSE;
}
无论图片大小如何,它总是能在我的第二代iPad上正常工作,但这段代码似乎在视网膜显示屏上存在问题。