Making a grid on iPhone using Opengl

Posted by TheGambler on Stack Overflow See other posts from Stack Overflow or by TheGambler
Published on 2010-05-27T13:48:26Z Indexed on 2010/05/27 13:51 UTC
Read the original article Hit count: 194

Filed under:
|
|

I'm trying to make a grid similar to what you would see in these geo games(geoDefense/geometry wars). I'm wanting to apply separate transformation matrixes to each to create different effects. So, it makes since to me that I need to draw each square separately to that I can apply a different transformation to each one.

The problem I'm having is mapping these grids out or connecting the squares. The coordinate systems is still confusing to me. I know it would be easy just to create a huge triangle strip but I'm not able to figure out a way to apply separate transformations to each square( quad ) if I use triangle strips. So first question:

Can you apply different transformations to quads if you use a triangle strip to draw a huge grid? If so, any tips suggestions on how to do so?

If not, how does one usually connect textures without using triangle strips?

Here is my coord setup:

const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 45.0; 
GLfloat size; 
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION); 
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0); 
CGRect rect = view.bounds; 

glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / 
               (rect.size.width / rect.size.height), zNear, zFar); 
glViewport(0, 0, rect.size.width, rect.size.height);  

Here is my draw:

- (void)drawView:(GLView*)view;
{
    int loop;
    //glColor4f(1.0, 1.0, 1.0, 0.5);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //Grid Loop
    for( loop = 0; loop < kNumberSectionsInGrid; loop++ )              
    { 
        //glLoadIdentity();
        static Matrix3D    shearMatrix;
        Matrix3DSetShear(shearMatrix, 0.2, 0.2);
        static Matrix3D     finalMatrix;
        //Matrix3DMultiply(temp2Matrix, shearMatrix, finalMatrix);
        glLoadMatrixf(shearMatrix);
        glTranslatef(-1.0f,(float)loop,-3.0f);
        glScalef(0.1, 0.1, 0.0);

        Vertex3D vertices[] = {
            {-1.0,  1.0, 0.5},
            { 1.0,  1.0, 0.5},
            { -1.0, -1.0, 0.5}, 
            { 1.0, -1.0, 0.5}
        };
        static const Vector3D normals[] = {
            {0.0, 0.0, 1.0},
            {0.0, 0.0, 1.0},
            {0.0, 0.0, 1.0},
            {0.0, 0.0, 1.0},
        };
        GLfloat texCoords[] = {
            0.0, 1.0,
            1.0, 1.0,
            0.0, 0.0,
            1.0, 0.0
        };
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_NORMAL_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);


        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glVertexPointer(3, GL_FLOAT, 0, vertices);
        glNormalPointer(GL_FLOAT, 0, normals);
        glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_NORMAL_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    }
}

glMatrixMode(GL_MODELVIEW);

© Stack Overflow or respective owner

Related posts about iphone

Related posts about opengl