0

I am trying to load a height map for terrain using SOIL. I use the following code:

unsigned char* image = SOIL_load_image(fname.c_str(), &width, &height, 0, SOIL_LOAD_L);

glBindTexture(GL_TEXTURE_2D, name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);

However, my terrain looks steppy because the height is expressed with 8 bits only. How can I load 16-bit height map with SOIL? Or should I use another image library for this task?

RostakaGmfun
  • 487
  • 6
  • 21
  • 1
    `SOIL` *should* be able to load 16-bit BMP images, at least from what I can garner from it's source code. Would it be possible to supply both the image you are trying to load, and the one being output by `SOIL`? – ssell Apr 23 '14 at 15:15
  • This really is not a good idea. `GL_LUMINANCE` is not supported in modern OpenGL implementations and your format/data types are all wrong. If you want a single-component 16-bit image format, use `GL_R16` for the internal format, `GL_RED` for the pixel transfer format and `GL_UNSIGNED_SHORT` for the pixel transfer type. Frankly, I don't see what SOIL has to do with anything in this question. – Andon M. Coleman Apr 23 '14 at 22:58
  • @Andon M. Coleman, as you pointed out, I had incorrect values for the internal and pixel transfer formats. However, this does not solve the problem because SOIL returns the contents of image as an array of unsigned bytes, not 16-bit values. The question is - how to load data in an `unsigned short` array? – RostakaGmfun Apr 24 '14 at 14:12
  • 1
    If you want to load an array of 16-bit data, don't even bother with SOIL. There are only a handful of HDR image formats, you would be better off avoiding an image file altogether and just store your data in a raw binary format. You can always layer it on top of something like zlib to improve storage requirements. – Andon M. Coleman Apr 24 '14 at 18:35
  • @Andon M. Coleman, OK, that is probably the best idea, so I am going to do so. – RostakaGmfun Apr 26 '14 at 11:51
  • @RostakaGmfun instead of renaming your question with (SOLVED), create your own answer to your own question and mark it as correct. – ilent2 Apr 27 '14 at 13:43

1 Answers1

0

As Andon M. Coleman recommended, I used raw binary format to store 16-bit height data and got the required result.

RostakaGmfun
  • 487
  • 6
  • 21