views:

32

answers:

1

Sorry about this long block of code, but I think it makes sense to include all of it. No matter what I play with, I cannot get my mesh to render fullscreen. The viewport is fullscreen, as is the GL view. Here's what happens:

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

This is the code that runs in my drawing loop:

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];

Thank you!

A: 

Try changing a bit of your code to:

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;
    ....

This should let you move the mesh about. After aligning to one corner (change xStart and yStart) you can scale width and height until it fits.

No one in particular
thanks! this worked perfectly.
Nick Lee