WakingJohn
2005.04.09, 06:27 PM
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:
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:
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
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:
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:
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