Im working on a simple heightmapped terrain. Cant seem to get it to read more than a 3rd of my image. Also it seems a bunxh of garbage is being drawn. Maybe someone can spot the problem?
Here is a screenshot and some code :D
initialization
numverts = (int) (((image->w - 1) * (image->h - 1))* 4 );
tverts = new vert3f[numverts];
int ix = 0, iz = 0;
int vplace = 0;
while(vplace < numverts)
{
tverts[vplace].x = ix;
tverts[vplace].y = (float)(getpixel(image, (int)ix, (int)iz) * heightscale);
tverts[vplace].z = iz;
vplace++;
tverts[vplace].x = ix;
tverts[vplace].y = (float)(getpixel(image, (int)ix, (int)(iz +1)) * heightscale);
tverts[vplace].z = iz + detail;
vplace++;
tverts[vplace].x = ix + detail;
tverts[vplace].y = (float)(getpixel(image, (int)(ix + 1), (int)(iz + 1)) * heightscale);
tverts[vplace].z = iz + detail;
vplace++;
tverts[vplace].x = ix + detail;
tverts[vplace].y = (float)(getpixel(image, (int)(ix + 1), (int)iz) * heightscale);
tverts[vplace].z = iz;
vplace++;
iz++;
if(iz > image->w)
{
ix++;
iz = 0;
}
}
glGenBuffersARB( 1, &VBOVertices ); // Get A Valid Name
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBOVertices );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, numverts *sizeof(float), tverts, GL_STATIC_DRAW_ARB );
per frame
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBOVertices );
glVertexPointer( scalars_per_vertice, GL_FLOAT, 0, (char *)NULL); // Set The Vertex Pointer To The Vertex Buffer
glDrawArrays( GL_QUADS, 0, numverts);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
image of problems