Je rencontre un problème pour rendre une texture d'arrière-plan dans mon application iPhone. Les images suivantes montrent le problème:Image de texture d'arrière-plan dans iPhone dessinée avec distorsion dans OpenGL ES
http://www.tojamgames.com/wp-content/uploads/2010/09/background_layer1.png
tojamgames.com/wp-content/uploads/2010/09/IMG_0246.png (ne peut pas faire un lien, désolé)
premier est l'image correcte, la seconde est celle qui a été dessinée avec OpenGL ES (oui, elle est plus petite, je l'ai recadrée manuellement dans un éditeur de photo pour supprimer une partie de l'interface de jeu. Vous pouvez avoir l'idée de la distorsion effet assez clair de cela, cependant). De toute évidence, les lignes de distorsion à travers la texture rendue ne sont pas idéales. Voici mon code qui configure opengl, charge la texture, et rend l'image - toute aide serait géniale !! Désolé, c'est long, mais je suis en train de fournir autant d'information que possible :-P
OpenGL Initialisation:
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glShadeModel(GL_FLAT);
glDisable(GL_DITHER);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, screenBounds.size.width, 0, screenBounds.size.height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glDisable(GL_DEPTH_TEST);
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
Texture Chargement:
glGenTextures(1, &_name);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &saveName);
glBindTexture(GL_TEXTURE_2D, _name);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
Dessin Scène
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, screenBounds.size.width , screenBounds.size.height);
// texture images have pre-multiplied alpha, so use this blend function
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
[backgroundImage drawAtPoint:CGPointMake(0,0)];
// more game-specific stuff you don't need to see :-P
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
Enfin, dessiner l'image elle-même (dans l'appel de méthode drawAtPoint)
// grab texture coordinates - maxS & maxT are the width & height in the POT texture
// that contain our NPOT image
GLfloat coordinates[] = { 0, 0,
_maxS, 0,
0, _maxT,
_maxS, _maxT };
GLfloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
// adjust the vertices of the quad so they're contained within the bounding rect of the
// image in the game, subtracting from screenHeight to invert the OpenGL coordinate system
GLfloat vertices[] = { rect.origin.x, screenHeight - rect.origin.y, 0.0,
rect.origin.x + rect.size.width, screenHeight - rect.origin.y, 0.0,
rect.origin.x, screenHeight - (rect.origin.y + rect.size.height), 0.0,
rect.origin.x + rect.size.width, screenHeight - (rect.origin.y + rect.size.height), 0.0 };
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _name);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glEnable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
Encore une fois, désolé, c'est long, mais j'espère que cela fournit suffisamment pour que quelqu'un puisse voir où j'ai foiré !!! Merci beaucoup!
Tom
Les deux liens sont rompus. – genpfault
Merci - avéré qu'ils étaient visibles uniquement pour moi en étant connecté. J'ai corrigé les liens. – Tojo