У меня проблема с окрашиванием изображения PNG с помощью GLKit.
У меня есть белое изображение PNG, которое я загружаю в приложение, а затем использую его для создания текстуры:
UIImage *image = [ UIImage imageNamed:@"brushImage" ];
NSError *error = nil;
texture_m = [[ GLKTextureLoader textureWithCGImage:image.CGImage options:nil error:&error] retain ];
if (error) {
NSLog(@"Error loading texture from image: %@",error);
}
текстура создается без ошибок.
однако, когда я хочу визуализировать текстуру с активированной смесью, цвет, кажется, игнорируется, и я получаю белое изображение. У меня не было проблем, когда я делал это в OpenGL1, когда изображение приобретало цвет, определенный в glColor4f()
. Вот мой код рендеринга:
-(void)render{
if (texture_m != nil) {
effect_m.texture2d0.enabled = GL_TRUE;
effect_m.texture2d0.envMode = GLKTextureEnvModeReplace;
effect_m.texture2d0.target = GLKTextureTarget2D;
effect_m.texture2d0.name = texture_m.name;
}
[effect_m prepareToDraw];
glClear(GL_COLOR_BUFFER_BIT);
GLfloat squareVertices[] = {
50, 50,
150, 50,
50, 150,
150, 150
};
GLfloat squareTexture[] = {
0, 0,
1, 0,
0, 1,
1, 1
};
glColor4f( 1, 0, 0, 1 );
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glEnable(GL_BLEND);
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, squareVertices);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, squareTexture );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_BLEND);
glDisableVertexAttribArray(GLKVertexAttribPosition);
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
}
Может ли кто-нибудь помочь решить эту проблему Спасибо
Реза