Archived

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

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

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

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 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 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...

1. 1
2. 2
Rutin
26
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631763
• Total Posts
3002197
×