OpenGL ES creating a 2D mesh

Apprentice
Posts: 12
Joined: 2009.04
Post: #1
Using OpenGL ES, I am trying to create a mesh that takes up the entire screen. My intention is to apply a texture to it and then distort it. My screen is 480x320 in size.

Here is what I have done:

Code:
#define kWindowWidth 480
#define kWindowHeight 360
#define kHorisontalDivisions 30
#define kVerticalDivisions 10

GLfloat pictureMeshVertices[kHorisontalDivisions][kVerticalDivisions][3];
GLfloat pictureMeshVerticesUnified[kHorisontalDivisions*kVerticalDivisions*3];

Code:
- (void)populateMesh
{
    int x;
    int y;
    int completedTriangles;
    
    float height = kWindowHeight/kVerticalDivisions;
    float width = kWindowWidth/kHorisontalDivisions;
    
    NSLog(@"width: %f, height: %f", width, height);
    
    for (y=0; y < kVerticalDivisions; y++) {
        for (x=0, completedTriangles=0; x < kHorisontalDivisions-1; x++, completedTriangles+=2) {
            pictureMeshVertices[completedTriangles][y][0] = (float)(x * width) + 0.0f;
            pictureMeshVertices[completedTriangles][y][1] = (float)(y * height) + height;
            pictureMeshVertices[completedTriangles][y][2] = 0.0f;
            
            pictureMeshVertices[completedTriangles+1][y][0] = (float) (x * width) + 0.0f;
            pictureMeshVertices[completedTriangles+1][y][1] = (float) ((y * height) + 0.0f);
            pictureMeshVertices[completedTriangles+1][y][2] = (float) 0.0f;
            
            NSLog(@"filling Line %i, %i: %f, %f, %f",completedTriangles, y,  pictureMeshVertices[completedTriangles][y][0], pictureMeshVertices[completedTriangles][y][1], pictureMeshVertices[completedTriangles][y][2] );
            NSLog(@"filling Line %i, %i: %f, %f, %f", completedTriangles+1, y,pictureMeshVertices[completedTriangles+1][y][0], pictureMeshVertices[completedTriangles+1][y][1], pictureMeshVertices[completedTriangles+1][y][2] );
            
        }
    }
    
    int i;
    int j;
    int k;
    int count = 0;
    for (j=0; j<kVerticalDivisions; j++) {
        for (i=0; i<kHorisontalDivisions; i++) {
            for (k=0; k<3; k++) {
                pictureMeshVerticesUnified[count] = pictureMeshVertices[i][j][k];
                //NSLog(@"%f",pictureMeshVerticesUnified[count] );
                count++;
            }
        }
    }
    NSLog(@"count: %i", count);
}

And the draw function will be like this:
Code:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, pictureMeshVerticesUnified);
glPushMatrix();
    glDrawArrays(GL_LINE_STRIP, 0, kHorisontalDivisions*kVerticalDivisions*3);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

However, I am getting this as a result.

It is clear that although the logic is somehow correct, I am forgetting something... Can anyone please point me in the right direction?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  how to create a grid / 2D mesh bfarah 1 4,147 Oct 20, 2010 02:22 AM
Last Post: iamflimflam1
  Boolean Mesh Operations and Mesh-Based CSG Oddity007 2 5,730 Feb 13, 2010 03:42 PM
Last Post: Oddity007
  Creating an OpenGL Overlay Florian 12 10,731 Jan 23, 2009 03:29 AM
Last Post: Florian
  Spherical Mesh. dave05 8 5,941 Oct 29, 2008 02:53 PM
Last Post: mholg
  Breaking down a concave mesh into convex pieces Willem 5 4,720 Aug 10, 2008 05:49 AM
Last Post: Willem