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

Recommended Posts

I have some code reading heightmap data from an image. The image gets loaded into memory and then I read the color from it. However, I'm having some trouble getting it to work as I should. I had some code that I have used for a while, but when I try a different sized heightmap, it seems to break. Here's what I had:
height = (p[(z*Image->w + x)*Image->format->BytesPerPixel + 2*z] - 128) * vScaleIn;

I think that's fairly standard, except for the "+ 2*z" part. I had to do that to get it to load this image right. However, if I resize the heightmap, I need to use this (no "+ 2*z"):
height = (p[(z*Image->w + x)*Image->format->BytesPerPixel] - 128) * vScaleIn;

If I use the smaller heightmap with the first code example, it looks like this. If I use the second (what seems like the correct code) with the smaller heightmap, it looks like this. If I use the larger heightmap with the first code, it looks like this. I took that image at a different location, but it shows the same error, just in the opposite direction. The larger heightmap looks correct with the second code bit. I'm not sure why that particular image needs the "+ 2*z". I've tried resaving the image, but it doesn't seem to be a problem with the file itself. Any ideas what I need to do to get code that works for any heightmap?

Share on other sites
Looks like a stide issue. Are you sure the bytes per pixel are correct? I mean the way you have it slanted out seems to suggest that your stride is off.

What format is your heightmap in?

~Wave

Share on other sites
Yeah, stride does seem like a likely candidate. However, both bytes per pixel values are set to 3. I'm using SDL_image to load the images, so it figures that out and I assume it does it right. My images are png images, and I have saved them both from the gimp. The larger one is just a resize of the the smaller one, so they shouldn't be all that different. I tried using "(Image->format->BytesPerPixel+1)" (perhaps allowing for an alpha channel), but that just results in a seg fault.

Share on other sites
To access a SDL_Surface you should not use the image width in the computation. Instead use the length of scanline given by the surface member "pitch".

Share on other sites
I'm not sure why they would do that, but that works great. Thanks.

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• Forum Statistics

• Total Topics
632950
• Total Posts
3009382
• Who's Online (See full list)

There are no registered users currently online

×