Cela fait un certain temps que je suis en train de lire des tutoriels, et je n'arrive pas à comprendre ce qui ne va pas, quelqu'un d'autre peut-il m'aider à comprendre ce qui ne va pas?Pourquoi ma texture ouverte est-elle blanche?
// Sets up an array of values to use as the sprite vertices.
const GLfloat spriteVertices[] = {
20.0f, 50.5f,
305.0f, 50.0f,
10.5f, 200.5f,
300.5f, 300.5f,
};
// Sets up an array of values for the texture coordinates.
const GLshort spriteTexcoords[] = {
0, 0,
100, 0,
0, 100,
100, 100,
};
-(void)setupView:(GLView*)view {
glMatrixMode(GL_PROJECTION);
CGRect rect = view.bounds;
glOrthof(0, rect.size.width, rect.size.height, 0, -1, 1);
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_MODELVIEW);
glDepthMask(GL_FALSE);
glLoadIdentity();
CGImageRef spriteImage = [UIImage imageNamed:@"rss_icon.png"].CGImage;
size_t width = CGImageGetWidth(spriteImage);
size_t height = CGImageGetHeight(spriteImage);
GLubyte *spriteData =
(GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
CGContextRef spriteContext = CGBitmapContextCreate(
spriteData, width, height, 8, width * 4,
CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast
);
CGContextDrawImage(
spriteContext,
CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height),
spriteImage
);
CGContextRelease(spriteContext);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, spriteData
);
free(spriteData);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
Code Draw:
- (void)drawView:(UIView *)theView {
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_SHORT, 0, spriteTexcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
Elles ne sont jamais désactivées, Bien sûr, je les ai ajoutées juste avant de dessiner. – Jacob
sont les dimensions de l'image une puissance de 2? –
ie 8,16,32,64,128 ... Non, il n'a pas été mentionné que c'était important dans tout ce que j'ai lu! J'essaie maintenant, merci. – Jacob