Quad Vertex Array Woes

WakingJohn
Unregistered
 
Post: #1
Hey,

I've been messing with this for about two days and can't figure out what I'm doing wrong. Basically its just drawing a few col of the mesh stored in the vertex array instead of drawing the entire square mesh. Heres my code:
Code:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0f, 1.0f, 1.0f);
// Draw a submesh
    glEnableClientState( GL_VERTEX_ARRAY );
    glVertexPointer( 3, GL_FLOAT, 0, vertices );
    glEnable( GL_TEXTURE_2D );
    glEnable( GL_POLYGON_OFFSET_FILL );
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    glTexCoordPointer( 2, GL_FLOAT, 0, textureUV );
        
        
    glBindTexture(GL_TEXTURE_2D, texture[0].texID);
    
    glDrawElements( GL_QUADS, SIZE*SIZE*4, GL_UNSIGNED_BYTE, indices );
        
    glDisableClientState( GL_VERTEX_ARRAY );
    glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    glDisable( GL_POLYGON_OFFSET_FILL );

and this is my generation of the arrays:
Code:
    int i = 0;
    int j = 0;
    int count = 0;
    int icount = 0;
    int tcount = 0;
    int size = SIZE;
    float mesh_vert_heights[size][size];
    
    for(i=0;i<size-1;i++)
    {
        for(j=0;j<size-1;j++)
            mesh_vert_heights[j][i] = ((float)rand()/RAND_MAX)*1.5f;
    }
    
    

    for(i=0;i<size-1;i++)
    {
        for(j=-1;j<size-1;j++)
        {        
            vertices[count] = j*1.0f; count++; //vertice
            vertices[count] = mesh_vert_heights[j][i];count++;
            vertices[count] = i*1.0f;count++;
            
            textureUV[tcount] = 1.0f-(float)(j)/size; tcount++;// uv
            textureUV[tcount] = (float)(i)/size; tcount++;
            
            indices[icount] = icount;                                                    icount++;//vertice for face
            
            vertices[count] = j*1.0f; count++;
            vertices[count] = mesh_vert_heights[j][1+i]; count++;
            vertices[count] = 1.0f+i*1.0f; count++;

            textureUV[tcount] =  1.0f-(float)(j)/size; tcount++;
            textureUV[tcount] = (float)(i+1)/size; tcount++;

            indices[icount] = icount;
            icount++;
            
            vertices[count] = 1.0f+j*1.0f; count++;
            vertices[count] = mesh_vert_heights[j+1][1+i]; count++;
            vertices[count] = 1.0f+i*1.0f; count++;

            textureUV[tcount] = 1.0f-(float)(j+1)/size; tcount++;
            textureUV[tcount] = (float)(i+1)/size; tcount++;
            
            indices[icount] = icount;
            icount++;
            
            vertices[count] = 1.0f+j*1.0f; count++;
            vertices[count] = mesh_vert_heights[j+1][i]; count++;
            vertices[count] = i*1.0f; count++;

            textureUV[tcount] =  1.0f-(float)(j+1)/size; tcount++;
            textureUV[tcount] = (float)(i)/size; tcount++;
            
            indices[icount] = icount;
            icount++;
        }
    }

This is all done in c++ carbon in xcode with opengl and glut.

Heres an image of whats happening, only with all heights set to 0 to aid in viewing the problem:
http://idiotcollective.com/weirdArray.jpeg
Quote this message in a reply
WakingJohn
Unregistered
 
Post: #2
Got it.

GLubyte should have been an GL unisgned int since I was dealing with larger values than 255 for the indices.

Thanks!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Particle Vertex Array bonanza 9 4,579 Jun 27, 2008 07:46 AM
Last Post: bonanza
  Vertex Array &amp; Interleaved Array troubles TomorrowPlusX 5 5,549 Nov 17, 2007 09:59 AM
Last Post: TomorrowPlusX
  Vertex Array Range bonanza 3 3,855 Jun 19, 2007 12:42 PM
Last Post: OneSadCookie
  Y value of a point on a quad evenmybird 5 3,706 Aug 6, 2006 02:32 PM
Last Post: OneSadCookie
  Compiled vertex array problem Frank C. 1 2,467 Feb 7, 2006 10:06 PM
Last Post: Frogblast