Jump to content
  • Advertisement
Sign in to follow this  
chad_420

Heightmap help

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
that cleared up the garbage but it still only make half the image, that heighmap is 50 X 50 but it come out to 25 x 50

Share this post


Link to post
Share on other sites
Array indicies go from 0 to length-1. Also, you're drawing a quad at every point along your bitmap's width excluding the last point. Since this is the case, the code:

iz++;
if(iz > image->w)
{
ix++;
iz = 0;
}




is going outside your bounds by two quads. This may work better:

iz++;
if(iz >= image->w-detail)
{
ix++;
iz = 0;
}




You also may want to add detail to ix rather than 1, and check to see if iz+detail will be outside of the bounds of the image.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!