2010-08-20 6 views
0

Désolé pour ce long bloc de code, mais je pense qu'il est logique d'inclure tout cela. Peu importe ce que je joue avec, je ne peux pas obtenir mon mesh pour le rendre en plein écran. La fenêtre est en plein écran, tout comme la vue GL. Voilà ce qui se passe:Rendu iPhone maille ouverte dans un coin de l'écran?

http://img191.imageshack.us/img191/247/screenshot2010082000163.png

C'est le code qui fonctionne dans ma boucle de dessin:

int verticalDivisions = 16; 
int horizontalDivisions = 16; 
GLfloat *verticesArr; 
GLfloat *textureCoordsArr; 
GLuint textureID = texture[0]; 

unsigned int verticesArrsize = (verticalDivisions * ((2 + horizontalDivisions * 2) * 3)); 
unsigned int textureCoordsArraySize = verticalDivisions * ((2 + horizontalDivisions * 2) * 2); 
verticesArr = (GLfloat *)malloc(verticesArrsize * sizeof(GLfloat)); 
textureCoordsArr = (GLfloat*)malloc(textureCoordsArraySize * sizeof(GLfloat)); 

float height = 1.0f/verticalDivisions; 
float width = 1.0f/horizontalDivisions; 

int i,j, count; 

count = 0; 

for (j=0; j<verticalDivisions; j++) { 
    for (i=0; i<=horizontalDivisions; i++, count+=6) { //2 vertices each time... 
     float currX = i * width; 
     float currY = j * height; 
     verticesArr[count] = currX;///backingWidth; 
     verticesArr[count+1] = (currY + height);///backingHeight; 
     verticesArr[count+2] = 0.0f; 

     verticesArr[count+3] = currX;///backingWidth; 
     verticesArr[count+4] = currY;///backingHeight; 
     verticesArr[count+5] = 0.0f; 
     //NSLog(@"v1: (%f,%f) v2:(%f,%f)",currX,currY+height,currX,currY); 
    } 
} 


count = 0; 

float xIncrease = 0.625f/(float)horizontalDivisions; 
float yIncrease = 0.898f/(float)verticalDivisions; 

int x,y; 
//int elements; 
count = 0; 

for (y=0; y<verticalDivisions; y++) { 
    for (x=0; x<horizontalDivisions+1; x++, count+=4) { 
     float currX = (float)x * xIncrease; 
     float currY = (float)y * yIncrease; 
     textureCoordsArr[count] = (float)currX; 
     textureCoordsArr[count+1] = (float)currY + yIncrease; 

     textureCoordsArr[count+2] = (float)currX; 
     textureCoordsArr[count+3] = (float)currY; 
     //NSLog(@"v1: (%f,%f) v2:(%f,%f)",currX,currY+yIncrease,currX,currY); 
    } 
} 

NSLog(@"expected %i vertices, and %i vertices were done",(verticalDivisions * ((2 + horizontalDivisions*2) * 2)) , count); 


glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); 
glLoadIdentity(); 
glColor4f(255.0, 255.0, 255.0, 0.0); 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

glEnable(GL_TEXTURE_2D); 
glEnableClientState(GL_VERTEX_ARRAY); 
glEnableClientState(GL_TEXTURE_COORD_ARRAY); 


glBindTexture(GL_TEXTURE_2D, textureID); 

glTexCoordPointer(2, GL_FLOAT, 0, textureCoordsArr); 
glVertexPointer(3, GL_FLOAT, 0, verticesArr); 


glPushMatrix();{ 
    int i; 
    for (i=0; i<verticalDivisions; i++) { 
     //glDrawArrays(GL_LINE_STRIP, i*(horizontalDivisions*2+2), horizontalDivisions*2+2); 
     glDrawArrays(GL_TRIANGLE_STRIP, i*(horizontalDivisions*2+2), (horizontalDivisions*2+2)); 

    } 
}glPopMatrix(); 


glDisableClientState(GL_VERTEX_ARRAY); 
glDisableClientState(GL_TEXTURE_COORD_ARRAY); 



glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); 
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; 

Merci!

+0

À quoi ressemble votre code d'installation GL? – Goz

+0

code d'installation n'est pas le problème, mon autre dessin fonctionne bien. merci –

Répondre

0

Essayez de changer un peu de votre code:

float xStart = -0.5; 
float yStart = -0.5; 
for (j=0; j<verticalDivisions; j++) { 
    for (i=0; i<=horizontalDivisions; i++, count+=6) { //2 vertices each time... 
     float currX = xStart + i * width; 
     float currY = yStart + j * height; 
     verticesArr[count] = currX;///backingWidth; 
    .... 

Cela devrait vous permettre de passer le maillage au sujet. Après s'être alignée sur un coin (changer xStart et yStart), vous pouvez ajuster la largeur et la hauteur jusqu'à ce que cela corresponde.

+0

merci! Cela a fonctionné parfaitement. –

Questions connexes