Archived

This topic is now archived and is closed to further replies.

heightmap-render-loop, automatic texture coords what's wrong?

This topic is 5802 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

I render my heightmap, pretty much like in the Nehe tutorial, but in the render loop I want to add texturing. I have one, big texture which I want to stretch over the differen quads. My idea was just auto-setting the texture coords, based on the value of the loop. So below''s my code, but it doesn''t work. Please help me with this...
  
	for ( xloop = 0; xloop < MAPSIZE; xloop += STEPSIZE )
		for ( yloop = 0; yloop < MAPSIZE; yloop += STEPSIZE )
		{
			x = xloop;
			y = Height(heightmap, xloop, yloop);
			z = yloop;

			glTexCoord2d(xloop / MAPSIZE, yloop / MAPSIZE);
			glVertex3i(x, y, z);

			x = xloop;
			y = Height(heightmap, xloop, yloop + STEPSIZE);
			z = yloop + STEPSIZE;

			glTexCoord2d(xloop / MAPSIZE + 1 / STEPSIZE, yloop / MAPSIZE);
			glVertex3i(x, y, z);

			x = xloop + STEPSIZE;
			y = Height(heightmap, xloop + STEPSIZE, yloop + STEPSIZE);
			z = yloop + STEPSIZE;

			glTexCoord2d(xloop / MAPSIZE + 1 / STEPSIZE, yloop / MAPSIZE + 1 / STEPSIZE);
			glVertex3i(x, y, z);

			x = xloop + STEPSIZE;
			y = Height(heightmap, xloop + STEPSIZE, yloop);
			z = yloop;

			glTexCoord2d(xloop / MAPSIZE, yloop / MAPSIZE + 1 / STEPSIZE);
			glVertex3i(x, y, z);
		}
  

Share this post


Link to post
Share on other sites
Looks like an integer division vs. float division problem.

3 / 2 == 1
1 / 2 == 0

1.0 / 2 == 0.5
3 / 2.0 == 1.5

Solution: cast to float

Edited by - Fruny on January 29, 2002 1:27:31 PM

Share this post


Link to post
Share on other sites
Ok... that worx...

I can see it doesn''t round to 0 any more, like it did before. But the coords are still incorrect... there must be a wrong calculation in my code...

Can anyone take a look at it? I think it''s clear what the code does even without any other code...

Share this post


Link to post
Share on other sites